-
Notifications
You must be signed in to change notification settings - Fork 64
Add projection pushdown optimizer #549
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
base: main
Are you sure you want to change the base?
Conversation
7d823ac
to
7a5c77d
Compare
storage/prometheus/scanners.go
Outdated
@@ -53,6 +53,10 @@ func (p Scanners) NewVectorSelector( | |||
hints storage.SelectHints, | |||
logicalNode logicalplan.VectorSelector, | |||
) (model.VectorOperator, error) { | |||
// Update hints with projection information if available | |||
hints.Grouping = logicalNode.Projection.Labels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nicer if we could add projection hints in Select natively
671ad73
to
6d92802
Compare
Signed-off-by: yeya24 <[email protected]>
Signed-off-by: yeya24 <[email protected]>
Signed-off-by: yeya24 <[email protected]>
Signed-off-by: yeya24 <[email protected]>
c48628e
to
a2d70e2
Compare
Signed-off-by: yeya24 <[email protected]>
This is unrelated to this change but seems a valid data race.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took an initial look. Only nits now. I'll take a closer looks later on.
@@ -121,6 +127,11 @@ func (p Scanners) NewMatrixSelector( | |||
} | |||
|
|||
vs := logicalNode.VectorSelector | |||
if vs.Projection != nil { | |||
hints.Grouping = vs.Projection.Labels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reuse the grouping hints? What is it used for currently?
Grouping []string // List of label names used in aggregation.
By bool // Indicate whether it is without or by.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://cloud-native.slack.com/archives/C08GK56D2H1/p1742377016587459?thread_ts=1742377016.587459&cid=C08GK56D2H1 some context available here; maybe worth adding a short version of this to a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing this. The thread was talking about a new field []ProjectionLabels
in SelectHInts
specifically for projection. Did the community agree on using []Grouping
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can put this projection overwriting grouping
and by
behavior under a FF so it shouldn't impact users who already use those hints.
Anyway, this is just the scanner implementation (physical plan) and whoever wants to utilize the Projection hints from the Optimizer can just implement their own scanner to handle Projection hints themselves.
Once we extend the select hints with projection specific fields we can have better support in this scanner.
@@ -87,7 +87,11 @@ func (f *VectorSelector) Clone() Node { | |||
|
|||
clone.Filters = shallowCloneSlice(f.Filters) | |||
clone.LabelMatchers = shallowCloneSlice(f.LabelMatchers) | |||
clone.Projection.Labels = shallowCloneSlice(f.Projection.Labels) | |||
if f.Projection != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should Projection.Clone() be implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized that Projection
is not a logical node.
engine/pushdown_test.go
Outdated
// Copyright (c) The Thanos Community Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package engine_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the current fuzz tests be extended to include projection pushdown once the issue with MergeSelects optimizer is fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's the plan. I expect this can only be merged after we have proper MergeSelects support as MergeSelects is by default enabled.
logicalplan/projection_pushdown.go
Outdated
} | ||
|
||
// pushProjection recursively traverses the tree and pushes projection information down. | ||
func (p ProjectionPushdown) pushProjection(node *Node, requiredLabels map[string]struct{}, isWithout bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this method be refactored? Maybe independent methods for each type of node types similar to how it's in execution.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you referring to adding another method in the logical node interface? https://github.com/thanos-io/promql-engine/blob/main/logicalplan/logical_nodes.go
I feel the logic of pushProjection
is kind of specific to this optimizer. I am not sure if it is worth it as it seems not reusable in other places.
Nice thanks @fpetkovski. Your implementation is much cleaner. I will definitely take a closer look |
Signed-off-by: yeya24 <[email protected]>
Signed-off-by: yeya24 <[email protected]>
I tried to implement projection support for merge select and I am able to create a working version in yeya24@6c7b7a2. It is able to pass correctness tests when I tried it locally. However, I kind of doubt if it is worth pursuing due to several limitations:
Things can be probably simplified a bit if we assume duplicate label check is disabled. However, this might impact something else of the optimizer and might not work for all cases. I would propose that we skip merge select optimizer for now for projection even though it is working using the code above. Merge select optimizer should check if we have projection in vector selector. If projection is enabled, don't try to merge select. Or vice versa, don't do projection pushdown if merge select is applied |
Signed-off-by: yeya24 <[email protected]>
30502cb
to
a35726d
Compare
Changes made to latest commit a35726d to don't merge select for vector selector with projection |
Fixes #496
This PR adds an implementation of Projection Pushdown optimizer which checks the expression and injects projection to vector selector accordingly.
Note:
scalar
,absent
andabsent_over_time
by inspiration from Add optimizer for extracting projection labels #550It is able to pass promqlsmith based fuzz test locally by using a mock implementation of projection querier.