Skip to content

SQL: Simplify expression optimization #35270

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

Closed
costin opened this issue Nov 5, 2018 · 3 comments
Closed

SQL: Simplify expression optimization #35270

costin opened this issue Nov 5, 2018 · 3 comments
Assignees
Labels

Comments

@costin
Copy link
Member

costin commented Nov 5, 2018

A common case in the optimizer is improving predicate expressions which tend to be Functions. However when this is referred through its id and that id changes, the plan becomes inconsistent.
For example SELECT COALESCE(null, 1) AS c FROM ... HAVING c > 100

The optimizer will optimize the Coalesce definition but HAVING c > 100 will still use the old script definition (now residing in the scalar reference).
This is a recurrent issue that affect all rules and proved to create bugs in the past due to old references lying around. In the above case it's even more problematic since the old id is not used (and thus the query does not blow up) but the old script is.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@costin
Copy link
Member Author

costin commented Nov 5, 2018

relates #29853

@jasontedor jasontedor added v6.7.0 and removed v6.6.0 labels Dec 19, 2018
@jasontedor jasontedor added v8.0.0 and removed v7.0.0 labels Feb 6, 2019
@jakelandis jakelandis added v7.3.0 and removed v7.2.0 labels Jun 17, 2019
@matriv matriv self-assigned this Mar 2, 2020
matriv added a commit to matriv/elasticsearch that referenced this issue Mar 3, 2020
Add a unit test to verify that the optimization of expression
(e.g. COALESCE) is applied to all instances of the expression:
SELECT, WHERE, GROUP BY.

Relates to elastic#35270
@matriv
Copy link
Contributor

matriv commented Mar 3, 2020

The issue has been resolved with the refactoring of the NamedExpression: #49570.

@matriv matriv closed this as completed Mar 3, 2020
matriv added a commit that referenced this issue Mar 4, 2020
Add a unit test to verify that the optimization of expression
(e.g. COALESCE) is applied to all instances of the expression:
SELECT, WHERE, GROUP BY and HAVING.

Relates to #35270
matriv added a commit that referenced this issue Mar 4, 2020
Add a unit test to verify that the optimization of expression
(e.g. COALESCE) is applied to all instances of the expression:
SELECT, WHERE, GROUP BY and HAVING.

Relates to #35270

(cherry picked from commit 2ceedc7)
matriv added a commit that referenced this issue Mar 4, 2020
Add a unit test to verify that the optimization of expression
(e.g. COALESCE) is applied to all instances of the expression:
SELECT, WHERE, GROUP BY and HAVING.

Relates to #35270

(cherry picked from commit 2ceedc7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants