Re: Removing unneeded self joins
Alexander Kuzmenkov <a.kuzmenkov@postgrespro.ru>
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
On 3/25/19 07:07, David Rowley wrote: > You had commented the test with: > > -- If index conditions are different for each side, we won't select the same > -- row on both sides, so the join can't be removed. > > but I don't quite understand why we can't remove the join in this > situation. My rationale was that we're not exactly removing the join, but replacing it with a scan. So it is not enough to just have a single row on each side, it must be the same physical row. In this example, before the transformation, t1.b is not equal to t2.b, but they become equal afterwards. This looks somewhat wrong. On the other hand, if the conditions are different, the resulting condition is going to evaluate to constant false and we won't get any rows, so maybe it's OK. This brings me again to the question of what are the conditions for join removal. If the formulation with indexes is not general enough, what do we use instead? I guess it could be something like this: 1. Given the (btree equality) join and restriction clauses, both sides are unique on the same set of columns. That is, if we fix the values of these columns, both sides have at most one matching row. a. For each of these columns, we have either i) a join clause that equates some expression referencing the outer column to the same expression referencing the same inner column. ii) a clause for each relation that equates the same expression referencing the outer and inner column to some other arbitrary expression, possibly a different one for each side. This expression may be a Const or some expression that references a Var of some third relation. 2. All the resulting columns can be calculated using either side of the join. For now, just require that both sides are base relations that refer to the same physical relation. Two points are not clear to me here: 1. We don't handle join clauses to third relations, but can they be treated the same way we treat Consts? 2. Can we simplify the join when we don't have any join clauses and only have Consts? Or should we have at least one join clause that equates the same inner and outer column? Why is one join clause enough? -- Alexander Kuzmenkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company