Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no difference.</p> <blockquote> <p>It seems to me that there might be a difference when it comes to performance. Anyone care to elaborate on this?</p> </blockquote> <p>All major engines (that is <code>MySQL</code>, <code>SQL Server</code>, <code>Oracle</code> and <code>PostgreSQL</code>) will merge these predicates on parsing stage, making identical plans from them.</p> <p>Handling of these conditions is more complex that mere applying operators in one or another order.</p> <p>For instance, in <code>Oracle</code>, an <code>IS NOT NULL</code> (or <code>NOT IS NULL</code>) condition implies a possibility to use an index, so a query like this:</p> <pre><code>SELECT column FROM mytable WHERE column IS NOT NULL </code></pre> <p>will most probably be executed with an <code>index fast full scan</code>, with no additional checks made in runtime (since the <code>NULL</code> values just won't make it into the index, so it's no use to check them).</p> <p>Even if each record would need to be checked, the order of checks will be defined by the optimizer (and not by the order the predicates and operators appear in the <code>WHERE</code> clause).</p> <p>For instance, here is a plan for an <code>Oracle</code> query:</p> <pre><code>SQL&gt; EXPLAIN PLAN FOR 2 2 SELECT * 3 FROM t_test 4 WHERE NOT column IS NULL 5 / Explained SQL&gt; SELECT * 2 FROM TABLE(DBMS_XPLAN.display()) 3 / PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Plan hash value: 958699830 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 30 | 1260 | 3 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| T_TEST | 30 | 1260 | 3 (0)| 00:00:01 | ---------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("COLUMN" IS NOT NULL) </code></pre> <p>As you can see, the <code>filter</code> was translated internally into an <code>IS NOT NULL</code> (which <code>Oracle</code> along with most commenters seems to believe to be a more appropriate form)</p> <p><strong>Update:</strong></p> <p>As Jonathan Leffler pointed out, these is difference when evaluating tuples (as opposed to single columns).</p> <p>A tuple consisting of mixed <code>NULL</code> and non-<code>NULL</code> values is neither a <code>NULL</code> nor a <code>NOT NULL</code>.</p> <p>In <code>PostgreSQL</code> (which supports this predicate against tuples), both these expressions:</p> <pre><code>SELECT (1, NULL) IS NULL SELECT (1, NULL) IS NOT NULL </code></pre> <p>evaluate to false.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload