0

I want to optimize my query using short circuit evaluation as below:

Query 1:

Select emp_id, emp_name 
From emp_table 
Where emp_name = "xyz" 
and emp_id >= 50; 

Query 2 :

Select emp_id, emp_name 
From emp_table 
Where emp_name = "xyz" 
and (emp_id >= 50 or 1 = 0); 

Will the addition of or 1 = 0 condition (short circuit evaluation) in query 2 result in optimization?
How exactly would the short circuit evaluation work in above example?

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223

1 Answers1

1

it won't result in optimization (well,, it could in case there is a bug in the database engine and this would workaround the bug ;)

but i don't thing this question has anything to do with short circuit evaluation - 0 and ?, 1 or ? are short circuit evaluated, not 1 = 0, 0 or ?, 1 and ? nor ? and (? or 1 = 0)

plus the engine should delete or 1 = 0 from your query during compile time (= optimize the query), but i don't know how to inspect the resulting bytecode, so i'm not sure about this...

Aprillion
  • 21,510
  • 5
  • 55
  • 89