Where 1 =-1 and 1 = 1 will it affect the query efficiency ?, Where-1
Today, when I use SQL profiler to talk to an SQL statement generated at the underlying layer, I followed the following code:
WITH TempQuery AS (SELECT *, ROW_NUMBER () OVER (order by CreateTime DESC) AS 'rownumberforsplit 'FROM (select E. name as Name, U. realyName as RealyName, C. [Description] as Descriptions, 'jobseeker 'as tsf, C. result, C. createTime from [Mr]. [User_Complaint] UC inner join [Mr]. [User] U on UC. userCode = U. code inner join [Mr]. [Complaint] C on UC. complaintCode = C. code inner join [Mr]. [Enterprise] E on UC. performanisecode = E. code union select E. name as Name, U. realyName as RealyName, C. [Description] as Descriptions, 'enterprises' as tsf, C. result, C. createTime from [Mr]. [Enterprise_Complaint] EC inner join [Mr]. [Enterprise] E on EC. performanisecode = E. code inner join [Mr]. [Complaint] C on EC. complaintCode = C. code inner join [Mr]. [User] U on EC. userCode = U. code) CPWHERE 1 = 1 AND 1 = 1) SELECT * FROM TempQuery WHERE RowNumberForSplit BETWEEN 1 AND 10; select count (1) AS TOTAL_COUNT FROM (select E. name as Name, U. realyName as RealyName, C. [Description] as Descriptions, 'jobseeker 'as tsf, C. result, C. createTime from [Mr]. [User_Complaint] UC inner join [Mr]. [User] U on UC. userCode = U. code inner join [Mr]. [Complaint] C on UC. complaintCode = C. code inner join [Mr]. [Enterprise] E on UC. performanisecode = E. code union select E. name as Name, U. realyName as RealyName, C. [Description] as Descriptions, 'enterprises' as tsf, C. result, C. createTime from [Mr]. [Enterprise_Complaint] EC inner join [Mr]. [Enterprise] E on EC. performanisecode = E. code inner join [Mr]. [Complaint] C on EC. complaintCode = C. code inner join [Mr]. [User] U on EC. userCode = U. code) cp where 1 = 1 AND 1 = 1
Then you will see the where 1 = 1 and 1 = 1 followed. I used this item to spell out the conditions, but some people later said that this affects the query performance, some people later said that it would not affect the operation. Then I am confused...
Let's test it by yourself.
First, let's take a look at the queries without this condition:
/****** Script for SelectTopNRows command from SSMS ******/SELECT TOP 100000 [RESOURCE_ID] ,[CLASS] ,[SORT_ID] ,[XML_CONTENT] ,[SEARCH_CONTENT] ,[ROW_ID] FROM [MCS_WORKFLOW].[WF].[GENERIC_FORM_RELATIVE_DATA] WHERE 1=1 AND 1=1
Then use the execution plan to estimate:
Then add the following conditions:
In the execution plan, we can see that the overhead is almost all on the clustered index table scan. We can see that the two tables have the same data.
Hey, it seems that their query efficiency is the same.
But why ???? Hundreds of times ....