BUG #14235: inconsistencies with IS NULL / IS NOT NULL

From: andrew(at)tao11(dot)riddles(dot)org(dot)uk
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14235: inconsistencies with IS NULL / IS NOT NULL
Date: 2016-07-08 02:47:46
Message-ID: 20160708024746.1410.57282@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14235
Logged by: Andrew Gierth
Email address: andrew(at)tao11(dot)riddles(dot)org(dot)uk
PostgreSQL version: 9.6beta2
Operating system: any
Description:

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

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

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;

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrew Gierth 2016-07-08 03:10:10 Re: BUG #14235: inconsistencies with IS NULL / IS NOT NULL
Previous Message Prashanth Adiyodi 2016-07-08 02:40:56 Re: Where clause in pg_dump: need help