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

SQL: Improve the optimization of null conditionals #71192

Merged
merged 2 commits into from
Apr 3, 2021

Conversation

costin
Copy link
Member

@costin costin commented Apr 1, 2021

Enhance the existing rules so that
Coalesce(ex) -> ex
NullIf(a, a) -> null
NullIf(null, a) -> null
NullIf(a, null) -> a

Enhance the existing rules so that
Coalesce(ex) -> ex
NullIf(a, a) -> null
NullIf(null, a) -> null
NullIf(a, null) -> a
@costin costin requested review from astefan, bpintea and matriv April 1, 2021 16:30
@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label Apr 1, 2021
@elasticmachine
Copy link
Collaborator

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

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. Nice! left a question.


@Override
public boolean foldable() {
return left.semanticEquals(right) || super.foldable();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't also be foldable if left.foldable() and left.fold() == null, but then we need to call left.fold() so I'm not sure we should do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

but then we need to call left.fold() so I'm not sure we should do that.

@matriv fmi, why would that be problematic?, if .foldable()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Conceptually you call foldable() beforehand, to check if it's safe to fold() something, so it's weird to call fold() on a child inside the check of foldable().

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

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

LGTM

Expression firstChild = children.get(0);
boolean sameChild = true;
for (int i = 1; i < children.size(); i++) {
Expression child = children.get(i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: there's an extra space after equals sign, but the assignment could also be done away with, child's only used once in following expression.


@Override
public boolean foldable() {
return left.semanticEquals(right) || super.foldable();
Copy link
Contributor

Choose a reason for hiding this comment

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

but then we need to call left.fold() so I'm not sure we should do that.

@matriv fmi, why would that be problematic?, if .foldable()?

@costin costin merged commit fcea303 into elastic:master Apr 3, 2021
costin added a commit to costin/elasticsearch that referenced this pull request Apr 3, 2021
Enhance the existing rules so that
Coalesce(ex) -> ex
NullIf(a, a) -> null
NullIf(null, a) -> null
NullIf(a, null) -> a
costin added a commit to costin/elasticsearch that referenced this pull request Apr 3, 2021
Enhance the existing rules so that
Coalesce(ex) -> ex
NullIf(a, a) -> null
NullIf(null, a) -> null
NullIf(a, null) -> a
costin added a commit that referenced this pull request Apr 3, 2021
…1270)

Enhance the existing rules so that
Coalesce(ex) -> ex
NullIf(a, a) -> null
NullIf(null, a) -> null
NullIf(a, null) -> a
costin added a commit that referenced this pull request Apr 3, 2021
…71271)

Enhance the existing rules so that
Coalesce(ex) -> ex
NullIf(a, a) -> null
NullIf(null, a) -> null
NullIf(a, null) -> a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying >enhancement Team:QL (Deprecated) Meta label for query languages team v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants