forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: do not build cross-joins on inputs of lookup joins
Rules that generate lookup joins no longer build cross-joins on the input of the lookup join to constrain an index column to a set of constant values. Instead, a lookup expression is used which generates multiple lookup spans during execution. Building a cross-join added extra complexity to the optimizer logic and has been shown to be error prone (see cockroachdb#78681 and cockroachdb#79384). Also, a cross-join could significantly increase the number of input rows, so it was likely less efficient than using a lookup expression. If an index column is constrained to a single constant value, we still project the value in the input of the lookup join so that it can be used as an equality column. This is more performant than using a lookup expression with an equality condition (see cockroachdb#66726). This commit the some other notable changes to the lookup join generation logic: 1. `inputProjections` is now initialized with a specific capacity to ensure that future appends will not cause allocations. 2. The logic has been reordered. The case when a single constant value is projected is handled before the multiple constant value or range cases. 3. An unnecessary projection is no longer added for single constant values when we revert to using a lookup expression. An explicit test was added for this. 4. Fix `isCanonicalLookupJoinFilter` so that expressions with inequalities and either an equality or `IN` are not used as lookup expressions. The `multiSpanGenerator` does not support these types of expressions, and would panic if it encountered them. This bug has existed for a while, but has been hidden because of the preference for the cross-join strategy. Note that there are several cases where a lookup join contains filters in the `ON` expression that are redundant with the lookup expression. I'm planning on addressing this in a future commit. Note that this commit does not affect inverted joins. Cross-joins can still be generated on inverted join inputs. Release note: None
- Loading branch information
Showing
14 changed files
with
756 additions
and
1,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.