Skip to content

QL: Optimize Like/Rlike all #62682

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

Merged
merged 5 commits into from
Sep 24, 2020
Merged

QL: Optimize Like/Rlike all #62682

merged 5 commits into from
Sep 24, 2020

Conversation

costin
Copy link
Member

@costin costin commented Sep 21, 2020

Replace common Like and RLike queries that match all characters with
IsNotNull (exists) queries

Fix #62585

Replace common Like and RLike queries that match all characters with
IsNotNull (exists) queries

Fix elastic#62585
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (:Query Languages/EQL)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (:Query Languages/SQL)

@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label Sep 21, 2020
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.

Left a comment about the Like/LikePattern.

@costin
Copy link
Member Author

costin commented Sep 21, 2020

I've added more tests to check the query translation and it turns out IsNull/IsNotNull always defaulted to scripts. So I've fixed the translation rules and added moved the wildcard pattern rule in the optimizer so that according to the comments in #62651:

  1. it only gets applied once
  2. it ignores folding and works only on literal strings

It's worth revisiting some of the translations since this might not be singular case.

@Override
public boolean matchesAll() {
for (int i = 0 ; i < pattern.length(); i++) {
if (pattern.charAt(i) != '%') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that now the "problem" is reversed since the ReplaceWildcards takes place before this rule, but the test seems to work: https://github.com/elastic/elasticsearch/pull/62682/files#diff-6dd3fd1d0809ee5978cdccbc6bb7d7e1R17 ? In any case I think we should have a comment mentioning the order of the rules are applied and the choice of % or * in this rule.

Copy link
Member Author

Choose a reason for hiding this comment

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

LikePattern has several styles. In its constructor it accepts the % and _ characters instead of * and ?. The conversion is done internally and accessible.
The check above works on the raw pattern - I'll follow-up with a comment.

@matriv
Copy link
Contributor

matriv commented Sep 22, 2020

Relates to #62760

@costin
Copy link
Member Author

costin commented Sep 23, 2020

@elasticmachine update branch

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

@costin costin merged commit 4c23fad into elastic:master Sep 24, 2020
@costin costin deleted the fix/62585 branch September 24, 2020 10:32
@costin costin added the v8.0.0 label Sep 24, 2020
costin added a commit that referenced this pull request Sep 24, 2020
Replace common Like and RLike queries that match all characters with
IsNotNull (exists) queries

Fix #62585

(cherry picked from commit 4c23fad)
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 approach with the new checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EQL: Optimization for string with single wildcard
5 participants