Skip to content

[fix](fe) Cost pruned Iceberg scans and exchanges by partition rows - #70016

Open
hubgeter wants to merge 3 commits into
apache:masterfrom
hubgeter:fix/iceberg-selected-partition-rowcount
Open

hubgeter wants to merge 3 commits into
apache:masterfrom
hubgeter:fix/iceberg-selected-partition-rowcount

Conversation

@hubgeter

@hubgeter hubgeter commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Related PR: #69678

Problem Summary:

An internally partition-pruned Iceberg FileScan can still charge scan CPU and exchange costs using whole-table row estimates. For example, an MV compensation scan selecting one of three one-row partitions is charged for three rows even after pruning selects the right partition.

Carry snapshot-consistent partition row estimates through the connector MVCC partition view and converted-view cache. Use the selected partitions when calculating physical FileScan CPU cost, while keeping the existing table-level cardinality and column statistics together for retained Filter and Join estimation. This avoids applying partition selectivity twice and preserves column-statistics lineage.

Also cap exchange input rows with a bound proven from the child's logical memo expression. Propagate that bound only through Filter, Project, Limit, Sort and TopN, and preserve a smaller existing estimate. Hash, replicated, gather and random exchanges use the same bound. Joins, aggregates, generators, set operations and groups without logical expressions keep their previous estimates. Costing does not depend on the cheapest physical child or add mutable state to Cost.

Both lookups read already-materialized partition metadata from the statement snapshot without loading deferred metadata. Unknown counts, delete files, unavailable views and unsupported selections keep the existing estimate. The new exchange cap excludes explicit time-travel and scan selectors, which may address moving references; the existing FileScan CPU path retains its version-aware pin lookup. Ordinary Iceberg scans carry the statement snapshot ID to scan planning, so later appends do not widen that read.

The connector carrier gains an optional row estimate. After merging current master, the combined connector plugin API advances from 30.0 to 31.0 with its recorded surface updated; connector plugins must be rebuilt against the matching API. Metadata-listing close failures propagate instead of caching an incomplete partition view.

Validation of production sources committed as 7ba281cca59863ee36e79d8898f127d1b2a52196:

  • Checkstyle passed for the connector SPI, Iceberg connector and FE-core sources included in this PR.

  • Standard run-fe-ut.sh validation retained production and test compilation, used one test fork, and excluded unrelated BE Java plugin modules from the explicit module list. The broad run passed 762 SPI, Iceberg and existing FE tests; its only errors were in a supplemental local fixture. After correcting that fixture, the final focused run finished with BUILD SUCCESS and all 36 tests passing: 11 local exchange-bound cases, 21 existing FileScan statistics/cost cases and 4 cost-model cases.

  • Across those runs, 773 distinct tests in 49 classes have passing latest results: 155 SPI, 375 Iceberg and 243 FE-core tests. Production-source hashes were unchanged between runs. The supplemental exchange-bound and scan-append fixtures remain local; the compact SQL-only regression described below is included in this PR.

  • Coverage includes partition skew/evolution/delete files, old snapshots and cache generations, reference-specific pins, deferred metadata non-loading, all four exchange kinds, residual nonpartition predicates, Filter/Project/Limit/Sort/TopN propagation, smaller estimates, empty selections, the global-aggregate-on-empty exception, unsupported operators and logical proof independence from physical alternatives. An Iceberg SDK scan-planning test confirms that a pinned scan excludes a later appended file while an unpinned comparison scan sees both files.

  • Full FE package assembly, external-cluster regression, customer SQL A/B and remote CI have not been established by these local checks. The final MV winner remains cost based.

  • Added test_iceberg_mtmv_partition_scan_cost and its generated output at 7558f82402291aa75234015ba11ab49484912ca9: a 72-line SQL-only regression with five input rows, two materialized days and a new uncompensated day. It checks pruned ranges, residual and nonpartition NULL predicates, and an empty aggregate with rewriting disabled/enabled. It uses one awaited MV refresh and asserts neither exact cost values nor the winning plan. The current branch's regression runner passed five consecutive executions against patched open-source Doris 4.0.6 FE and matching official BE; the first generated 11 independently checked result blocks, and four further runs compared that golden output. This is compatibility validation; the exact master FE/BE combination remains for CI.

Release note

Improve scan and exchange costs for internally partition-pruned Iceberg scans, including materialized view compensation. Connector plugins require API version 31.0. Final plan selection remains cost based.

Check List (For Author)

  • Test

    • 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
  • Behavior changed:

    • No.
    • Yes. Eligible scan and exchange costs use selected-partition rows; Filter and Join cardinality keep the existing statistics contract.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hubgeter

hubgeter commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hubgeter

hubgeter commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/review

hubgeter added a commit to hubgeter/doris that referenced this pull request Nov 3, 2026
### What problem does this PR solve?

Related PR: apache#70016

Problem Summary: Use the current statistics model/cache packages and
Mockito's scoped static mock in the new FileScan statistics tests. This
removes dependencies on the legacy statistics package and JMockit while
retaining the selected-row, column-statistics and scan-cost assertions.

### Release note

None

### Check List (For Author)

- Test: FE-core Checkstyle and diff checks passed. The production FE
  sources compiled successfully; the standard FE unit-test script is
  rerunning test compilation and the selected suites with those classes.
- Behavior changed: No
- Does this need documentation: No
hubgeter added a commit to hubgeter/doris that referenced this pull request Nov 3, 2026
### What problem does this PR solve?

