Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xform: reorganize rules and tests for consistency #55654

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pkg/sql/opt/norm/testdata/rules/combo
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,15 @@ PruneJoinRightCols
GenerateIndexScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GeneratePartialIndexScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateConstrainedScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateIndexScans (no changes)
--------------------------------------------------------------------------------
================================================================================
Expand Down Expand Up @@ -583,9 +583,6 @@ GenerateIndexScans
├── s:4 = 'foo' [outer=(4), constraints=(/4: [/'foo' - /'foo']; tight), fd=()-->(4)]
└── f:3 > 100.0 [outer=(3), constraints=(/3: [/100.00000000000001 - ]; tight)]
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GeneratePartialIndexScans (no changes)
--------------------------------------------------------------------------------
================================================================================
Expand All @@ -610,6 +607,9 @@ GenerateConstrainedScans
- ├── s:4 = 'foo' [outer=(4), constraints=(/4: [/'foo' - /'foo']; tight), fd=()-->(4)]
- └── f:3 > 100.0 [outer=(3), constraints=(/3: [/100.00000000000001 - ]; tight)]
+ └── fd: ()-->(4), (1)-->(3), (3)-->(1)
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
================================================================================
Final best expression
Cost: 14.10
Expand Down Expand Up @@ -2872,15 +2872,15 @@ GenerateIndexScans (no changes)
GenerateIndexScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GeneratePartialIndexScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateConstrainedScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
ReorderJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions pkg/sql/opt/testutils/opttester/testdata/explore-trace
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ New expression 1 of 1:
└── const: 1 [type=int]

================================================================================
GenerateZigzagJoins
GeneratePartialIndexScans
================================================================================
Source expression:
select
Expand All @@ -57,7 +57,7 @@ Source expression:
No new expressions.

================================================================================
GeneratePartialIndexScans
GenerateConstrainedScans
================================================================================
Source expression:
select
Expand All @@ -73,10 +73,15 @@ Source expression:
├── variable: b:2 [type=int]
└── const: 1 [type=int]

No new expressions.
New expression 1 of 1:
scan ab@secondary
├── columns: a:1(int!null) b:2(int!null)
├── constraint: /2/1: [/1 - /1]
├── key: (1)
└── fd: ()-->(2)

================================================================================
GenerateConstrainedScans
GenerateZigzagJoins
================================================================================
Source expression:
select
Expand All @@ -92,12 +97,7 @@ Source expression:
├── variable: b:2 [type=int]
└── const: 1 [type=int]

New expression 1 of 1:
scan ab@secondary
├── columns: a:1(int!null) b:2(int!null)
├── constraint: /2/1: [/1 - /1]
├── key: (1)
└── fd: ()-->(2)
No new expressions.
----
----

Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/opt/testutils/opttester/testdata/opt-steps
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ GenerateIndexScans (higher cost)
├── variable: b:2 [type=int]
└── const: 1 [type=int]
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GeneratePartialIndexScans (no changes)
--------------------------------------------------------------------------------
================================================================================
Expand All @@ -167,6 +164,9 @@ GenerateConstrainedScans
- ├── variable: b:2 [type=int]
- └── const: 1 [type=int]
+ └── fd: ()-->(2)
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
================================================================================
Final best expression
Cost: 14.41
Expand Down Expand Up @@ -714,9 +714,6 @@ GenerateIndexScans (higher cost)
├── variable: k:1 [type=int]
└── const: 1 [type=int]
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GeneratePartialIndexScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -746,6 +743,9 @@ FoldComparison
- └── const: 1 [type=int]
+ ├── constraint: /2/1/3: [/true/1 - /true/1]
+ └── fd: ()-->(1)
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
================================================================================
Final best expression
Cost: 14.51
Expand Down
42 changes: 0 additions & 42 deletions pkg/sql/opt/xform/rules/join.opt
Original file line number Diff line number Diff line change
Expand Up @@ -234,48 +234,6 @@
$private
)

