[PATCH] Optimize IS DISTINCT FROM NULL => IS NOT NULL
Marti Raudsepp <marti@juffo.org>
From: Marti Raudsepp <marti@juffo.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2012-03-08T17:00:58Z
Lists: pgsql-hackers
Attachments
- distinct-to-nulltest.patch (text/x-patch) patch
Hi list, This patch enables a simple optimization in eval_const_expressions_mutator. If we know that one argument to DistinctExpr is NULL then we can optimize it to a NullTest, which can be an indexable expression. For example the query: EXPLAIN (costs off) SELECT * FROM foo WHERE j IS NOT DISTINCT FROM NULL; Old behavior: Seq Scan on foo Filter: (NOT (j IS DISTINCT FROM NULL::integer)) New behavior: Index Scan using foo_j_idx on foo Index Cond: (j IS NULL) Regards, Marti