title: SQL IF EXISTS with OR Condition
body: <p>I am facing a performance issue with a SQL statement. I have noticed a performance degradation in one SQL statement in one of a procedure.</p>
  
  <p><strong>SQL Statement:</strong></p>
  
  <pre><code>IF EXISTS(SELECT TOP 1 FROM TABLE1 WHERE COLUMN1 = 'XYZ')  OR @ISALLOWED = 1
  BEGIN
      -- SQL Statements
  END
  </code></pre>
  
  <p>I couldn't able to understand why OR statement with IF Exists statement is causing performance issue in above query. Because if I rewrite the above statement like this:</p>
  
  <pre><code>DECLARE @ISVALUEEXISTS BIT
  SET @ISVALUEEXISTS = 0
  
  IF EXISTS(SELECT TOP 1 FROM TABLE1 WHERE COLUMN1 = 'XYZ')
      SET @ISVALUEEXISTS = 1
  
  IF (@ISVALUEEXISTS = 1 OR @ISALLOWED = 1 )
  BEGIN
       --SQL Statements
  END
  </code></pre>
  
  <p>Then performance issue is gone. So, I'm couldn't able to understand how and why OR condition with IF Exists statement is causing problem.</p>
  
  <p>Anyone has any idea about this?</p>