Consider the following SQL:
select * from dbname.tablename
where
field1 = 'a' and
field2 = 'b' and
field3 = 'c' and
1=1
You may wonder why I would add 1=1
at the end of the WHERE clause. For ad-hoc querying, I do this so that I can comment out any combination of conditions without having to modify the SQL. Using this SQL, I can comment out field1 = 'a' and
and the SQL will work because of the trailing 1=1
condition. Consider this SQL without this little trick:
field1 = 'a' and
field2 = 'b' and
field3 = 'c'
Commenting out field3 = 'c'
will break the SQL because it will look at field2 = 'b' and
as the final condition and it will bark at you with, "and WHAT??"
The reason why I am asking this is because I have been known to forget to remove the 1=1
from the WHERE clause before I paste the SQL into a production query. I am wondering if this impedes performance. 1=1
is a constant condition, so is there really a strenuous calculation being made here even if the recordset contains 10,000 rows?