Why Is “WHERE 1=0” Slow?
I saw a question the other day, questioning why they're creation of temporary tables was so slow. What they were doing was (a much more complicated version of) this: SELECT soh.SalesOrderID, sod.SalesOrderDetailID, soh.SalesOrderNumber INTO #MyTempTable FROM Sales.SalesOrderHeader AS soh JOIN Sales.SalesOrderDetail AS sod ON sod.SalesOrderID = soh.SalesOrderID WHERE 1 = 0; Now, my immediate response, and no, I didn't type it, was, "Hey, you're not "creating" temporary tables. You're using SELECT...INTO." Let's be fair. That is a method to create temporary tables. Also, that method has some advantages. Biggest one being, you don't have to know, or define, the data structure. You get it for free. It does come down to one thing though. Why is "WHERE 1=0" slow? WHERE 1=0 Math may be weird these days, but in good…