You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
106334: xform: compute distribution of a lookup join with a lookup join as input r=rytaft a=msirek
The adjustment to optimizer costing of lookup joins, added in v23.1,
to account for non-local input relation distribution (among the regions
in a multiregion database) did not account for the case where the
input to the lookup join is itself a lookup join. This resulted in an
extra distribution cost being added to some best-cost lookup joins,
causing the optimizer to no longer select them.
The issue is in function `getCRBDRegionColFromInput`, which only looks
for scan and locality-optimized scan operations as inputs. It is now
updated with a recursive call to itself plus a call to
`BuildLookupJoinLookupTableDistribution`, so the proper distribution
of a chain of lookup joins, plus the associated `crdb_region` column
in the lookup table can be determined. Function
`BuildLookupJoinLookupTableDistribution` is updated to return the
first lookup index column, when it is matched with the input's
crdb_region column, to facilitate this behavior.
Fixes: cockroachdb#105942
Release note (bug fix): This patch fixes an optimizer costing bug
introduced in v23.1 which may cause a query involving 2 or more
joins with REGIONAL BY ROW tables to not pick the most optimal
lookup joins.
----
xform: improve detection of local lookup joins with RBR tables
This commit improves the optimizer's ability to detect the proper
distribution of a string of lookup joins involving REGIONAL BY ROW
tables by updating the interfaces which match on the `crdb_region`
key column of the join to use a `ColSet` which holds all of the
`crdb_region` column ids which have been equated with eachother.
Informs: cockroachdb#105942
Release note (bug fix): This patch fixes an optimizer costing bug
introduced in v23.1 which may cause a query whose best-cost query
plan is a string of lookup joins with REGIONAL BY ROW tables, one
after the other in sequence, to not pick the most optimal join plan.
----
execbuilder: use lookup join lookup table distribution in home region checking
This commit updates enforce_home_region checking to build the lookup
join lookup table's distribution the same as is done in the coster.
This can prevent some lookup joins with a home region from being
errored out as not having a home region.
Informs: cockroachdb#105942
Release note: None
----
memo: print lookup table distribution in EXPLAIN output
This commit adds the distribution of the lookup table of lookup join to
the EXPLAIN output when it is not empty.
Informs: cockroachdb#105942
Release note: None
Co-authored-by: Mark Sirek <[email protected]>
# Locality optimized search with lookup join will be supported in phase 2 or 3
640
-
# when we can dynamically determine if the lookup will access a remote region.
641
-
retry
642
-
statement error pq: Query has no home region\. Try adding a filter on o\.crdb_region and/or on key column \(o\.id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
643
-
SELECT * FROM customers c JOIN orders o ON c.id = o.cust_id AND
645
+
# Static checking should not error this query out, because we now generate a
646
+
# plan with a home region for it.
647
+
query T retry
648
+
EXPLAIN (OPT) SELECT * FROM customers c JOIN orders o ON c.id = o.cust_id AND
649
+
(c.crdb_region = o.crdb_region) WHERE c.id = '69a1c2c2-5b18-459e-94d2-079dc53a4dd0'
# This query should error out dynamically during execution, but
667
+
# `GetLookupJoinLookupTableDistribution` doesn't currently work in
668
+
# the execbuilder phase because `Optimizer.stateMap` is empty.
669
+
# TODO(msirek): Fix this test case to not error out statically.
670
+
statement error pq: Query has no home region\. Try adding a filter on o\.crdb_region and/or on key column \(o\.cust_id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
671
+
SELECT 'a' FROM customers c JOIN orders o ON c.id = o.cust_id AND
644
672
(c.crdb_region = o.crdb_region) WHERE c.id = '69a1c2c2-5b18-459e-94d2-079dc53a4dd0'
0 commit comments