Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLMws-000820-9W for pgsql-bugs@arkaria.postgresql.org; Fri, 08 Jul 2016 03:59:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bLMwr-00067a-GU for pgsql-bugs@arkaria.postgresql.org; Fri, 08 Jul 2016 03:59:29 +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 1bLMwD-0005PP-Nn for pgsql-bugs@postgresql.org; Fri, 08 Jul 2016 03:58:49 +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 1bLMwA-0003xc-1e for pgsql-bugs@postgresql.org; Fri, 08 Jul 2016 03:58:49 +0000 Received: from localhost ([127.0.0.1]:24712 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.84 (FreeBSD)) (envelope-from ) id 1bLMw8-000DSU-4M for pgsql-bugs@postgresql.org; Fri, 08 Jul 2016 03:58:44 +0000 From: Andrew Gierth To: pgsql-bugs@postgresql.org Subject: Re: BUG #14235: inconsistencies with IS NULL / IS NOT NULL In-Reply-To: <8760sg96u2.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Fri, 08 Jul 2016 04:10:10 +0100") Message-ID: <871t349405.fsf@news-spur.riddles.org.uk> References: <20160708024746.1410.57282@wrigleys.postgresql.org> <8760sg96u2.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) Date: Fri, 08 Jul 2016 04:58:44 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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 --=-=-= Content-Type: text/plain Here's that change as a proper patch with the original testcase added as a regression test. -- Andrew (irc:RhodiumToad) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=cnulls.patch Content-Description: nested composite nulls patch diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 1435f05..99af4b4 100644 --- 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); } diff --git a/src/test/regress/expected/rowtypes.out b/src/test/regress/expected/rowtypes.out index 3630ef4..17cbb4c 100644 --- a/src/test/regress/expected/rowtypes.out +++ b/src/test/regress/expected/rowtypes.out @@ -657,3 +657,93 @@ select row_to_json(r) from (select q2,q1 from tt1 offset 0) r; {"q2":0,"q1":0} (3 rows) +-- +-- test IS [NOT] NULL on nested cases, to ensure consistency +-- (bug #14235) +-- +create type ct1 as (a integer, b integer); +create type ct2 as (a integer, b ct1); +create type ct3 as (a integer, b ct2); +create function make_ct1(integer,integer) returns ct1 + language sql immutable + as $f$ select row($1,$2*$2)::ct1; $f$; +create function make_ct2(integer,integer) returns ct2 + language sql immutable + as $f$ select row($1,row($2,$2)::ct1)::ct2; $f$; +create function make_ct3(integer,integer) returns ct3 + language sql immutable + as $f$ select row($1,row($2,row($2,$2)::ct1)::ct2)::ct3; $f$; +create function stable_null() returns integer + language plpgsql stable cost 1 + as $f$ begin return null; end; $f$; +create function volatile_null() returns integer + language plpgsql volatile cost 1000 + as $f$ begin return null; end; $f$; +select row(null,null)::ct1 is null as ct1, + row(null,row(null,null)::ct1)::ct2 is null as ct2, + row(null,row(null,row(null,null)::ct1)::ct2)::ct3 is null as ct3; + ct1 | ct2 | ct3 +-----+-----+----- + t | f | f +(1 row) + +select row(1,null)::ct1 is not null as row_cons, + '(1,)'::ct1 is not null as row_literal, + make_ct1(1,null) is not null as inlined_const, + make_ct1(1,stable_null()) is not null as inlined_func, + make_ct1(1,volatile_null()) is not null as called_func; + row_cons | row_literal | inlined_const | inlined_func | called_func +----------+-------------+---------------+--------------+------------- + f | f | f | f | f +(1 row) + +select row(1,row(null,null)::ct1)::ct2 is not null as row_cons, + '(1,"(,)")'::ct2 is not null as row_literal, + make_ct2(1,null) is not null as inlined_const, + make_ct2(1,stable_null()) is not null as inlined_func, + make_ct2(1,volatile_null()) is not null as called_func; + row_cons | row_literal | inlined_const | inlined_func | called_func +----------+-------------+---------------+--------------+------------- + t | t | t | t | t +(1 row) + +select row(1,row(null,row(null,null)::ct1)::ct2)::ct3 is not null as row_cons, + '(1,"(,""(,)"")")'::ct3 is not null as row_literal, + make_ct3(1,null) is not null as inlined_const, + make_ct3(1,stable_null()) is not null as inlined_func, + make_ct3(1,volatile_null()) is not null as called_func; + row_cons | row_literal | inlined_const | inlined_func | called_func +----------+-------------+---------------+--------------+------------- + t | t | t | t | t +(1 row) + +select row(null,null)::ct1 is null as row_cons, + '(,)'::ct1 is null as row_literal, + make_ct1(null,null) is null as inlined_const, + make_ct1(null,stable_null()) is null as inlined_func, + make_ct1(null,volatile_null()) is null as called_func; + row_cons | row_literal | inlined_const | inlined_func | called_func +----------+-------------+---------------+--------------+------------- + t | t | t | t | t +(1 row) + +select row(null,row(null,null)::ct1)::ct2 is null as row_cons, + '(,"(,)")'::ct2 is null as row_literal, + make_ct2(null,null) is null as inlined_const, + make_ct2(null,stable_null()) is null as inlined_func, + make_ct2(null,volatile_null()) is null as called_func; + row_cons | row_literal | inlined_const | inlined_func | called_func +----------+-------------+---------------+--------------+------------- + f | f | f | f | f +(1 row) + +select row(null,row(null,row(null,null)::ct1)::ct2)::ct3 is null as row_cons, + '(,"(,""(,)"")")'::ct3 is null as row_literal, + make_ct3(null,null) is null as inlined_const, + make_ct3(null,stable_null()) is null as inlined_func, + make_ct3(null,volatile_null()) is null as called_func; + row_cons | row_literal | inlined_const | inlined_func | called_func +----------+-------------+---------------+--------------+------------- + f | f | f | f | f +(1 row) + diff --git a/src/test/regress/sql/rowtypes.sql b/src/test/regress/sql/rowtypes.sql index 677d34a..5faa7e6 100644 --- a/src/test/regress/sql/rowtypes.sql +++ b/src/test/regress/sql/rowtypes.sql @@ -286,3 +286,72 @@ create temp table tt1 as select * from int8_tbl limit 2; create temp table tt2 () inherits(tt1); insert into tt2 values(0,0); select row_to_json(r) from (select q2,q1 from tt1 offset 0) r; + +-- +-- test IS [NOT] NULL on nested cases, to ensure consistency +-- (bug #14235) +-- + +create type ct1 as (a integer, b integer); +create type ct2 as (a integer, b ct1); +create type ct3 as (a integer, b ct2); + +create function make_ct1(integer,integer) returns ct1 + language sql immutable + as $f$ select row($1,$2*$2)::ct1; $f$; + +create function make_ct2(integer,integer) returns ct2 + language sql immutable + as $f$ select row($1,row($2,$2)::ct1)::ct2; $f$; + +create function make_ct3(integer,integer) returns ct3 + language sql immutable + as $f$ select row($1,row($2,row($2,$2)::ct1)::ct2)::ct3; $f$; + +create function stable_null() returns integer + language plpgsql stable cost 1 + as $f$ begin return null; end; $f$; + +create function volatile_null() returns integer + language plpgsql volatile cost 1000 + as $f$ begin return null; end; $f$; + +select row(null,null)::ct1 is null as ct1, + row(null,row(null,null)::ct1)::ct2 is null as ct2, + row(null,row(null,row(null,null)::ct1)::ct2)::ct3 is null as ct3; + +select row(1,null)::ct1 is not null as row_cons, + '(1,)'::ct1 is not null as row_literal, + make_ct1(1,null) is not null as inlined_const, + make_ct1(1,stable_null()) is not null as inlined_func, + make_ct1(1,volatile_null()) is not null as called_func; + +select row(1,row(null,null)::ct1)::ct2 is not null as row_cons, + '(1,"(,)")'::ct2 is not null as row_literal, + make_ct2(1,null) is not null as inlined_const, + make_ct2(1,stable_null()) is not null as inlined_func, + make_ct2(1,volatile_null()) is not null as called_func; + +select row(1,row(null,row(null,null)::ct1)::ct2)::ct3 is not null as row_cons, + '(1,"(,""(,)"")")'::ct3 is not null as row_literal, + make_ct3(1,null) is not null as inlined_const, + make_ct3(1,stable_null()) is not null as inlined_func, + make_ct3(1,volatile_null()) is not null as called_func; + +select row(null,null)::ct1 is null as row_cons, + '(,)'::ct1 is null as row_literal, + make_ct1(null,null) is null as inlined_const, + make_ct1(null,stable_null()) is null as inlined_func, + make_ct1(null,volatile_null()) is null as called_func; + +select row(null,row(null,null)::ct1)::ct2 is null as row_cons, + '(,"(,)")'::ct2 is null as row_literal, + make_ct2(null,null) is null as inlined_const, + make_ct2(null,stable_null()) is null as inlined_func, + make_ct2(null,volatile_null()) is null as called_func; + +select row(null,row(null,row(null,null)::ct1)::ct2)::ct3 is null as row_cons, + '(,"(,""(,)"")")'::ct3 is null as row_literal, + make_ct3(null,null) is null as inlined_const, + make_ct3(null,stable_null()) is null as inlined_func, + make_ct3(null,volatile_null()) is null as called_func; --=-=-= Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --=-=-=--