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.