pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #14235: inconsistencies with IS NULL / IS NOT NULL
Date: Fri, 08 Jul 2016 04:10:10 +0100
Message-ID: <8760sg96u2.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <20160708024746.1410.57282@wrigleys.postgresql.org>
References: <20160708024746.1410.57282@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

>>>>> "andrew" == andrew  <andrew@tao11.riddles.org.uk> writes:

 andrew> While discussing the issues resulting from the spec's
 andrew> definition of IS NULL and IS NOT NULL on composite values, we
 andrew> discovered the following inconsistent cases, all of which
 andrew> appear to be the fault of eval_const_expressions.

 andrew> In short, the transformations applied to NullTest nodes change
 andrew> the semantics, which can then make the final result depend on,
 andrew> for example, whether function calls were inlined or not.

And here's my analysis of what seems to be going on:

The executor, when doing IS [NOT] NULL on a composite value, looks at
each column to see if it is the null value. It does NOT recurse into
nested composite values, and my reading of the spec suggests that this
is correct.

But eval_const_expressions thinks it has license to change

  ROW(a,b) IS NULL

into

  (a IS NULL) AND (b IS NULL)

which has the effect of recursing one level into a nested composite
value.

It seems possible that this could be fixed by simply setting
argisrow=false for all the null tests generated in such cases.
Specifically I've tried this, which seems to fix all the inconsistent
cases:

inline patch 1: src/backend/optimizer/util/clauses.c (+7/-1 lines) download inline-1.patch--- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -3308,7 +3308,13 @@ eval_const_expressions_mutator(Node *node, newntest = makeNode(NullTest); newntest->arg = (Expr *) relem; newntest->nulltesttype = ntest->nulltesttype; - newntest->argisrow = type_is_rowtype(exprType(relem)); + /* + * We must unconditionally set argisrow false here. + * Otherwise, we'd be treating a nested composite + * structure as though it were at top level, which + * would change the semantics of the test. + */ + newntest->argisrow = false; newntest->location = ntest->location; newargs = lappend(newargs, newntest); }
-- Andrew (irc:RhodiumToad) -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs

view thread (13+ messages)  latest in thread

Message-ID: <8760sg96u2.fsf@news-spur.riddles.org.uk>
Permalink:  ../8760sg96u2.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/8760sg96u2.fsf@news-spur.riddles.org.uk

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk
  Subject: Re: BUG #14235: inconsistencies with IS NULL / IS NOT NULL
  In-Reply-To: <8760sg96u2.fsf@news-spur.riddles.org.uk>
  References: <20160708024746.1410.57282@wrigleys.postgresql.org> <8760sg96u2.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox