DECLARE @false bit = 0;
IF @false
xxxx;
In a stored procedure in SQL Server, if you declare a bit variable, set it to 0, and never change it, then when it's used in an IF, like IF @false
, will the compiler simply leave out those blocks of code, or will it always evaluate the Boolean expression and branch? The answer will determine whether all my debug logging code needs to be commented out for production.
From experimentation, I've concluded that there is, in fact, a performance degradation, albeit minuscule. By performing many "IF @false = 1 xxx;" statements between time checks, I determined that the compiler wasn't smart enough, even though @false could never be 1, to exclude those statements. Adding many additional "IF @false = 1 xxx;" statements further increased the small delay. Consequently, I will comment out these statements.