englefly opened a new pull request, #70917:
URL: https://github.com/apache/doris/pull/70917

   ### Background
   
   Nereids normalizes an `IN` predicate before cardinality estimation. The 
normalizer removes duplicate options, and a separate rule converts a single 
remaining option to an equality predicate.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #46794 (introduced the rewrite size limit)
   PR Type: Bugfix
   
   Problem Summary:
   
   An `IN` predicate with 201 copies of the same literal reaches cardinality 
estimation with all 201 options. Estimation can count repeated values 
separately. Deduplicating the leading literals lets that example normalize to a 
single equality while limiting the work on lists whose first 200 options have 
little repetition.
   
   ### Details
   
   - **Frequency:** Always when normalizing the 201-option repeated-literal 
example.
   - **Root cause:** `InPredicateDedup` skipped every list over 200 options. 
`FilterEstimation` counts each surviving in-range literal, including duplicate 
copies.
   - **Why existing tests missed it:** 
`ExpressionRewriteTest.testInPredicateDedup` uses four options. The 
`test_simplify_in_predicate` SQL regression covers type coercion on short date 
and timestamp lists. Both stay within the rewrite limit.
   - **Fix:** Sample and deduplicate leading literals in one pass. If a 101st 
distinct value occurs within the first 200 options, keep the original 
predicate. Otherwise, continue to the first nonliteral or the end of the list. 
Retain one copy of each literal in first-seen order, including NULL, and append 
the untouched suffix from the first nonliteral.
   - **Other paths and branches:** The Nereids normalization rule is shared by 
its plan entry points. Range inference and nonconstant extraction keep their 
own 200-option checks through the shared constant. The original deduplication 
limit is present on `branch-3.1`, `branch-4.0`, `branch-4.1`, and `branch-4.2`. 
This PR targets `master`.
   - **Behavior change:** Large lists with a repetitive leading section can 
produce a smaller predicate and different cardinality estimates. The first 200 
options can reject the rewrite early. Once the sample qualifies, the scan can 
reach the end of the literal prefix.
   
   ### Testing
   
   - On `master` before the fix, the new rewrite test reproduced three 
failures. A list with 201 copies kept all of them, duplicate literals before a 
function survived, and a large `NOT IN` retained repeated NULLs.
   - On the candidate, the local FE unit-test runner passed all 94 tests in 
`InPredicateDedupTest`, `ExpressionRewriteTest`, `SimplifyInPredicateTest`, and 
`FilterEstimationTest`. The large-list fixture has 9,999 options under the 
default expression width limit.
   - FE Checkstyle reported zero violations.
   
   ### Release note
   
   Nereids now deduplicates repetitive literal prefixes in large `IN` lists, 
which can improve row estimates for generated queries with many repeated values.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: OpenAI Codex (GPT-6)
   - Generated: Planner change, unit tests, and PR description
   - Human review: Not reported
   


-- 
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]

Reply via email to