Skip to content

Commit 9e661c8

Browse files
airborne12claude
andcommitted
[fix](nereids) Do not infer multi_match predicates across column equalities
### What problem does this PR solve? Issue Number: N/A Related PR: apache#69419 Problem Summary: multi_match runs its query through the inverted index of its column, like MATCH, so its result depends on that index and not only on the value of the column. Predicate inference still copied it to an equal column: SELECT id FROM infer_match_predicate_parser WHERE c1 = c2 AND (multi_match(c1, 'any', 'apple') OR multi_match(c1, 'any', 'pear')); added the same OR over c2. c2 has an index without a parser, so the copy dropped row 1 ('apple red'). InferPredicateByReplace now also skips the inputs that contain MultiMatch. ### Release note Fix incorrect rows when equality inference copies a multi_match predicate to an equal column. ### Check List (For Author) - Test: - InferPredicateByReplaceTest adds multi_match to the shapes of the MATCH and SEARCH cases. InferPredicateByReplaceTest, InferPredicatesTest and UnequalPredicateInferTest pass (139 tests). Checkstyle passes. - Regression test: infer_match_predicate adds the query above, which returns row 1; its .out was generated by the framework. - Behavior changed: Yes. Predicate inference no longer copies a predicate that contains multi_match to an equal column. - Does this need documentation: No. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4c70c72 commit 9e661c8

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/InferPredicateByReplace.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.doris.nereids.trees.expressions.Slot;
3636
import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
3737
import org.apache.doris.nereids.trees.expressions.functions.NoneMovableFunction;
38+
import org.apache.doris.nereids.trees.expressions.functions.scalar.MultiMatch;
3839
import org.apache.doris.nereids.trees.expressions.functions.scalar.Search;
3940
import org.apache.doris.nereids.trees.expressions.literal.Literal;
4041
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
@@ -240,8 +241,8 @@ public static Set<Expression> infer(Set<Expression> inputs) {
240241
Map<Expression, Set<Expression>> exprPredicates = new HashMap<>();
241242
for (Expression input : inputs) {
242243
// Inference can evaluate a predicate on rows that never reach its original filter.
243-
// MATCH and SEARCH depend on column indexes, and copies can change score().
244-
if (input.containsType(Match.class, Search.class, SearchExpression.class)
244+
// MATCH, multi_match and SEARCH depend on column indexes, and copies can change score().
245+
if (input.containsType(Match.class, MultiMatch.class, Search.class, SearchExpression.class)
245246
|| input.anyMatch(expr -> expr instanceof NoneMovableFunction
246247
|| !((ExpressionTrait) expr).isDeterministic())
247248
|| input.getInputSlots().size() != 1) {

‎fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/InferPredicateByReplaceTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.doris.nereids.trees.expressions.functions.scalar.AssertTrue;
3636
import org.apache.doris.nereids.trees.expressions.functions.scalar.DateTrunc;
3737
import org.apache.doris.nereids.trees.expressions.functions.scalar.Length;
38+
import org.apache.doris.nereids.trees.expressions.functions.scalar.MultiMatch;
3839
import org.apache.doris.nereids.trees.expressions.functions.scalar.Search;
3940
import org.apache.doris.nereids.trees.expressions.functions.scalar.SignBit;
4041
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
@@ -112,6 +113,7 @@ private static Stream<Arguments> matchAndSearchPredicates() {
112113
return Stream.of(
113114
new MatchAny(a, new StringLiteral("apple")),
114115
new MatchPhrase(a, new StringLiteral("apple red")),
116+
new MultiMatch(a, new StringLiteral("any"), new StringLiteral("apple")),
115117
new Search(new StringLiteral("a:apple")),
116118
new SearchExpression("a:apple", SearchDslParser.parseDsl("a:apple"), ImmutableList.of(a)))
117119
.flatMap(search -> {

‎regression-test/data/nereids_rules_p0/infer_predicate/infer_match_predicate.out‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
-- !search --
99
1
1010

11+
-- !multi_match --
12+
1
13+
1114
-- !score --
1215
1 0.4700036
1316
2 0.4700036

‎regression-test/suites/nereids_rules_p0/infer_predicate/infer_match_predicate.groovy‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ suite("infer_match_predicate") {
4343
SELECT id FROM infer_match_predicate_parser
4444
WHERE c1 = c2 AND (search('c1:apple') OR c1 = 'pear')
4545
"""
46+
order_qt_multi_match """
47+
SELECT id FROM infer_match_predicate_parser
48+
WHERE c1 = c2 AND (multi_match(c1, 'any', 'apple') OR multi_match(c1, 'any', 'pear'))
49+
"""
4650

4751
sql "DROP TABLE IF EXISTS infer_match_predicate_score"
4852
sql """

0 commit comments

Comments
 (0)