Re: Removing unneeded self joins
Alexander Korotkov <aekorotkov@gmail.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Remove GUC_NOT_IN_SAMPLE from enable_self_join_elimination
- 717d0e8dd945 18.0 landed
-
Put enable_self_join_elimination into postgresql.conf.sample
- c2d329260cd8 18.0 landed
-
Get rid of ojrelid local variable in remove_rel_from_query()
- e167191dc146 18.0 landed
-
Implement Self-Join Elimination
- fc069a3a6319 18.0 cited
-
Revert: Remove useless self-joins
- d1d286d83c0e 17.0 landed
-
Replace lateral references to removed rels in subqueries
- 466979ef031a 17.0 landed
-
Replace relids in lateral subquery parse tree during SJE
- 489072ab7a9e 17.0 landed
-
Forbid SJE with result relation
- 8c441c082797 17.0 landed
-
Fix misuse of RelOptInfo.unique_for_rels cache by SJE
- 30b4955a4668 17.0 landed
-
Replace the relid in some missing fields during SJE
- a7928a57b9f0 17.0 landed
-
Revert 56-bit relfilenode change and follow-up commits.
- a448e49bcbe4 16.0 cited
-
Stabilize timetz test across DST transitions.
- 4a071afbd056 14.0 cited
-
Speed up finding EquivalenceClasses for a given set of rels
- 3373c7155350 13.0 cited
-
Fix mark-and-restore-skipping test case to not be a self-join.
- 24d08f3c0a1f 12.0 landed
Attachments
- v2-0002-Minor-refactoring-for-self-join-elimination-code.patch (application/octet-stream) patch v2-0002
- v2-0003-Forbid-self-join-elimination-on-table-sampling-sc.patch (application/octet-stream) patch v2-0003
- v2-0004-Fix-self-join-elimination-work-with-PlaceHolderIn.patch (application/octet-stream) patch v2-0004
- v2-0001-Clarify-the-SJE-self-join-elimination-acronym.patch (application/octet-stream) patch v2-0001
Hi, Richard! On Thu, May 2, 2024 at 4:14 PM Richard Guo <guofenglinux@gmail.com> wrote: > On Thu, May 2, 2024 at 6:08 PM Alexander Korotkov <aekorotkov@gmail.com> wrote: >> On Thu, May 2, 2024 at 12:45 PM Andrei Lepikhov >> <a.lepikhov@postgrespro.ru> wrote: >> > One question for me is: Do we anticipate other lateral self-references >> > except the TABLESAMPLE case? Looking into the extract_lateral_references >> > implementation, I see the only RTE_SUBQUERY case to be afraid of. But we >> > pull up subqueries before extracting lateral references. So, if we have >> > a reference to a subquery, it means we will not flatten this subquery >> > and don't execute SJE. Do we need more code, as you have written in the >> > first patch? >> >> I think my first patch was crap anyway. Your explanation seems >> reasonable to me. I'm not sure this requires any more code. Probably >> it would be enough to add more comments about this. > > > The tablesample case is not the only factor that can cause a relation to > have a lateral dependency on itself after self-join removal. It can > also happen with PHVs. As an example, consider > > explain (costs off) > select * from t t1 > left join lateral > (select t1.a as t1a, * from t t2) t2 > on true > where t1.a = t2.a; > server closed the connection unexpectedly > > This is because after self-join removal, a PlaceHolderInfo's ph_lateral > might contain rels mentioned in ph_eval_at, which we should get rid of. > > For the tablesample case, I agree that we should not consider relations > with TABLESAMPLE clauses as candidates to be removed. Removing such a > relation could potentially change the syntax of the query, as shown by > Alexander's example. It seems to me that we can just check that in > remove_self_joins_recurse, while we're collecting the base relations > that are considered to be candidates for removal. > > This leads to the attached patch. This patch also includes some code > refactoring for the surrounding code. Great, thank you for your work on this! I'd like to split this into separate patches for better granularity of git history. I also added 0001 patch, which makes first usage of the SJE acronym in file to come with disambiguation. Also, I've added assert that ph_lateral and ph_eval_at didn't overlap before the changes. I think this should help from the potential situation when the changes we do could mask another bug. I would appreciate your review of this patchset, and review from Andrei as well. ------ Regards, Alexander Korotkov Supabase