Skip to content

engine: fix limitratio to limit the map access and update sort logic #583

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Saumya40-codes
Copy link
Contributor

limit the number of map access calls in limit_ratio, as it won't be needed to check whether to add samples or not.

For instant queries:
limitk, limit_ratio doesn't require to sort values at the end.

Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
@Saumya40-codes Saumya40-codes marked this pull request as ready for review June 5, 2025 04:12
Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
engine/sort.go Outdated
@@ -155,6 +156,10 @@ func (s aggregateResultSort) comparer(samples *promql.Vector) func(i, j int) boo
if lblsCmp != 0 {
return lblsCmp < 0
}

if s.sortOrder == noValueSort {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used? It looks very weird. Maybe we can just avoid calling this function (& sorting) overall?

Copy link
Contributor Author

@Saumya40-codes Saumya40-codes Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/thanos-io/promql-engine/blob/main/engine/sort.go#L100C1-L104C5 for limit k/_ratio, we set sortOrder to noValueSort.

Of what I saw, we would need sort if some grouping is used, though sorting sample values would be just extra step as its not needed in two of these aggregations.

Maybe we can just avoid calling this function (& sorting) overall?

Right, but is it ok if order in which samples are, differs? this is just for when some groupings are used for instant queries

Signed-off-by: Saumya Shah <saumyabshah90@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants