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

   ### What problem does this PR solve?
   
   Issue Number: close #69262
   
   Related PR: None
   
   Problem Summary:
   
   A scan over a temporary partition uses the row count of normal partitions. 
Even after both counts have been reported, a temporary partition with 5 rows is 
estimated as 3 rows when the normal partition contains 3 rows.
   
   The selected-partition path only runs when fewer partitions are selected 
than the number of normal partitions. The partition-index row-count lookup also 
searches only normal partitions.
   
   Use the existing partition lookup that includes temporary partitions, and 
sum the selected temporary indexes' row counts independently of the normal 
partition count. For incomplete reports, retain the available count with a 
minimum estimate of one row. Keep temporary column statistics unknown instead 
of using normal-partition statistics or injected table counts. Preserve 
virtual-column statistics derivation.
   
   Reproduction:
   
   ```sql
   CREATE TABLE t (k1 INT NOT NULL, k2 INT) DUPLICATE KEY(k1)
   PARTITION BY RANGE(k1) (PARTITION p1 VALUES LESS THAN (10))
   DISTRIBUTED BY HASH(k1) BUCKETS 1
   PROPERTIES ("replication_num" = "1");
   ALTER TABLE t ADD TEMPORARY PARTITION tp1 VALUES LESS THAN (10);
   INSERT INTO t VALUES (1, 1), (2, 2), (3, 3);
   INSERT INTO t TEMPORARY PARTITION (tp1)
   VALUES (4, 4), (5, 5), (6, 6), (7, 7), (8, 8);
   SHOW PARTITIONS FROM t;
   SHOW TEMPORARY PARTITIONS FROM t;
   ```
   
   Wait until SHOW reports 3 rows for p1 and 5 rows for tp1, then run:
   
   ```sql
   EXPLAIN SELECT * FROM t TEMPORARY PARTITION (tp1);
   SELECT COUNT(*) FROM t TEMPORARY PARTITION (tp1);
   ```
   
   Before: cardinality=3, COUNT(*)=5.
   After: cardinality=5, COUNT(*)=5.
   
   ### Release note
   
   Correct optimizer cardinality estimates for temporary partition scans.
   
   ### Check List (For Author)
   
   - Test
       - [x] Regression test
       - [x] Unit Test
       - [x] Manual test (reproduction above)
       - [ ] No need to test or manual test.
   
   Validation before rebase:
   
   - `run-fe-ut.sh`: StatsCalculatorTest and OlapTableTest, 52 passed.
   - `run-regression-test.sh`: statistics suite 
`test_temporary_partition_row_count`, generation and verification runs both 
passed. The expected output was generated by the script.
   - Regression coverage: normal scan estimates 3 rows; temporary scans 
estimate 5, 2, and 7 rows for the selected partitions.
   - `build.sh --fe`: passed, including Checkstyle.
   - ASAN BE and BE Java extensions built successfully for the test cluster.
   
   Validation after rebase onto upstream/master (378404eeb1):
   
   - StatsCalculatorTest and OlapTableTest: 52 passed, no failures or errors.
   - FE core Checkstyle: 0 violations.
   - The six changed files are identical to the pre-rebase patch.
   - Full distribution builds and cluster regression were not repeated after 
rebase. Their earlier results are from the pre-rebase revision.
   
   - Behavior changed:
       - [ ] No.
       - [x] Yes. Temporary scan estimates use their selected partitions; query 
plans may change. Unreported counts remain estimates.
   
   - Does this need documentation?
       - [x] No. This restores existing behavior; no syntax or option changes.
       - [ ] Yes.
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label
   
   ### What problem does this PR solve?
   
   Issue Number: close #xxx
   
   Related PR: #xxx
   
   Problem Summary:
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


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