englefly opened a new pull request, #71052: URL: https://github.com/apache/doris/pull/71052
### Background Nereids can rewrite an `IN` predicate with nonconstant options into a disjunction of equality comparisons. Backend `IN` evaluation evaluates all nonconstant arguments, while subsequent simplification of the disjunction can remove branches. Functions marked non-movable or volatile need their evaluation preserved. ### What problem does this PR solve? Issue Number: None Related PR: #46794 (introduced nonconstant IN extraction), #55417 (added the volatile comparison guard) PR Type: Bugfix Problem Summary: Nonconstant `IN` extraction can remove mandatory checks when another option already matches, or duplicate a protected comparison expression. Skip extraction when either side contains a non-movable or volatile expression, using the existing recursive trait check. Most of the diff adds full-normalization unit tests and SQL error regressions. For example, the full-normalization unit test checks this expression: ```sql TRUE IN (TRUE, TRUE, assert_true(IA > 0, 'invalid value')) ``` | Normalization | Expression | |---|---| | Before the fix | `TRUE` | | With the fix | `TRUE IN (TRUE, assert_true((IA > 0), 'invalid value'))` | ### Details - **Frequency:** Always for the reproduced full-normalization cases with a matching constant and an assertion, checked bitmap conversion, or volatile option. - **Root cause:** `InPredicateExtractNonConstant` only guards volatile comparison expressions. Its generated `OR` branches can be folded away, and non-movable comparison expressions can be duplicated. The gap has existed since the original extraction rule; this fix does not change deduplication. - **Why existing tests missed it:** `ExpressionRewriteTest.testInPredicateExtractNonConstant` exercises four ordinary column/arithmetic cases using only extraction. The SQL regression `test_simplify_in_predicate` covers date/timestamp coercion, and `query_p0/in_predicate/inPredicate` disables constant folding. Neither checks mandatory evaluation through full normalization. - **Fix:** Apply `containsVolatileOrNoneMovableExpression()` to the entire predicate, including nested option expressions. This protects `assert_true`, `to_bitmap_with_check`, volatile builtins, and UDFs declared VOLATILE without maintaining a function-name list. Ordinary extraction and the 200-option limit remain intact. - **Other paths and branches:** `NOT IN` uses the same `IN` child and the shared normalizer covers the plan entry points. Remote `branch-3.1`, `branch-4.0`, `branch-4.1`, and `branch-4.2` still have the guard gap; this PR targets master. Older branches may need adaptation to their unique/volatile expression APIs when backporting. - **Behavior change:** Mandatory checks remain executable instead of disappearing, and marked functions retain eager IN evaluation. Untagged functions such as `sleep`, and ordinary cast/division errors, are outside this change's protection contract. ### Testing - Baseline on master: the new six-method `InPredicateExtractNonConstantTest` produced four assertion failures, zero errors, and zero skips. The failures showed removed `assert_true`, nested checked bitmap conversion and volatile options, plus duplicated comparison assertions. - Candidate: `bash run-fe-ut.sh --run org.apache.doris.nereids.rules.expression.InPredicateExtractNonConstantTest,org.apache.doris.nereids.rules.expression.ExpressionRewriteTest,org.apache.doris.nereids.rules.expression.SimplifyInPredicateTest` ran 24 tests locally, all passed with zero errors/skips. The new six-method suite passed. - `mvn checkstyle:check -pl fe-core`: zero violations locally. `git diff --check`: passed. - Added `test_in_predicate_mandatory_evaluation` with four SQL error cases for `assert_true` and checked bitmap conversion under `IN` and `NOT IN`. Not run locally because this worktree has no FE/BE runtime cluster; selected by the default P0 configuration. ### Release note Preserve assertion and checked bitmap conversion errors when optimizing IN and NOT IN predicates containing nonconstant expressions. ### Check List (For Author) - Behavior changed: Yes (see Details) - Does this need documentation: No - Pre-submission status: Partially verified: SQL regressions not run locally; no FE/BE runtime cluster ### AI Disclosure - Tool: OpenAI Codex (GPT-6) - Generated: Planner guard, unit tests, SQL regressions, and this description - Human review: Not stated -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
