-
Notifications
You must be signed in to change notification settings - Fork 169
Do not attempt to push down calls with offsets #1129
Conversation
ab68577
to
e503cb1
Compare
e503cb1
to
28762d6
Compare
b6a5ff6
to
098a214
Compare
pkg/pgmodel/querier/query_builder.go
Outdated
|
||
// We can't handle offsets in pushdowns | ||
vs, isVectorSelector := queryHints.CurrentNode.(*parser.VectorSelector) | ||
if isVectorSelector && (vs.Offset != 0 || vs.OriginalOffset != 0) { |
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.
Base on Prometheus docs OriginalOffset
is actual offset set from the query so it seems no need to check Offset
as that is just derived during query execution.
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.
done
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.
The plot thickens: this change was not good. We do actually need to validate that both Offset
and OriginalOffset
are zero.
pkg/pgmodel/querier/query_builder.go
Outdated
} | ||
|
||
// We can't handle offsets in pushdowns | ||
vs, isVectorSelector := queryHints.CurrentNode.(*parser.VectorSelector) |
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.
Shouldn't we handle MatrixSelector
as well?
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 don't think so (but I might be missing something). A MatrixSelector doesn't have an offset, its fields are Range
and VectorSelector
. The contained VectorSelector
may have an offset, and will be handled by this logic.
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.
Hmm MatrixSelector
does not embed VectorSelector
but Expr
which may contain VectorSelector
. So I guess in case of MatrixSelector
it would not successfully type assert.
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.
In other words in case of MatrixSelector
we would need to type assert on it's . VectorSelector
field
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've restructured the code by folding the canAttemptPushdown
into tryPushDown
. This makes the conditions that we're asserting clearer. In particular, it's more visible that we only attempt pushdowns on VectorSelector
, which handles your concern here.
@@ -2506,6 +2506,10 @@ func TestPromQLQueryEndpoint(t *testing.T) { | |||
name: "two pushdowns, same metric different matchers", | |||
query: `sum(rate(metric_2{foo = "bar"}[5m]))/sum(rate(metric_2[5m]))`, | |||
}, | |||
{ | |||
name: "pushdown with offset", |
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.
A bit confused with test naming. Since we don't support pushing down queries with offsets, maybe name it: no pushdown when using offset
? Given name gives me an impression that pushdown works with offset
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.
As these tests are primarily used to compare the result that Promscale delivers compared to Prometheus, IMO the description of the test should be independent of what Promscale does or doesn't do. I've updated the test name to delta function over range selector with offset
.
f6ad797
to
2c28d79
Compare
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.
Couple of nits and a question: do we want to add a TODO to add in the offset support if its something that might be added in the future?
Other than that, I have no problems with the PR itself. Great work 👍
pkg/pgmodel/querier/query_builder.go
Outdated
|
||
// We can't push down without hints | ||
if queryHints == nil || selectHints == nil { | ||
return false | ||
} | ||
|
||
// We can't do pushdowns without the extension | ||
if !extension.ExtensionIsInstalled { | ||
return false | ||
} | ||
|
||
// We can't handle subqueries in pushdowns | ||
if hasSubquery(path) { | ||
return false | ||
} |
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.
The correct Go style for things like this is to use a switch statement, would make the code more compact and easier to read.
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.
TIL, thanks!
pkg/pgmodel/querier/query_builder.go
Outdated
@@ -242,7 +242,29 @@ func canAttemptPushdown(metadata *promqlMetadata) bool { | |||
path := metadata.path // PromQL AST. | |||
queryHints := metadata.queryHints | |||
selectHints := metadata.selectHints | |||
return extension.ExtensionIsInstalled && queryHints != nil && !hasSubquery(path) && selectHints != nil | |||
|
|||
// We can't push down without hints |
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'm sorry, I have to do this. 😁
// We can't push down without hints | |
// We can't push down without hints. |
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.
No problem! Fixed.
I've opened #1130 to track this. |
1aadc44
to
30fd31a
Compare
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 believe we need to handle MatrixSelector
explicitly. Check my related comment.
We don't correctly handle pushdowns with offsets, so we just skip them instead of returning erroneous results.
0588a42
to
54235be
Compare
Description
We don't correctly handle pushdowns with offsets, so we just skip them
instead of returning erroneous results.
Merge requirements
Please take into account the following non-code changes that you may need to make with your PR:
Updated the relevant documentation