Skip to content

2.25.0.0-b469

tagged this 16 Dec 10:03
Summary:
This diff fixes a bug that disallowed BNL's from being formed where the inner side contains partitioned/child rels. Usually, an index scan path that accepts batched relations is formed in `indexpath.c::yb_get_batched_index_paths` if there is a compatible batchable join clause passed to it. A batchable join clause on index relation is compatible if one of either its LHS/RHS refers to the indexed relation. In the case where this relation is a child partition rel, the same rule applies -- a compatible batched join clause must refer to the child rel not its parent rel. Unfortunately, in the case of outer joins the join clauses being passed in referred to the parent rel instead of the appropriate child rel, disallowing a batch-accepting index path to be formed.

The set of clauses being passed to `indexpath.c::yb_get_batched_index_paths` can either come from implied equivalence class expressions or explicit join clauses. A join clause might fall into the former case if it's an inner join clause. These clauses and their batched equivalents are formed in `equivclass.c::generate_join_implied_equalities` and correctly referred to appropriate child rels. However, in the other case where a join clause from the set passed into `yb_get_batched_index_paths` might be pulled from `Relation->joininfo` by `indxpath.c::match_join_clauses_to_index`. Clauses stored in the `joininfo` field of a relation are already assumed to be adjusted for that particular relation. When a child relation is formed [[ https://github.com/yugabyte/yugabyte-db/blob/5dc707d9e737c99068ef1d2d4ca1dd197faa5c67/src/postgres/src/backend/optimizer/path/allpaths.c#L1129 | here ]], any join clauses that the child inherits have its variable relids adjusted accordingly. Unfortunately, this adjustment did not extend to the `yb_batched_rinfo` field of the `RestrictInfo` join clauses, causing potential index path planners to throw away clauses from this `yb_batched_rinfo` as incompatibly referring to parent relations.

Because of the above, outer joins on partitioned relations did not produce candidate BNL plans while inner joins did.

Also as a part of this change, `get_cheapest_path_for_pathkeys` is also adjusted to prefer batch-accepting paths if `yb_prefer_bnl` is on.

Original commit: d91f628fc179f1b2f3a883aa872c94b6d2a8d0ec / D40594

Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressJoin'

Reviewers: mtakahara, gkukreja

Reviewed By: mtakahara

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D40695
Assets 2
Loading