1

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?

oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
  • @oscilatibgcretin Here is another **[Link](http://dba.stackexchange.com/questions/7983/does-where-1-1-usually-have-an-impact-on-query-performance)** To support my **answer**. **:)** – Prahalad Gaggar Apr 23 '13 at 13:24
  • possible duplicate of [T-SQL 1=1 Performance Hit](http://stackoverflow.com/questions/1049512/t-sql-1-1-performance-hit) – Eric Apr 23 '13 at 13:54
  • I tried deleting, but there's an answer, so I just marked it. I was surprised to see others have come up with the exact same trick. – oscilatingcretin Apr 23 '13 at 13:58

1 Answers1

1

In sweet and simple words NO.

Please refer the Answer

Community
  • 1
  • 1
Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71