Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-12 Thread Richard Guo
On Fri, Apr 12, 2024 at 4:19 PM David Rowley wrote: > After further work on the comments, I pushed the result. > > Thanks for working on this. Thanks for pushing! BTW, I noticed a typo in the comment of add_base_clause_to_rel. --- a/src/backend/optimizer/plan/initsplan.c +++

Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-12 Thread David Rowley
On Thu, 11 Apr 2024 at 18:49, Richard Guo wrote: > I agree with both of your points. But I also think we do not need to > skip applying the NOT NULL qual optimization for partitioned tables. > For partitioned tables, if the parent is marked NOT NULL, then all its > children must also be marked

Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-11 Thread Richard Guo
On Thu, Apr 11, 2024 at 10:23 AM David Rowley wrote: > On Wed, 10 Apr 2024 at 19:12, Richard Guo wrote: > > And I think recording NOT NULL columns for traditional inheritance > > parents can be error-prone for some future optimization where we look > > at an inheritance parent's notnullattnums

Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-10 Thread David Rowley
On Wed, 10 Apr 2024 at 19:12, Richard Guo wrote: > And I think recording NOT NULL columns for traditional inheritance > parents can be error-prone for some future optimization where we look > at an inheritance parent's notnullattnums and make decisions based on > the assumption that the included

Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-10 Thread Richard Guo
On Wed, Apr 10, 2024 at 1:13 PM David Rowley wrote: > I looked at the patch and I don't think it's a good idea to skip > recording NOT NULL constraints to fix based on the fact that it > happens to result in this particular optimisation working correctly. > It seems that just makes this work in

Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-09 Thread David Rowley
On Wed, 10 Apr 2024 at 17:18, Tom Lane wrote: > > David Rowley writes: > > I think a better fix is just to not apply the optimisation for > > inheritance RTEs in add_base_clause_to_rel(). > > Is it worth paying attention to whether the constraint is marked > connoinherit? If that involves an

Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-09 Thread Tom Lane
David Rowley writes: > I think a better fix is just to not apply the optimisation for > inheritance RTEs in add_base_clause_to_rel(). Is it worth paying attention to whether the constraint is marked connoinherit? If that involves an extra syscache fetch, I'd tend to agree that it's not worth

Re: Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-09 Thread David Rowley
On Tue, 9 Apr 2024 at 21:55, Richard Guo wrote: > > In b262ad440e we introduced an optimization that drops IS NOT NULL quals > on a NOT NULL column, and reduces IS NULL quals on a NOT NULL column to > constant-FALSE. I happened to notice that this is not working correctly > for traditional

Incorrect handling of IS [NOT] NULL quals on inheritance parents

2024-04-09 Thread Richard Guo
In b262ad440e we introduced an optimization that drops IS NOT NULL quals on a NOT NULL column, and reduces IS NULL quals on a NOT NULL column to constant-FALSE. I happened to notice that this is not working correctly for traditional inheritance parents. Traditional inheritance parents might have