Related PR: apache#70016

Problem Summary: Use the current deferred partition marker, the
snapshot-aware internal-pruning overload and statement-scoped cost
weights in the selected-partition FileScan tests. The tests exercise
actual re-pruning, logical/physical statistics and scan cost calculation.

### Release note

None

### Check List (For Author)

- Test: Unit Test; the standard run-fe-ut.sh invocation passed all 450
  selected tests in 45 classes across 74 FE reactor modules, including
  all 13 FileScan statistics tests. Production/test compilation and
  three-module Checkstyle passed. External regression and full FE
  packaging are not run.
- Behavior changed: No
- Does this need documentation: No
@hubgeter

hubgeter commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hubgeter

hubgeter commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Selected model is at capacity. Please try a different model.
Workflow run: https://github.com/apache/doris/actions/runs/41578338213

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28478 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit cb2df35acf0ca5b0f8f18a0a3f2f5b334f57efe7, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17587	5227	5368	5227
q2	2124	301	243	243
q3	10283	1360	812	812
q4	4676	463	339	339
q5	7421	788	531	531
q6	183	181	148	148
q7	731	783	592	592
q8	9256	1298	1058	1058
q9	5475	4171	4166	4166
q10	6827	1293	1035	1035
q11	422	241	228	228
q12	631	399	288	288
q13	18234	3577	3016	3016
q14	292	273	261	261
q15	q16	717	707	673	673
q17	1174	751	577	577
q18	7050	6122	6096	6096
q19	1114	946	601	601
q20	413	340	224	224
q21	4867	2105	2281	2105
q22	349	292	258	258
Total cold run time: 99826 ms
Total hot run time: 28478 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5669	5652	5650	5650
q2	681	564	530	530
q3	5167	5361	4955	4955
q4	1998	2186	1560	1560
q5	5266	5127	5550	5127
q6	248	197	156	156
q7	2360	2113	1836	1836
q8	3029	2672	2736	2672
q9	8005	7937	7926	7926
q10	3713	3930	3278	3278
q11	635	463	428	428
q12	725	697	571	571
q13	3718	3894	3309	3309
q14	310	326	299	299
q15	q16	674	726	674	674
q17	8336	7042	7061	7042
q18	13048	12223	12843	12223
q19	902	782	790	782
q20	2150	2117	1944	1944
q21	5730	4771	4940	4771
q22	487	451	403	403
Total cold run time: 72851 ms
Total hot run time: 66136 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 151253 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit cb2df35acf0ca5b0f8f18a0a3f2f5b334f57efe7, data reload: false

query5	4300	579	454	454
query6	423	226	212	212
query7	4810	461	226	226
query8	319	164	162	162
query9	8790	3194	3201	3194
query10	475	313	254	254
query11	6051	3863	3556	3556
query12	155	99	90	90
query13	1247	463	346	346
query14	6075	3919	3654	3654
query14_1	3460	3457	3448	3448
query15	205	203	183	183
query16	953	455	414	414
query17	874	662	548	548
query18	2428	425	315	315
query19	194	201	129	129
query20	83	83	82	82
query21	205	128	108	108
query22	13010	12972	12797	12797
query23	13441	12661	12373	12373
query23_1	12462	12498	12512	12498
query24	7374	820	477	477
query24_1	475	498	472	472
query25	516	402	334	334
query26	1259	251	136	136
query27	2754	438	276	276
query28	4597	2029	2043	2029
query29	1546	588	433	433
query30	303	224	186	186
query31	1029	923	822	822
query32	147	86	86	86
query33	515	290	231	231
query34	886	849	500	500
query35	737	767	656	656
query36	814	805	715	715
query37	120	97	86	86
query38	1771	1713	1667	1667
query39	790	792	740	740
query39_1	736	728	743	728
query40	213	117	99	99
query41	67	63	64	63
query42	91	86	83	83
query43	358	366	312	312
query44	1340	696	703	696
query45	177	179	161	161
query46	831	963	565	565
query47	2713	2898	2685	2685
query48	301	306	215	215
query49	566	412	276	276
query50	674	273	212	212
query51	10612	10835	10440	10440
query52	89	84	72	72
query53	186	208	150	150
query54	232	206	195	195
query55	71	70	68	68
query56	278	209	202	202
query57	1662	1621	1579	1579
query58	285	256	244	244
query59	2160	2221	1969	1969
query60	297	252	223	223
query61	164	147	150	147
query62	387	351	286	286
query63	190	159	160	159
query64	2684	972	767	767
query65	3345	3284	3289	3284
query66	1779	425	309	309
query67	20065	20188	20167	20167
query68	3035	1017	640	640
query69	391	286	250	250
query70	869	786	774	774
query71	293	235	209	209
query72	2784	2744	2357	2357
query73	512	518	298	298
query74	4687	4519	4366	4366
query75	2337	2298	1909	1909
query76	2310	1030	605	605
query77	354	379	277	277
query78	9639	9762	9160	9160
query79	905	892	530	530
query80	472	419	339	339
query81	519	329	267	267
query82	199	135	109	109
query83	192	200	180	180
query84	284	126	103	103
query85	764	403	362	362
query86	267	239	235	235
query87	1993	1957	1777	1777
query88	3704	2775	2717	2717
query89	313	295	262	262
query90	2102	175	172	172
query91	161	149	129	129
query92	99	87	87	87
query93	1000	1027	584	584
query94	449	311	277	277
query95	582	384	314	314
query96	674	490	246	246
query97	2415	2431	2294	2294
query98	162	150	149	149
query99	774	774	641	641
Total cold run time: 233136 ms
Total hot run time: 151253 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.43 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit cb2df35acf0ca5b0f8f18a0a3f2f5b334f57efe7, data reload: false

query1	0.01	0.01	0.01
query2	0.09	0.04	0.05
query3	0.26	0.09	0.09
query4	1.61	0.09	0.10
query5	0.23	0.24	0.26
query6	1.16	0.68	0.68
query7	0.04	0.00	0.00
query8	0.06	0.04	0.04
query9	0.43	0.35	0.36
query10	0.59	0.59	0.58
query11	0.20	0.16	0.13
query12	0.18	0.15	0.15
query13	0.52	0.50	0.49
query14	1.02	1.02	1.02
query15	0.65	0.65	0.60
query16	0.36	0.36	0.35
query17	1.13	1.12	1.13
query18	0.21	0.18	0.20
query19	2.08	2.00	1.97
query20	0.02	0.01	0.01
query21	15.50	0.19	0.14
query22	4.95	0.05	0.06
query23	16.28	0.34	0.13
query24	2.71	0.54	0.39
query25	0.14	0.07	0.04
query26	1.36	0.21	0.16
query27	0.04	0.04	0.04
query28	3.96	0.81	0.39
query29	12.52	4.16	3.29
query30	0.29	0.14	0.10
query31	2.77	0.57	0.33
query32	3.22	0.59	0.49
query33	3.14	3.21	3.20
query34	15.40	4.04	3.40
query35	3.38	3.35	3.38
query36	0.56	0.44	0.43
query37	0.09	0.07	0.06
query38	0.06	0.04	0.04
query39	0.04	0.04	0.03
query40	0.17	0.15	0.15
query41	0.09	0.04	0.03
query42	0.04	0.02	0.02
query43	0.04	0.04	0.03
Total cold run time: 97.6 s
Total hot run time: 24.43 s

hubgeter added a commit to hubgeter/doris that referenced this pull request Nov 3, 2026
### What problem does this PR solve?

Related PR: apache#70016

Problem Summary: Combining selected-partition row counts with table-level column
statistics applies partition-filter selectivity twice and breaks the original
column-statistics lineage. Preserve the existing logical and physical FileScan
cardinality estimates, and use materialized partition row counts from the matching
statement snapshot only when computing the physical scan CPU cost. This keeps the
reduced scan work estimate without regressing Filter/Join cardinality or broadcast
eligibility.

### Release note

Correct selected-partition scan costs without changing downstream filter and join
cardinality estimates.

### Check List (For Author)

- Test: Unit Test - 539 tests in 48 classes passed via run-fe-ut.sh; FE Checkstyle passed. Local cluster and full FE packaging were not run.
- Behavior changed: Yes - selected-partition row counts affect only physical scan CPU costs; filtering estimates retain existing statistics.
- Does this need documentation: No
@hubgeter

hubgeter commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Local pipeline review — ✅ PASS

schema: doris-repo-review/v1
status: PASS
pr: apache/doris#70016
commit: e5b79542a0de446420a2807d32b95bad059fa297
base: 952ed6904ff40c010e42dcd3398249bae4b5304f
reviewed_at: 2026-11-03T09:20+00:00
reviewer: hubgeter
model: gpt-6.1-sol
effort: max
findings: {blocker: 0, major: 0, minor: 0, nit: 0}
rounds: 1
converged: true

Notes for maintainers

  • fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModel.java:226 — Selected-partition rows affect physical scan CPU cost only; keeping table-level cardinality and column statistics together fixes the previous F-01 and F-02 filter/broadcast regressions.
  • All 14 changed files were reviewed by gpt-6.1-sol / max. Prior implementation validation passed 539 tests in 48 classes and FE Checkstyle; the review itself was read-only and did not rerun tests.
  • Customer SQL/cluster A/B, a guaranteed final MV winner, measured performance improvement and a full FE package build remain unverified. Connector plugins require matching API 29.0.

Reviewed locally with the doris-repo-review pipeline. Repository policy may accept this receipt for the matching commit; it is not a human Apache approval.

@hubgeter

hubgeter commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 92.11% (35/38) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28310 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit e5b79542a0de446420a2807d32b95bad059fa297, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17572	5162	5067	5067
q2	2170	315	261	261
q3	10220	1393	829	829
q4	4675	454	333	333
q5	7449	794	511	511
q6	184	189	154	154
q7	752	786	601	601
q8	9257	1368	1012	1012
q9	5396	4200	4197	4197
q10	6820	1301	1035	1035
q11	422	241	230	230
q12	629	389	276	276
q13	18129	3454	3011	3011
q14	271	270	249	249
q15	q16	724	709	686	686
q17	1179	734	566	566
q18	6988	6176	6108	6108
q19	1113	944	596	596
q20	370	333	232	232
q21	4641	2099	2299	2099
q22	343	293	257	257
Total cold run time: 99304 ms
Total hot run time: 28310 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5583	5564	5573	5564
q2	695	562	551	551
q3	5195	5355	4944	4944
q4	2003	2143	1550	1550
q5	5234	5127	5388	5127
q6	247	208	153	153
q7	2393	2075	1881	1881
q8	3136	2655	2671	2655
q9	8113	7919	7957	7919
q10	3694	3990	3275	3275
q11	649	436	447	436
q12	732	679	528	528
q13	3449	3877	3289	3289
q14	331	341	294	294
q15	q16	700	723	651	651
q17	8084	6992	6854	6854
q18	13012	12220	12885	12220
q19	902	811	787	787
q20	2148	2148	1931	1931
q21	5626	4695	4803	4695
q22	516	461	401	401
Total cold run time: 72442 ms
Total hot run time: 65705 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 151231 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit e5b79542a0de446420a2807d32b95bad059fa297, data reload: false

query5	4316	590	427	427
query6	423	206	188	188
query7	4809	436	228	228
query8	318	163	147	147
query9	8787	3177	3179	3177
query10	496	309	259	259
query11	5959	3865	3568	3568
query12	143	91	88	88
query13	1246	434	319	319
query14	6149	3917	3670	3670
query14_1	3467	3446	3455	3446
query15	209	196	181	181
query16	949	433	431	431
query17	890	654	531	531
query18	2422	421	314	314
query19	203	161	136	136
query20	85	86	85	85
query21	216	133	112	112
query22	12988	13145	12980	12980
query23	13427	12757	12491	12491
query23_1	12501	12464	12469	12464
query24	7373	880	461	461
query24_1	476	485	486	485
query25	504	394	334	334
query26	1272	253	140	140
query27	2772	432	269	269
query28	4640	2030	2025	2025
query29	1524	583	433	433
query30	292	209	182	182
query31	1017	941	826	826
query32	141	91	88	88
query33	584	288	226	226
query34	1219	862	514	514
query35	736	751	622	622
query36	820	813	735	735
query37	119	104	80	80
query38	1770	1729	1666	1666
query39	784	784	744	744
query39_1	722	747	728	728
query40	211	119	96	96
query41	66	63	61	61
query42	88	82	81	81
query43	344	363	312	312
query44	1335	708	711	708
query45	178	183	164	164
query46	825	954	559	559
query47	2867	3036	2772	2772
query48	305	311	223	223
query49	568	394	304	304
query50	661	273	209	209
query51	10472	10415	10238	10238
query52	81	80	70	70
query53	194	203	156	156
query54	232	187	178	178
query55	68	67	65	65
query56	235	216	223	216
query57	1651	1628	1584	1584
query58	288	267	257	257
query59	2151	2187	2003	2003
query60	307	247	224	224
query61	137	133	145	133
query62	389	338	285	285
query63	185	156	162	156
query64	2738	923	728	728
query65	3358	3262	3281	3262
query66	1768	423	294	294
query67	20294	20170	20281	20170
query68	2978	994	616	616
query69	385	299	242	242
query70	840	774	760	760
query71	295	228	207	207
query72	2746	2575	2303	2303
query73	529	522	296	296
query74	4670	4545	4385	4385
query75	2345	2329	1901	1901
query76	2314	1007	609	609
query77	331	354	270	270
query78	9785	9750	9107	9107
query79	887	857	526	526
query80	466	449	359	359
query81	514	325	266	266
query82	206	132	107	107
query83	192	196	203	196
query84	286	131	103	103
query85	764	421	371	371
query86	259	236	232	232
query87	2023	1969	1834	1834
query88	3667	2752	2715	2715
query89	318	284	245	245
query90	2105	166	163	163
query91	171	156	124	124
query92	92	89	91	89
query93	988	990	583	583
query94	443	323	262	262
query95	570	343	355	343
query96	673	490	236	236
query97	2450	2418	2326	2326
query98	158	152	149	149
query99	763	767	648	648
Total cold run time: 233930 ms
Total hot run time: 151231 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.24 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit e5b79542a0de446420a2807d32b95bad059fa297, data reload: false

query1	0.01	0.01	0.00
query2	0.09	0.05	0.06
query3	0.26	0.08	0.08
query4	1.61	0.11	0.11
query5	0.23	0.24	0.24
query6	1.18	0.68	0.67
query7	0.04	0.01	0.01
query8	0.05	0.04	0.04
query9	0.40	0.36	0.34
query10	0.57	0.59	0.58
query11	0.20	0.14	0.14
query12	0.19	0.15	0.15
query13	0.49	0.49	0.49
query14	1.04	1.02	0.98
query15	0.63	0.61	0.62
query16	0.35	0.35	0.35
query17	1.16	1.13	1.19
query18	0.21	0.20	0.18
query19	2.15	2.01	1.98
query20	0.01	0.01	0.01
query21	15.52	0.20	0.13
query22	4.82	0.06	0.06
query23	16.26	0.34	0.12
query24	3.20	0.61	0.33
query25	0.12	0.05	0.07
query26	1.14	0.21	0.16
query27	0.04	0.03	0.03
query28	2.71	0.73	0.37
query29	12.46	4.16	3.24
query30	0.28	0.12	0.10
query31	2.77	0.56	0.32
query32	3.23	0.60	0.50
query33	3.15	3.28	3.20
query34	15.42	3.98	3.37
query35	3.31	3.34	3.36
query36	0.56	0.46	0.42
query37	0.09	0.07	0.07
query38	0.04	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.14	0.14
query41	0.08	0.03	0.03
query42	0.04	0.03	0.02
query43	0.05	0.03	0.03
Total cold run time: 96.38 s
Total hot run time: 24.24 s

@hubgeter
hubgeter marked this pull request as ready for review November 3, 2026 13:26
hubgeter added a commit to hubgeter/doris that referenced this pull request Nov 4, 2026
### What problem does this PR solve?

Related PR: apache#70016

Problem Summary: Merge the latest master while preserving selected-partition scan costing and the upstream metadata error handling. Both branches independently advanced connector API 28.0 to 29.0 with different public surfaces. Advance the combined surface to API 30.0 and keep the merged recorded baseline so plugins built for upstream API 29.0 cannot be mistaken for compatible builds.

### Release note

Connector plugins must be rebuilt against API version 30.0.

### Check List (For Author)

- Test: Unit Test via run-fe-ut.sh; all 155 connector SPI tests passed after the merge. The broader focused FE run is in progress at commit time; final results are recorded in the PR. Checkstyle passed for fe-connector-spi, fe-connector-iceberg and fe-core.
- Behavior changed: Yes. The connector compatibility gate uses API 30.0; selected-partition cost and retained Filter/Join cardinality behavior are preserved.
- Does this need documentation: No.
@hubgeter

hubgeter commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hubgeter

hubgeter commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Local pipeline review — ✅ PASS

schema: doris-repo-review/v1
status: PASS
pr: apache/doris#70016
commit: 7a4620c7cf442b038e9928d14ad46dfdd18f13c3
base: 736649fcb41544ef977bb7677a1e6a5df5b7996b
reviewed_at: 2026-11-04T03:39+00:00
reviewer: hubgeter
model: gpt-6.1-sol
effort: max
findings: {blocker: 0, major: 0, minor: 0, nit: 0}
rounds: 1
converged: true

Notes for maintainers

  • fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModel.java:225 — Selected pinned partition rows affect physical FileScan CPU only; retained Filter/Join cardinality and column original lineage keep the baseline contract. Previous F-01/F-02 remain fixed.
  • fe/fe-connector/pom.xml:58 — API 30.0 retains both upstream typed table-absence errors and this row carrier; connector plugins require a matching rebuild. The merged MetadataRead boundary preserves pin ownership and failure propagation.
  • fe/fe-core/src/main/java/org/apache/doris/datasource/mvcc/PluginDrivenMvccSnapshot.java:282 — Costing reads only already-materialized RANGE rows for the exact table reference. Unknown/delete-affected/native/deferred/unavailable paths retain existing fallback.
  • Full review covered 14/14 files, re-confirmed 23 inherited dismissal entries and converged in one round. This review ran no builds or Doris tests; separate exact-head implementation validation passed 539 focused tests in 48 classes and Checkstyle. Customer SQL/cluster A/B, a guaranteed final MV winner and full FE/provider packaging remain unverified.

Reviewed locally with the doris-repo-review pipeline. Repository policy may accept this receipt for the matching commit; it is not a human Apache approval.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28810 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 7a4620c7cf442b038e9928d14ad46dfdd18f13c3, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17622	5201	5087	5087
q2	2138	328	259	259
q3	10226	1367	858	858
q4	4688	457	346	346
q5	7446	791	527	527
q6	184	187	156	156
q7	743	816	599	599
q8	9262	1330	1066	1066
q9	5462	4194	4170	4170
q10	6835	1299	1049	1049
q11	440	247	235	235
q12	635	406	291	291
q13	18097	3557	3048	3048
q14	292	282	251	251
q15	q16	723	709	652	652
q17	1196	748	576	576
q18	6920	6197	6120	6120
q19	1102	958	600	600
q20	395	338	221	221
q21	5021	2421	2498	2421
q22	378	348	278	278
Total cold run time: 99805 ms
Total hot run time: 28810 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5994	5886	6092	5886
q2	751	638	593	593
q3	5612	5749	5263	5263
q4	2027	2159	1593	1593
q5	5758	5888	5543	5543
q6	240	188	139	139
q7	2220	1984	1856	1856
q8	3056	2654	2744	2654
q9	8021	7638	7459	7459
q10	3604	3588	3106	3106
q11	583	406	375	375
q12	667	647	499	499
q13	3362	3594	3037	3037
q14	294	294	266	266
q15	q16	662	670	627	627
q17	7715	7019	6891	6891
q18	13023	12252	12834	12252
q19	891	794	786	786
q20	2151	2143	1937	1937
q21	5715	4606	4714	4606
q22	503	489	411	411
Total cold run time: 72849 ms
Total hot run time: 65779 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 151333 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 7a4620c7cf442b038e9928d14ad46dfdd18f13c3, data reload: false

