1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

Teach parser to transform "x IS [NOT] DISTINCT FROM NULL" to a NullTest.

Now that we've nailed down the principle that NullTest with !argisrow
is fully equivalent to SQL's IS [NOT] DISTINCT FROM NULL, let's teach
the parser about it.  This produces a slightly more compact parse tree
and is much more amenable to optimization than a DistinctExpr, since
the planner knows a good deal about NullTest and next to nothing about
DistinctExpr.

I'm not sure that there are all that many queries in the wild that could
be improved by this, but at least one source of such cases is the patch
just made to postgres_fdw to emit IS [NOT] DISTINCT FROM NULL when
IS [NOT] NULL isn't semantically correct.

No back-patch, since to the extent that this does affect planning results,
it might be considered undesirable plan destabilization.
This commit is contained in:
Tom Lane
2016-07-28 17:23:03 -04:00
parent ef5d4a3cfa
commit 8d19d0e139
4 changed files with 65 additions and 16 deletions

View File

@ -2903,6 +2903,10 @@ _outAExpr(StringInfo str, const A_Expr *node)
appendStringInfoString(str, " DISTINCT ");
WRITE_NODE_FIELD(name);
break;
case AEXPR_NOT_DISTINCT:
appendStringInfoString(str, " NOT_DISTINCT ");
WRITE_NODE_FIELD(name);
break;
case AEXPR_NULLIF:
appendStringInfoString(str, " NULLIF ");
WRITE_NODE_FIELD(name);