Re: Making Vars outer-join aware
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "Finnerty, Jim" <jfinnert@amazon.com>
Cc: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-01T20:40:45Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Re-allow INDEX_VAR as rt_index in ChangeVarNodes().
- fbf80421ead5 16.0 landed
-
Fix thinkos in have_unsafe_outer_join_ref; reduce to Assert check.
- f50f029c497d 16.0 landed
-
Invent "join domains" to replace the below_outer_join hack.
- 3bef56e11650 16.0 landed
-
Do assorted mop-up in the planner.
- b448f1c8d83f 16.0 landed
-
Make Vars be outer-join-aware.
- 2489d76c4906 16.0 landed
-
Invent "multibitmapsets", and use them to speed up antijoin detection.
- e9e26b5e7166 16.0 landed
-
Add basic regression tests for semi/antijoin recognition.
- 0043aa6b8597 16.0 landed
-
Improve performance of adjust_appendrel_attrs_multilevel.
- 2f17b57017e5 16.0 landed
-
Refactor addition of PlaceHolderVars to joinrel targetlists.
- afa0ec30bfd1 16.0 landed
-
Use an explicit state flag to control PlaceHolderInfo creation.
- b3ff6c742f6c 16.0 landed
-
Make PlaceHolderInfo lookup O(1).
- 6569ca43973b 16.0 landed
"Finnerty, Jim" <jfinnert@amazon.com> writes: > Given that views are represented in a parsed representation, does anything need to happen to the Vars inside a view when that view is outer-joined to? No. The markings only refer to what is in the same Query tree as the Var itself. Subquery flattening during planning does deal with this: if we pull up a subquery (possibly inserted from a view) that was underneath an outer join, the nullingrel marks on the upper-level Vars referring to subquery outputs will get merged into what is pulled up, either by unioning the varnullingrel bitmaps if what is pulled up is just a Var, or if what is pulled up isn't a Var, by wrapping it in a PlaceHolderVar that carries the old outer Var's markings. We had essentially this same behavior with PlaceHolderVars before, but I think this way makes it a lot more principled and intelligible (and I suspect there are now cases where we manage to avoid inserting unnecessary PlaceHolderVars that the old code couldn't avoid). > If an outer join is converted to an inner join, must this information get propagated to all the affected Vars, potentially across query block levels? Yes. The code is there in the patch to run around and remove nullingrel bits from affected Vars. One thing that doesn't happen (and didn't before, so this is not a regression) is that if we strength-reduce a FULL JOIN USING to an outer or plain join, it'd be nice if the "COALESCE" hack we represent the merged USING column with could be replaced with the same lower-relation Var that the parser would have used if the join weren't FULL to begin with. Without that, we're leaving optimization opportunities on the table. I'm hesitant to try to do that though as long as the COALESCE structures look exactly like something a user could write. It'd be safer if we used some bespoke node structure for this purpose ... but nobody's bothered to invent that. regards, tom lane