# GenerateZigzagJoins creates ZigzagJoin operators for all index pairs (of the
# Scan table) where the prefix column(s) of both indexes is/are fixed to
# constant values in the filters. See comments in GenerateZigzagJoin and
# distsqlrun/zigzagjoiner.go for more details on when a zigzag join can be
# planned.
#
# Zigzag joins are prohibited when the source Scan operator has been configured
# with a row-level locking mode. This is mostly out of convenience so that these
# row-level locking modes don't need to added to the ZigzagJoin operator. There
# doesn't seem to be a strong reason to support this, but if one comes up, it
# should be possible to lift this restriction.
[GenerateZigzagJoins, Explore]
(Select
(Scan $scan:*) & (IsCanonicalScan $scan) & ^(IsLocking $scan)
$filters:*
)
=>
(GenerateZigzagJoins $scan $filters)

# GenerateInvertedIndexZigzagJoins creates ZigzagJoin operators for inverted
# indexes that can be constrained with two or more distinct constant values.
# Inverted indexes contain one row for each path-to-leaf in a JSON value, so one
# row in the primary index could generate multiple inverted index keys. This
# property can be exploited by zigzag joining on the same inverted index, fixed
# at any two of the JSON paths we are querying for.
#
# Zigzag joins are prohibited when the source Scan operator has been configured
# with a row-level locking mode. This is mostly out of convenience so that these
# row-level locking modes don't need to added to the ZigzagJoin operator. There
# doesn't seem to be a strong reason to support this, but if one comes up, it
# should be possible to lift this restriction.
[GenerateInvertedIndexZigzagJoins, Explore]
(Select
(Scan $scan:*) &
(IsCanonicalScan $scan) &
^(IsLocking $scan) &
(HasInvertedIndexes $scan)
$filters:*
)
=>
(GenerateInvertedIndexZigzagJoins $scan $filters)

# GenerateLookupJoinWithFilter creates a LookupJoin alternative for a Join which
# has a Select->Scan combination as its right input. The filter can get merged
# with the ON condition (this is correct for inner, left, and semi/anti join).
Expand Down
42 changes: 42 additions & 0 deletions pkg/sql/opt/xform/rules/select.opt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,48 @@
=>
(GenerateInvertedIndexScans $scanPrivate $filters)

# GenerateZigzagJoins creates ZigzagJoin operators for all index pairs (of the
# Scan table) where the prefix column(s) of both indexes is/are fixed to
# constant values in the filters. See comments in GenerateZigzagJoin and
# distsqlrun/zigzagjoiner.go for more details on when a zigzag join can be
# planned.
#
# Zigzag joins are prohibited when the source Scan operator has been configured
# with a row-level locking mode. This is mostly out of convenience so that these
# row-level locking modes don't need to added to the ZigzagJoin operator. There
# doesn't seem to be a strong reason to support this, but if one comes up, it
# should be possible to lift this restriction.
[GenerateZigzagJoins, Explore]
(Select
(Scan $scan:*) & (IsCanonicalScan $scan) & ^(IsLocking $scan)
$filters:*
)
=>
(GenerateZigzagJoins $scan $filters)

# GenerateInvertedIndexZigzagJoins creates ZigzagJoin operators for inverted
# indexes that can be constrained with two or more distinct constant values.
# Inverted indexes contain one row for each path-to-leaf in a JSON value, so one
# row in the primary index could generate multiple inverted index keys. This
# property can be exploited by zigzag joining on the same inverted index, fixed
# at any two of the JSON paths we are querying for.
#
# Zigzag joins are prohibited when the source Scan operator has been configured
# with a row-level locking mode. This is mostly out of convenience so that these
# row-level locking modes don't need to added to the ZigzagJoin operator. There
# doesn't seem to be a strong reason to support this, but if one comes up, it
# should be possible to lift this restriction.
[GenerateInvertedIndexZigzagJoins, Explore]
(Select
(Scan $scan:*) &
(IsCanonicalScan $scan) &
^(IsLocking $scan) &
(HasInvertedIndexes $scan)
$filters:*
)
=>
(GenerateInvertedIndexZigzagJoins $scan $filters)

# SplitDisjunction splits disjunctions (Or expressions) into a Union of two
# Select expressions, the first containing the left sub-expression of the Or
# expression and the second containing the right sub-expression. All other
Expand Down
Loading