query5	4330	614	453	453
query6	449	215	193	193
query7	4806	441	235	235
query8	335	167	153	153
query9	8790	3155	3189	3155
query10	475	313	254	254
query11	5963	3857	3581	3581
query12	144	95	88	88
query13	1256	454	307	307
query14	6097	3911	3650	3650
query14_1	3377	3426	3388	3388
query15	205	208	191	191
query16	945	434	384	384
query17	847	670	521	521
query18	2412	406	297	297
query19	216	158	131	131
query20	86	87	85	85
query21	217	134	108	108
query22	12942	13034	12783	12783
query23	13331	12899	12428	12428
query23_1	12549	12463	12451	12451
query24	7342	817	465	465
query24_1	494	532	492	492
query25	545	426	378	378
query26	1248	260	144	144
query27	2751	439	269	269
query28	4622	2059	2053	2053
query29	1545	594	462	462
query30	301	233	182	182
query31	1023	942	817	817
query32	147	100	99	99
query33	538	303	258	258
query34	907	862	510	510
query35	736	768	649	649
query36	810	809	725	725
query37	131	102	82	82
query38	1765	1758	1685	1685
query39	791	800	745	745
query39_1	732	744	750	744
query40	223	121	104	104
query41	78	69	70	69
query42	92	88	89	88
query43	344	364	318	318
query44	1331	697	719	697
query45	181	183	168	168
query46	835	984	587	587
query47	2869	2999	2856	2856
query48	303	326	233	233
query49	590	425	301	301
query50	675	276	219	219
query51	10617	10551	10595	10551
query52	82	83	79	79
query53	191	204	155	155
query54	251	224	194	194
query55	77	70	68	68
query56	269	229	233	229
query57	1657	1604	1575	1575
query58	294	258	267	258
query59	2133	2192	1949	1949
query60	299	256	235	235
query61	176	172	171	171
query62	391	333	306	306
query63	188	159	165	159
query64	2866	965	804	804
query65	3323	3273	3244	3244
query66	1754	419	323	323
query67	20168	20144	20122	20122
query68	3290	1005	631	631
query69	391	289	251	251
query70	820	810	763	763
query71	293	245	200	200
query72	2863	2596	2023	2023
query73	520	533	299	299
query74	4626	4476	4317	4317
query75	2336	2287	1952	1952
query76	2376	1014	579	579
query77	351	375	262	262
query78	9795	9744	9208	9208
query79	956	903	525	525
query80	876	431	326	326
query81	578	326	270	270
query82	723	128	101	101
query83	287	200	185	185
query84	313	117	101	101
query85	981	429	376	376
query86	364	242	226	226
query87	1995	1932	1797	1797
query88	3769	2775	2777	2775
query89	336	280	243	243
query90	1721	168	164	164
query91	161	154	130	130
query92	104	99	87	87
query93	1006	1038	582	582
query94	519	313	281	281
query95	586	352	301	301
query96	681	486	234	234
query97	2477	2420	2321	2321
query98	162	151	156	151
query99	766	760	664	664
Total cold run time: 235540 ms
Total hot run time: 151333 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.31 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 7a4620c7cf442b038e9928d14ad46dfdd18f13c3, data reload: false

query1	0.01	0.01	0.01
query2	0.10	0.05	0.04
query3	0.26	0.09	0.08
query4	1.60	0.10	0.10
query5	0.23	0.25	0.25
query6	1.17	0.68	0.69
query7	0.04	0.01	0.01
query8	0.06	0.03	0.03
query9	0.40	0.34	0.36
query10	0.61	0.58	0.57
query11	0.20	0.15	0.14
query12	0.19	0.15	0.15
query13	0.48	0.50	0.48
query14	1.02	1.02	1.02
query15	0.63	0.61	0.60
query16	0.34	0.34	0.31
query17	1.10	1.16	1.14
query18	0.21	0.18	0.19
query19	2.14	2.00	2.05
query20	0.02	0.01	0.02
query21	15.49	0.20	0.13
query22	4.93	0.06	0.05
query23	16.27	0.32	0.12
query24	3.01	0.78	0.42
query25	0.12	0.05	0.04
query26	1.57	0.22	0.16
query27	0.03	0.04	0.04
query28	3.22	0.73	0.36
query29	12.48	4.14	3.29
query30	0.28	0.13	0.10
query31	2.78	0.55	0.33
query32	3.23	0.59	0.50
query33	3.24	3.17	3.15
query34	15.40	3.99	3.38
query35	3.37	3.36	3.34
query36	0.55	0.45	0.40
query37	0.09	0.07	0.06
query38	0.05	0.04	0.03
query39	0.04	0.03	0.04
query40	0.17	0.16	0.14
query41	0.08	0.03	0.03
query42	0.04	0.04	0.03
query43	0.04	0.04	0.04
Total cold run time: 97.29 s
Total hot run time: 24.31 s

924060929
924060929 previously approved these changes Nov 4, 2026

@924060929 924060929 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iceberg partition pruning can reduce scan work while FileScan CPU cost still uses whole-table rows. This change carries pinned partition row estimates through the connector and converted-view cache into physical scan costing, while preserving cardinality and column-statistics lineage for retained filters and joins.

Independent static review covered all 14 changed files and the relevant snapshot, MV compensation, pruning, cache and scan translation paths. No blocking P0/P1/P2 issues were found. Unknown estimates and unsupported or unloaded views retain the existing estimate; costing does not trigger deferred metadata loading. Connector API 30.0 is updated consistently and requires matching plugin rebuilds.

APPROVE for the reviewed FE code at 7a4620c. No builds or tests were run during this review. The supplied current-head CI records show successful P0, FE UT, compilation and external regression checks, but NonConcurrent Regression failed. Its cause and the complete required-check policy were not available; this is not a merge-readiness confirmation.

Automated FE-focused static review (gpt-6.1-sol, high). No build or tests were run.

hubgeter added a commit to hubgeter/doris that referenced this pull request Nov 9, 2026
### What problem does this PR solve?

Related PR: apache#70016

Problem Summary: Merge current master into the partition scan cost fix. Preserve the upstream connector API 30 surface and the partition row estimate additions by advancing the combined plugin API to 31.

### Release note

Connector plugins must be rebuilt for API 31.

### Check List (For Author)

- Test: Checkstyle passed for the connector SPI reactor. Focused unit tests will validate the final implementation.
- Behavior changed: Yes, the combined connector plugin API is version 31.
- Does this need documentation: No
hubgeter added a commit to hubgeter/doris that referenced this pull request Nov 9, 2026
### What problem does this PR solve?

Related PR: apache#70016

