Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLMBv-0004s3-2F for pgsql-bugs@arkaria.postgresql.org; Fri, 08 Jul 2016 03:10:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bLMBt-0006mF-Te for pgsql-bugs@arkaria.postgresql.org; Fri, 08 Jul 2016 03:10:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bLMBE-00061W-1k for pgsql-bugs@postgresql.org; Fri, 08 Jul 2016 03:10:16 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bLMBA-0002w1-Kj for pgsql-bugs@postgresql.org; Fri, 08 Jul 2016 03:10:15 +0000 Received: from localhost ([127.0.0.1]:21152 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.84 (FreeBSD)) (envelope-from ) id 1bLMB9-000CDT-2c for pgsql-bugs@postgresql.org; Fri, 08 Jul 2016 03:10:11 +0000 From: Andrew Gierth To: pgsql-bugs@postgresql.org Subject: Re: BUG #14235: inconsistencies with IS NULL / IS NOT NULL In-Reply-To: <20160708024746.1410.57282@wrigleys.postgresql.org> (andrew@tao11.riddles.org.uk's message of "Fri, 08 Jul 2016 02:47:46 +0000") Message-ID: <8760sg96u2.fsf@news-spur.riddles.org.uk> References: <20160708024746.1410.57282@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) Date: Fri, 08 Jul 2016 04:10:10 +0100 MIME-Version: 1.0 Content-Type: text/plain X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org >>>>> "andrew" == andrew 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: --- 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