Skip to content

Commit

Permalink
fix bug: or-to-in and simplify-range conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Oct 11, 2024
1 parent bc9b87d commit 7839b32
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class ExpressionOptimization extends ExpressionRewrite {
SimplifyDecimalV3Comparison.INSTANCE,
SimplifyRange.INSTANCE,
OrToIn.INSTANCE,
SimplifyRange.INSTANCE,
DateFunctionRewrite.INSTANCE,
ArrayContainToArrayOverlap.INSTANCE,
CaseWhenToIf.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ public Expression toExpression() {
for (int i = 1; i < sourceValues.size(); i++) {
result = mergeExprOp.apply(result, sourceValues.get(i).toExpression());
}
if (result.equals(expr)) {
return expr;
}
return result;
}
}
Expand Down
62 changes: 62 additions & 0 deletions regression-test/suites/nereids_rules_p0/or_to_in/ortoin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.


suite("ortoin") {
sql """
drop table if exists table_10_undef_partitions2_keys3_properties4_distributed_by53;
CREATE TABLE `table_10_undef_partitions2_keys3_properties4_distributed_by53` (
`pk` int NULL,
`col_varchar_10__undef_signed` varchar(10) NULL,
`col_bigint_undef_signed` bigint NULL,
`col_varchar_64__undef_signed` varchar(64) NULL
) ENGINE=OLAP
DUPLICATE KEY(`pk`, `col_varchar_10__undef_signed`)
DISTRIBUTED BY HASH(`pk`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1");
"""

// OrToIn Rule set state flag in Or expression. SimplifyRange Rule may remove this flag, and hence
// OrToIn and SimplifyRange Rules go into dead loop.
// to fix this bug, if the input expression and output expression of SimplifyRange Rule are the same,
// SimplifyRange will return input expression to keep expression state.
//
sql """
explain
SELECT
*
FROM
table_10_undef_partitions2_keys3_properties4_distributed_by53
WHERE
(
`pk` IN (2, -114)
AND `pk` IS NOT NULL
)
OR
(
col_varchar_64__undef_signed IS NULL
AND `pk` IN (7, 1)
AND `pk` IS NOT NULL
)
OR
(
(`pk` <> -89)
)
;
"""
}

0 comments on commit 7839b32

Please sign in to comment.