Problem Summary: Partition-pruned scans can still pay exchange costs based on whole-table row estimates. Prove a cost-only bound from the logical memo expression and already-materialized statement partition metadata. Propagate it through row-nonincreasing unary operators and cap all distribution kinds without changing cardinality, column statistics, or physical child selection. Keep explicit scan selectors on the existing exchange estimate and preserve reference-aware FileScan CPU costing.

### Release note

Improve exchange cost estimates for partition-pruned Iceberg scans, including materialized view compensation.

### Check List (For Author)

- Test: Unit Test via run-fe-ut.sh. Across broad validation and the final focused rerun, 773 distinct tests in 49 classes have passing latest results. The final 36-test run passed after correcting a local-only fixture, including 11 new bound cases, 21 existing scan cases and 4 cost-model cases. Checkstyle passed for connector SPI, Iceberg and FE-core sources. Supplemental test fixtures remain local.
- Behavior changed: Yes, eligible exchange costs use a selected-partition upper bound; logical statistics are unchanged.
- Does this need documentation: No
@hubgeter hubgeter changed the title [fix](fe) Cost Iceberg scans using selected partition rows [fix](fe) Cost pruned Iceberg scans and exchanges by partition rows Nov 9, 2026
hubgeter added a commit to hubgeter/doris that referenced this pull request Nov 16, 2026
### What problem does this PR solve?

Issue Number: None
Related PR: apache#70016

Problem Summary: Add a compact five-row integration check for partition-pruned Iceberg queries while an MV covers only the first two days. Compare deterministic results with MV rewriting disabled and enabled, including range pruning, a retained NULL predicate, a nonpartition predicate, and an empty aggregate. Leave exact cost and plan-choice assertions to the FE unit tests.

### Release note

None

### Check List (For Author)

- Test: Regression test via run-regression-test.sh: five consecutive successful executions with the master regression runner against patched Apache Doris 4.0.6 FE and matching official BE. The first run generated 11 output blocks, independently checked against the input rows; four further runs compared that golden output. Exact master FE/BE integration remains for CI.
- Behavior changed: No, test-only change.
- Does this need documentation: No
### Background

Iceberg partition pruning can reduce the work performed by a FileScan
and the exchanges above it. The optimizer estimates physical cost
independently from the logical table and column statistics.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#70016 (upstream patch), apache#69678 (partition pruning)
PR Type: Bugfix

Problem Summary:

An Iceberg scan that selects only part of a snapshot can still be
charged for all rows. Propagate a bounded estimate from selected
partitions into scan and exchange costing.

### Details

- **Frequency:** Applies when a snapshot-consistent count is available for the selected partitions.
- **Root cause:** FileScan and exchange costs used whole-table estimates after pruning.
- **Why existing tests missed it:** Previous cases checked pruning or result correctness without asserting that the cost reflected the chosen partitions.
- **Fix:** Carry partition row estimates through the connector metadata and use them in costing while retaining the logical statistics for filter and join estimation.
- **Other paths and branches:** Preserve the published patch's snapshot and selector rules. Advance the connector SPI to 36.0 on the current master and retain the existing split-refinement SPI surface.

### Testing

- FE Checkstyle on the changed Java files, Groovy syntax parsing, and git diff --check passed.
- Used the existing whitespace-clean regression output blob. Compared it with the generated upstream file and confirmed that only the final empty line differs.
- FE unit, SPI reflection and Doris regression tests were skipped by request.

### Release note

Iceberg query planning accounts for selected partition rows when costing
supported pruned scans and their exchanges.

### Check List (For Author)

- Behavior changed: Yes (see Details).
- Does this need documentation: No.
- Pre-submission status: Partially verified: FE unit and Doris regression tests are pending.

### AI Disclosure

- Tool: Codex.
- Generated: Local merge conflict resolution and commit description. Production and test behavior derive from the upstream patch.
- Human review: Pending.
@hubgeter
hubgeter force-pushed the fix/iceberg-selected-partition-rowcount branch from 7558f82 to 5bcb4b1 Compare November 20, 2026 09:08
@hubgeter

Copy link
Copy Markdown
Contributor Author

run buildall

@hubgeter

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete authoritative diff for PR #70016 and found no new blocking or non-blocking code findings. The change carries snapshot-consistent Iceberg partition row estimates through the SPI, converted range-view cache, and PluginDriven MVCC snapshot; delete-file and unavailable/unknown cases conservatively fall back, while known zero remains distinct. The cost helper reads only already-materialized statement-pinned range metadata, preserves existing cardinality and column-statistics lineage, and applies exchange bounds only through non-expansive logical operators with a minimum against smaller existing estimates. Deferred publication uses immutable maps and volatile completion publication, and selector-aware physical lookups preserve time-travel identity. The retained four-argument SPI constructor, 36.0 plugin API bump, and refreshed surface baseline preserve compatibility requirements. Added unit/regression coverage was inspected; this review invocation was static-only and did not execute builds or tests. No user-provided review focus was supplied. Existing review threads contained no blocking findings. The review converged in round 1.

Review converged after 1 round(s).

### Background

The frontend loads plugins built for its connector API version. Master assigned
36.0 to the file format SPI while the Iceberg partition row estimates in this
branch independently advanced the same version.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#70016 (partition row estimates), apache#70903 (file format SPI)
PR Type: Build/CI/Chore

Problem Summary: Merge master into the partition estimates branch. Pin the
combined API to 37.0 so plugins can distinguish the new partition surface.

### Details

- **Affected:** The connector parent POM and the plugin API surface test.
- **Developer and release impact:** Rebuild external connector plugins against
  API 37.0 when deploying an FE with the new partition surface.
