-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QL: Optimize Like/Rlike all (#62682)
Replace common Like and RLike queries that match all characters with IsNotNull (exists) queries Fix #62585 (cherry picked from commit 4c23fad)
- Loading branch information
Showing
14 changed files
with
219 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...k/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/planner/QueryTranslationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql.planner; | ||
|
||
import org.elasticsearch.xpack.eql.plan.physical.PhysicalPlan; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class QueryTranslationTests extends AbstractQueryFolderTestCase { | ||
|
||
public void testLikeOptimization() throws Exception { | ||
PhysicalPlan plan = plan("process where process_name == \"*\" "); | ||
assertThat(asQuery(plan), containsString("\"exists\":{\"field\":\"process_name\"")); | ||
} | ||
|
||
public void testMatchOptimization() throws Exception { | ||
PhysicalPlan plan = plan("process where match(process_name, \".*\") "); | ||
assertThat(asQuery(plan), containsString("\"exists\":{\"field\":\"process_name\"")); | ||
} | ||
|
||
private static String asQuery(PhysicalPlan plan) { | ||
return plan.toString().replaceAll("\\s+", ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...c/test/java/org/elasticsearch/xpack/ql/expression/predicate/regex/StringPatternTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.ql.expression.predicate.regex; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
public class StringPatternTests extends ESTestCase { | ||
|
||
private boolean isTotalWildcard(String pattern, char escape) { | ||
return new LikePattern(pattern, escape).matchesAll(); | ||
} | ||
|
||
private boolean isTotalRegex(String pattern) { | ||
return new RLikePattern(pattern).matchesAll(); | ||
} | ||
|
||
public void testWildcardMatchAll() throws Exception { | ||
assertTrue(isTotalWildcard("%", '0')); | ||
assertTrue(isTotalWildcard("%%", '0')); | ||
|
||
assertFalse(isTotalWildcard("a%", '0')); | ||
assertFalse(isTotalWildcard("%_", '0')); | ||
assertFalse(isTotalWildcard("%_%_%", '0')); | ||
assertFalse(isTotalWildcard("_%", '0')); | ||
assertFalse(isTotalWildcard("0%", '0')); | ||
} | ||
|
||
public void testRegexMatchAll() throws Exception { | ||
assertTrue(isTotalRegex(".*")); | ||
assertTrue(isTotalRegex(".*.*")); | ||
assertTrue(isTotalRegex(".*.?")); | ||
assertTrue(isTotalRegex(".?.*")); | ||
assertTrue(isTotalRegex(".*.?.*")); | ||
|
||
assertFalse(isTotalRegex("..*")); | ||
assertFalse(isTotalRegex("ab.")); | ||
assertFalse(isTotalRegex("..?")); | ||
} | ||
} |
Oops, something went wrong.