3pitt
3pitt

Reputation: 941

SQL Optimization - Redundant Boolean Logic

DB is Oracle 11g, if that matters. I have a query with a long where clause - consisting of three medium sized subblocks (that must all evaluate to true, obviously). However, for two of the subblocks, every single statement is just connected by AND. So, for each such subblock, the preceding AND, one opening parenthesis, and one closing parenthesis are redundant. would removing these improve the execution time of my query?

select * from tbl 
where 1=1 AND (x OR y OR (w AND z))
AND (a AND b AND c)
AND (d AND e AND f);

versus

select * from tbl 
where 1=1 AND (x OR y OR (w AND z))
AND a AND b AND c
AND d AND e AND f;

obviously these queries return the same records, but what is the difference in execution time?

Upvotes: 0

Views: 57

Answers (1)

Tony Andrews
Tony Andrews

Reputation: 132580

It appears you have code something like:

where (a = 1 and b = 2 and c = 3)
  and (d = 4 and e = 5 and f = 6)
  and (g = 7 or h = 8 or i = 9)

In that case it is of course true that some of the parentheses are redundant i.e. it can be rewritten as:

where a = 1 and b = 2 and c = 3
  and d = 4 and e = 5 and f = 6
  and (g = 7 or h = 8 or i = 9)

However there will be no difference in performance between the two queries because they are semantically identical.

Upvotes: 1

Related Questions