- **License and third-party:** None.
- **Rollback:** Reverting the partition statistics SPI changes together with
  this version bump restores the master connector contract.

### Testing

Checkstyle 9.3 passed on all 13 changed Java files. Both FE connector
architecture scripts passed. A source check verified the ordered union of
both plugin method baselines and the unchanged metadata method baseline.

### Release note

Connector plugins built for the API with partition row estimates use
connector plugin API 37.0.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified: local compilation was skipped
  at the author's request. Remote checks cover compilation and runtime tests.

### AI Disclosure

- Tool: OpenAI Codex
- Generated: Merge conflict resolution, static verification and commit message
- Human review: Pending
@hubgeter

Copy link
Copy Markdown
Contributor Author

run buildall

@hubgeter

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE. Reviewed #70016 at head 17b1d2b against base 47b0dea. The change adds optional per-partition row estimates to the connector MVCC SPI, carries them through immutable pinned Iceberg partition views, and uses them only for cost estimates while preserving cardinality and scan semantics.

Critical checkpoints: the stated goal is implemented with focused FE connector/MVCC/Nereids changes and targeted unit/regression coverage; no unsafe shared-state or lock/lifecycle issue was found (deferred publication is memoized and volatile, and metadata is never loaded by the statistics accessor); the SPI surface/version and backward-compatible constructor are updated together; parallel Iceberg delete, duplicate-name, evolution, pinned-snapshot, unknown-row, unavailable-view, and selector paths were traced; row-count and exchange costs fall back safely when metadata is unavailable or unknown; and the new regression fixture checks reference/rewrite result equivalence. Persistence, FE-BE wire fields, configuration, and security boundaries are not involved.

No existing inline review threads or user focus points were present. No new verified findings remain. This review converged in round 1: all assigned full and risk reviewers returned NO_NEW_VALUABLE_FINDINGS, every changed path was covered, and all risk items were dismissed with concrete evidence. Review was static-only; builds, tests, benchmarks, and a live cluster were not run in this runner.

Review converged after 1 round(s).

### Background

The connector API version allows the frontend to distinguish compatible
plugins. Native Iceberg encryption landed on master with API 37.0 while
this branch already used 37.0 for per-partition row estimates.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#70016, apache#70697
PR Type: Build/CI/Chore

Problem Summary: Merge current master and assign the combined connector
API version 38.0 in the parent POM and the plugin surface test.

### Details

- Affected: Connector plugin API version declaration and frozen surface test.
- Developer and release impact: External connector plugins using the new
  partition estimate API need to target version 38.0.
- License and third-party: None.

### Testing

Checkstyle passed on all 13 Java files in the PR. The connector import and
metadata funnel checks passed. The frozen plugin baseline retains all 12
upstream additions and all eight PR additions. The metadata baseline and
original PR file list were verified. The PR diff passed git diff --check.

### Release note

Connector plugins supporting the partition row estimates target API 38.0.

### Check List (For Author)

- Behavior changed: Yes, the plugin API version advances.
- Does this need documentation: No.
- Pre-submission status: Partially verified. Local compilation was skipped
  at the author's request. Runtime verification is delegated to CI.

### AI Disclosure

- Tool: OpenAI Codex
- Generated: Merge conflict resolution and static verification
- Human review: Pending
@hubgeter

Copy link
Copy Markdown
Contributor Author

run buildall

@hubgeter

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen hello-stephen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No actionable defects found in the source review of all 17 changed paths at ac574f5. Checked Iceberg merged counts and delete handling, pinned snapshot/deferred lifecycle, cache and SPI compatibility, and scan/exchange cost propagation. Review converged after one round with three delegated reviewers. Builds and tests were not run as requested; added tests were inspected. Residual test gap: the new exchange-cost/forGroup path has no direct unit assertion.

Review converged after 1 round(s).

if (selectedRows.isPresent()) {
// Partition metadata measures scan work. Keep the table-level cardinality and column
// statistics together so retained filters do not apply pruning selectivity twice.
scanRowCount = selectedRows.getAsLong();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the selected partition rows for FileScan CPU only when the connector can enforce that selection during file planning? I tested three daily DATE partitions (Jan 1–3, 2024) containing 1, 1,000 and 1,000 rows. For WHERE DAYOFWEEK(dt) = 2, Nereids selected Jan 1 and costed the scan at 5 CPU units (one row). Iceberg drops this function predicate during conversion and ignores requiredPartitions, so the SDK planned all three files, whose record counts sum to 2,001. The residual filter still returns the right rows, but the low scan cost can favor a plan that reads all three files. Please keep the existing scan estimate when file pruning cannot be established, and cover this residual-predicate case in the tests.

return OptionalLong.empty();
}
long rowCount = 0;
for (String name : partitionNames) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we compute this sum once for an immutable partition selection on its pinned snapshot and reuse it across cost calculations? Both FileScan and each candidate Exchange reach this loop. In a focused test with 10,000 selected partitions, costing one scan, one Gather and one Broadcast visited 30,000 partition entries for the same selection. On a wide date range, the planner pays for the same metadata traversal each time it compares distribution alternatives.

Comment thread fe/fe-connector/pom.xml
all five families).
-->
<connector.plugin.api.version>37.0</connector.plugin.api.version>
<connector.plugin.api.version>38.0</connector.plugin.api.version>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR description and release note to match the connector API version here. The release note currently tells plugin authors to target 31.0, while this build declares 38.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants