Re: BUG #17540: Prepared statement: PG switches to a generic query plan which is consistently much slower
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: william.duclot@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2022-07-07T03:31:30Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- v1-0001-Track-NOT-NULL-columns-in-RelOptInfo-for-base-rel.patch (text/plain) patch v1-0001
- v1-0002-Don-t-add-is-NOT-NULL-clause-to-MinMaxAggInfo-tra.patch (text/plain) patch v1-0002
On Thu, 7 Jul 2022 at 15:07, Tom Lane <tgl@sss.pgh.pa.us> wrote: > While I don't have any problem with tracking column NOT NULL flags > in RelOptInfo once the planner has a use for that info, I'm not sure > that we have a solid use-case for it quite yet. In particular, the > fact that the table column is marked NOT NULL doesn't mean that any > particular occurrence of that column's Var can be freely assumed to be > non-null. The patch I'm working on to label Vars that have possibly > been nulled by outer joins [1] seems like essential infrastructure for > doing anything very useful with the info. I was aware that you'd done that work. I'm interested in it, but just not found the time to look yet. > Maybe that objection doesn't apply to build_minmax_path's usage in > particular, but that's an awfully narrow use-case. I thought I'd quickly put the idea together and fairly quickly noticed that we do preprocess_minmax_aggregates() in grouping_planner(), which is long before we load the RelOptInfo data in add_base_rels_to_query(), which is called in query_planner(). I considered if we could move the preprocess_minmax_aggregates(), but that does not seem right, although, surprisingly, no tests seem to fail from doing so. I'd have expected at least some EXPLAIN outputs to have changed from the no-longer-present IS NOT NULL quals. I imagine a much less narrow case would be to check for redundant RestrictInfos in distribute_restrictinfo_to_rels(). That would also catch cases such as WHERE non_nullable_col IS NULL, provided that qual made it down to baserestrictinfo. When I realised that, I thought I might be starting to overlap with your work in the link below. > [1] https://www.postgresql.org/message-id/flat/830269.1656693747@sss.pgh.pa.us The 2 attached patches do fix the bad reported plan, it's just that it's a very roundabout way of fixing it Anyway, I've no current plans to take the attached any further. I think it'll be better to pursue your NULLable-Var stuff and see if we can do something more generic like remove provably redundant NullTests from baserestrictinfo. David
Commits
-
Add better handling of redundant IS [NOT] NULL quals
- b262ad440ede 17.0 landed