-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Move more horizon planning to the operators #13412
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
Merged
harshit-gangal
merged 27 commits into
vitessio:main
from
planetscale:continue-horizon-planning
Jul 5, 2023
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c2171b9
error out if we have aggregate gtid in handleAggr
frouioui da016f0
remove un-required for loop
frouioui 2139472
add GetSelectExprs to the operator interface and remove horizon/derived
frouioui 6ccbcc9
support distinct aggregations on the new horizon planner
systay d52f903
stop pushing of aggregation filtering into derived tables
systay 3f84063
wip - enable derived tables in the new horizon planner
frouioui 64aa0fb
Bring back support for union inside derived tables
frouioui 3280d79
fix typo in error
frouioui c5d7eb8
update test expectations
systay 2e31f83
use semantics.RewriteDerivedTableExpression instead of manual rewriti…
systay 9a11f44
work on making derived tables with aggregation work
systay 7796a6e
refactor code
systay b134c92
enable horizon planning in more situations
systay 3da1903
update test expectations
systay c9fcec9
make sure to always use a method to create aggregate params
systay 92d28de
cleanup and refactoring
systay 3cb619e
use weight strings for min/max
systay 77d630a
update list of error code
frouioui b320671
disallow aggregation on top of aggregation with a clearer error message
systay f016a89
fail min/max queries on types we cant compare
systay f6d57f0
test: remove pattern not used
systay 0f9d320
spread table id through derived tables
systay 8aeb0dd
add ordering bottom up so the order can be re-used
systay 14c7bce
unify Derived and Horizon into a single struct
systay fb61542
refactor: aggregation-pushing
systay 15453dc
add support handling sum(distinct x) and count(distinct x) on top of …
systay a1901f0
Merge remote-tracking branch 'upstream/main' into continue-horizon-pl…
systay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ import ( | |
| "fmt" | ||
| "strconv" | ||
|
|
||
| "vitess.io/vitess/go/vt/vterrors" | ||
|
|
||
| "google.golang.org/protobuf/proto" | ||
|
|
||
| "vitess.io/vitess/go/mysql/collations" | ||
|
|
@@ -41,7 +43,6 @@ type AggregateParams struct { | |
| // These are used only for distinct opcodes. | ||
| KeyCol int | ||
| WCol int | ||
| WAssigned bool | ||
| CollationID collations.ID | ||
|
|
||
| Alias string `json:",omitempty"` | ||
|
|
@@ -53,22 +54,26 @@ type AggregateParams struct { | |
| OrigOpcode AggregateOpcode | ||
| } | ||
|
|
||
| func (ap *AggregateParams) isDistinct() bool { | ||
| return ap.Opcode == AggregateCountDistinct || ap.Opcode == AggregateSumDistinct | ||
| func NewAggregateParam(opcode AggregateOpcode, col int, alias string) *AggregateParams { | ||
| out := &AggregateParams{ | ||
| Opcode: opcode, | ||
| Col: col, | ||
| Alias: alias, | ||
| WCol: -1, | ||
| } | ||
| if opcode.NeedsComparableValues() { | ||
| out.KeyCol = col | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func (ap *AggregateParams) preProcess() bool { | ||
| switch ap.Opcode { | ||
| case AggregateCountDistinct, AggregateSumDistinct, AggregateGtid, AggregateCount, AggregateGroupConcat: | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| func (ap *AggregateParams) WAssigned() bool { | ||
| return ap.WCol >= 0 | ||
| } | ||
|
|
||
| func (ap *AggregateParams) String() string { | ||
| keyCol := strconv.Itoa(ap.Col) | ||
| if ap.WAssigned { | ||
| if ap.WAssigned() { | ||
| keyCol = fmt.Sprintf("%s|%d", keyCol, ap.WCol) | ||
| } | ||
| if ap.CollationID != collations.Unknown { | ||
|
|
@@ -161,7 +166,7 @@ func merge( | |
| ) ([]sqltypes.Value, []sqltypes.Value, error) { | ||
| result := sqltypes.CopyRow(row1) | ||
| for index, aggr := range aggregates { | ||
| if aggr.isDistinct() { | ||
| if aggr.Opcode.IsDistinct() { | ||
| if row2[aggr.KeyCol].IsNull() { | ||
| continue | ||
| } | ||
|
|
@@ -194,8 +199,14 @@ func merge( | |
| } | ||
| result[aggr.Col], err = evalengine.NullSafeAdd(value, v2, fields[aggr.Col].Type) | ||
| case AggregateMin: | ||
| if aggr.WAssigned() && !row2[aggr.Col].IsComparable() { | ||
| return minMaxWeightStringError() | ||
| } | ||
| result[aggr.Col], err = evalengine.Min(row1[aggr.Col], row2[aggr.Col], aggr.CollationID) | ||
| case AggregateMax: | ||
| if aggr.WAssigned() && !row2[aggr.Col].IsComparable() { | ||
| return minMaxWeightStringError() | ||
| } | ||
| result[aggr.Col], err = evalengine.Max(row1[aggr.Col], row2[aggr.Col], aggr.CollationID) | ||
| case AggregateCountDistinct: | ||
| result[aggr.Col], err = evalengine.NullSafeAdd(row1[aggr.Col], countOne, fields[aggr.Col].Type) | ||
|
|
@@ -241,6 +252,10 @@ func merge( | |
| return result, curDistincts, nil | ||
| } | ||
|
|
||
| func minMaxWeightStringError() ([]sqltypes.Value, []sqltypes.Value, error) { | ||
| return nil, nil, vterrors.VT12001("min/max on types that are not comparable is not supported") | ||
| } | ||
|
|
||
| func convertFinal(current []sqltypes.Value, aggregates []*AggregateParams) ([]sqltypes.Value, error) { | ||
| result := sqltypes.CopyRow(current) | ||
| for _, aggr := range aggregates { | ||
|
|
@@ -270,17 +285,13 @@ func convertFields(fields []*querypb.Field, aggrs []*AggregateParams) []*querypb | |
| if aggr.Alias != "" { | ||
| fields[aggr.Col].Name = aggr.Alias | ||
| } | ||
| if aggr.isDistinct() { | ||
| // TODO: this should move to plan time | ||
| aggr.KeyCol = aggr.Col | ||
| } | ||
|
Comment on lines
-273
to
-276
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discussed, changing this on plan time is a problem. we would need to have local KeyCol index and passed in while execution. |
||
| } | ||
| return fields | ||
| } | ||
|
|
||
| func findComparableCurrentDistinct(row []sqltypes.Value, aggr *AggregateParams) sqltypes.Value { | ||
| curDistinct := row[aggr.KeyCol] | ||
| if aggr.WAssigned && !curDistinct.IsComparable() { | ||
| if aggr.WAssigned() && !curDistinct.IsComparable() { | ||
| aggr.KeyCol = aggr.WCol | ||
| curDistinct = row[aggr.KeyCol] | ||
| } | ||
|
|
||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.