Skip to main content

Posts

Showing posts from April, 2018

Short circuit on Teradata

My colleague found that some queries on Teradata are improved by  Short-circuit evaluation . This is common knowledge among software engineers, but DBA may not know it. I knew it short circuit, but I didn't know it is effective to sql. For example, following query seems not bad and you may think everything is ok. (Please forget 'like any' since it is rewritten internally) SELECT  * FROM t1 WHERE  c1 LIKE '%a0001%' OR  c1  LIKE  '%a0002%' OR  c1  LIKE  %a0003%' ... OR c1  LIKE  '%a9999%' ; By using short circuit, this query can be rewritten like this.  SELECT  * FROM t1 WHERE  c1  LIKE  '%a%' and  (  c1  LIKE  '%a0001%'  OR c1  LIKE  '%a0002%'   OR  c1  LIKE  '%a0003%'  ...   OR  c1  LIKE  '%a9999%' ) ; Of course, this rewrite isn't effective for all situations. It depends on the data character...