Re: Keep notnullattrs in RelOptInfo (Was part of UniqueKey patch series)

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, "Hou, Zhijie" <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com>, Floris Van Nee <florisvannee(at)optiver(dot)com>
Subject: Re: Keep notnullattrs in RelOptInfo (Was part of UniqueKey patch series)
Date: 2021-07-03 14:08:26
Message-ID: CAKU4AWrcp00x=QFNEZWvdTsaDewnaeN5vhXfVoLhWQYzPQ+8yw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi:
I'd start to work on UniqueKey again, it would be great that we can target
it
to PG 15. The attached patch is just for the notnull_attrs. Since we can't
say
a column is nullable or not without saying in which resultset, so I think
attaching
it to RelOptInfo is unavoidable. Here is how my patch works.

@@ -686,6 +686,12 @@ typedef struct RelOptInfo
/* default result targetlist for Paths scanning this relation */
struct PathTarget *reltarget; /* list of Vars/Exprs, cost, width */

+ Bitmapset **notnull_attrs; /* The attno which is not null after evaluating
+ * all the quals on this relation, for baserel,
+ * the len would always 1. and for others the array
+ * index is relid from relids.
+ */
+

For baserel, it records the notnull attrs as a bitmapset and stores it to
RelOptInfo->notnull_attrs[0]. As for the joinrel, suppose the relids is
{1,3,
5}, then the notnull_attrs[1/3/5] will be used to store notnull_attrs
Bitmapset
for relation 1,3,5 separately. I don't handle this stuff for all kinds of
upper
relation and subquery so far since UniqueKey doesn't rely on it and looks
more stuff should be handled there.

The patch also included some debug messages in
set_baserel/joinrel_notnullattrs
and attached the test.sql for easier review. Any feedback is welcome and
hope
this implementation would not block UniqueKey stuff.

Attachment Content-Type Size
v1-0001-add-the-not-null-attrs-for-RelOptInfo.-Here-is-ho.patch application/octet-stream 9.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-07-03 14:10:13 Re: Preventing abort() and exit() calls in libpq
Previous Message Peter Eisentraut 2021-07-03 11:38:53 Re: [PATCH v3 1/1] Fix detection of preadv/pwritev support for OSX.