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

ESQL: avoid computing duplicate aggs #100544

Closed
costin opened this issue Oct 9, 2023 · 2 comments · Fixed by #100642
Closed

ESQL: avoid computing duplicate aggs #100544

costin opened this issue Oct 9, 2023 · 2 comments · Fixed by #100642
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:QL (Deprecated) Meta label for query languages team

Comments

@costin
Copy link
Member

costin commented Oct 9, 2023

Description

In cases where the same agg is used, instead of computing it multiple times, make another reference to it:

stats a = min(x), b = min(x) by z

should become

stats a = min(x) by z
eval b = a
keep a,b,z
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@elasticsearchmachine elasticsearchmachine added the Team:QL (Deprecated) Meta label for query languages team label Oct 9, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/elasticsearch-esql (:Query Languages/ES|QL)

costin added a commit to costin/elasticsearch that referenced this issue Oct 10, 2023
Replace duplicated aggregations in a stat with an alias (through a
 synthetic eval).
Additionally introduce agg normalization which replaces field aliases
 inside agg and the literals in Count with "*".

This improves the query:

eval x = salary
stats c = count(), m = min(x), m1 = min(salary), c1 = count(1)

to
stats c = count(*), m = min(x)
eval m1 = m, c1 = c
keep c, m, m1, c1

Fix elastic#100544
costin added a commit to costin/elasticsearch that referenced this issue Oct 10, 2023
Replace duplicated aggregations in a stat with an alias (through a
 synthetic eval).
Additionally introduce agg normalization which replaces field aliases
 inside agg and the literals in Count with "*".

This improves the query:

eval x = salary
stats c = count(), m = min(x), m1 = min(salary), c1 = count(1)

to
stats c = count(*), m = min(x)
eval m1 = m, c1 = c
keep c, m, m1, c1

Fix elastic#100544
elasticsearchmachine pushed a commit that referenced this issue Oct 18, 2023
Replace duplicated aggregations in a stat with an alias (through a 
synthetic eval). Additionally introduce agg normalization which replaces
field aliases  inside agg and the literals in Count with "*".

This improves the query:

eval x = salary stats c = count(), m = min(x), m1 = min(salary), c1 =
count(1)

to stats c = count(*), m = min(x) eval m1 = m, c1 = c keep c, m, m1, c1

Fix #100544
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:QL (Deprecated) Meta label for query languages team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants