Skip to content

[opt](filescan) Reuse external scan tasks within a statement - #66530

Merged
924060929 merged 19 commits into
apache:masterfrom
924060929:fix/cir-21262-typed-scan-reuse-key
Sep 21, 2026
Merged

924060929 merged 19 commits into
apache:masterfrom
924060929:fix/cir-21262-typed-scan-reuse-key

Conversation

@924060929

@924060929 924060929 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary:

Queries with repeated equivalent external-table relations independently plan the same remote files for every branch, duplicating connector metadata work. The connector SPI already provides statement-scoped memoization for metadata, but scan planning was not memoized, so each duplicate relation re-planned through the connector SDK.

This change adds statement-scoped scan reuse to all four connectors. Each builds a typed key from the facts that affect its split set:

  • Iceberg: table/snapshot/schema identity, predicate, case sensitivity, task type.
  • Paimon: relation/target identity, snapshot/schema, options, projection, predicate.
  • Hudi: query/incremental instant, reader mode, partition identity, runtime-prune mode, Hudi parameters.
  • Hive: catalog/table identity, immutable partition/file-listing inputs.

Equivalent non-batch scans reuse connector-native tasks within one statement execution. Iceberg streaming/lazy batch paths, Hive partition-batch paths, transactional Hive scans, and system-table paths remain uncached to preserve their existing memory, transaction, and planning semantics.

The public ConnectorStatementScope String-key SPI remains unchanged for plugin compatibility. Each connector stores a private typed-key map under its own statement-scope namespace. The reuse switch is forwarded with the session and must be explicitly true, so an older planning FE that omits it safely disables reuse. Background task workers close their final StatementContext after each task so retained scan plans do not remain reachable for the worker lifetime.

Release note

Reuse equivalent non-batch Iceberg, Paimon, Hudi, and Hive scan-planning results within one statement execution.

Check List (For Author)

  • Test: Unit Test
    • HiveScanBatchModeTest
    • HudiScanReuseKeyTest
    • IcebergScanPlanProviderTest
    • PaimonScanPlanProviderTest
    • ConnectorPluginSurfaceTest
    • TaskProcessorTest
    • Checkstyle clean
    • ./build.sh --fe
  • Behavior changed: Yes. Equivalent non-batch external scans reuse statement-scoped planning results; transactional Hive, partition-batch/streaming, and system-table paths retain their previous behavior.
  • Does this need documentation: No

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

@924060929 924060929 changed the title [improvement](fe) Use typed keys with structural equals for scan reuse [refactor](fe) Replace string-encoded scan reuse keys with typed equals/hashCode Aug 6, 2026
@924060929 924060929 changed the title [refactor](fe) Replace string-encoded scan reuse keys with typed equals/hashCode [refactor](fe) Use typed equals/hashCode for scan reuse keys Aug 6, 2026
@morrySnow morrySnow changed the title [refactor](fe) Use typed equals/hashCode for scan reuse keys [refactor](scan) Use typed equals/hashCode for scan reuse keys Aug 6, 2026
@924060929 924060929 changed the title [refactor](scan) Use typed equals/hashCode for scan reuse keys [fix](fe) Fix scan reuse key aliasing and deduplicate key helpers Aug 6, 2026
@924060929 924060929 changed the title [fix](fe) Fix scan reuse key aliasing and deduplicate key helpers [refactor](fe) Replace string encoding with typed keys for scan reuse Aug 6, 2026
@924060929 924060929 changed the title [refactor](fe) Replace string encoding with typed keys for scan reuse [refactor](fe) Use typed objects instead of string encoding for scan reuse keys Aug 6, 2026
@924060929 924060929 changed the title [refactor](fe) Use typed objects instead of string encoding for scan reuse keys [improvement](fe) Statement-scoped scan reuse for Hive and Paimon, unify key approach Aug 6, 2026
@924060929 924060929 changed the title [improvement](fe) Statement-scoped scan reuse for Hive and Paimon, unify key approach [improvement](fe) Replace string-encoded scan reuse keys with typed equals/hashCode Aug 6, 2026
@924060929 924060929 changed the title [improvement](fe) Replace string-encoded scan reuse keys with typed equals/hashCode [improvement](fe) Reuse external scan tasks within a statement Aug 6, 2026
@924060929
924060929 force-pushed the fix/cir-21262-typed-scan-reuse-key branch from 141fd94 to cc165ac Compare August 6, 2026 07:04
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929
924060929 force-pushed the fix/cir-21262-typed-scan-reuse-key branch 2 times, most recently from 495ee54 to ab618f7 Compare August 6, 2026 08:23
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (1/1) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17729	3996	3931	3931
q2	2023	328	199	199
q3	10312	1407	799	799
q4	4685	475	338	338
q5	7535	868	563	563
q6	185	170	134	134
q7	765	790	620	620
q8	9313	1580	1590	1580
q9	5366	4125	4141	4125
q10	6736	1625	1332	1332
q11	501	352	328	328
q12	716	564	454	454
q13	18062	3306	2724	2724
q14	267	270	234	234
q15	q16	726	735	661	661
q17	992	1044	1007	1007
q18	6543	5590	5562	5562
q19	1299	1259	1042	1042
q20	823	661	595	595
q21	5945	2659	2475	2475
q22	447	348	297	297
Total cold run time: 100970 ms
Total hot run time: 29000 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4277	4234	4200	4200
q2	281	326	206	206
q3	4534	4893	4392	4392
q4	2178	2223	1406	1406
q5	4252	4097	4135	4097
q6	225	174	126	126
q7	1674	1591	1396	1396
q8	2767	2144	2128	2128
q9	7395	7493	7642	7493
q10	4272	4303	3886	3886
q11	546	419	373	373
q12	720	731	514	514
q13	3320	3476	2999	2999
q14	288	290	266	266
q15	q16	689	721	648	648
q17	1298	1301	1286	1286
q18	12099	10984	11794	10984
q19	1206	1148	1222	1148
q20	2218	2205	1971	1971
q21	5621	4824	4807	4807
q22	547	491	436	436
Total cold run time: 60407 ms
Total hot run time: 54762 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 166728 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 ab618f77680e4b572cff7534fd87c2ca04d150f5, data reload: false

query5	4310	600	441	441
query6	444	220	204	204
query7	4842	584	335	335
query8	319	192	146	146
query9	8776	4123	4063	4063
query10	487	356	313	313
query11	5788	2199	1995	1995
query12	173	96	99	96
query13	1296	585	438	438
query14	6103	4265	4040	4040
query14_1	3842	3832	3786	3786
query15	203	197	174	174
query16	1057	461	448	448
query17	888	666	547	547
query18	2471	470	323	323
query19	202	188	138	138
query20	100	98	102	98
query21	228	159	135	135
query22	13033	13011	13632	13011
query23	16196	15455	14889	14889
query23_1	14803	14514	14672	14514
query24	7565	1701	1231	1231
query24_1	1240	1246	1205	1205
query25	523	417	356	356
query26	1307	351	211	211
query27	2656	629	379	379
query28	4541	2044	2021	2021
query29	1052	613	491	491
query30	338	260	221	221
query31	1189	1125	1051	1051
query32	122	60	61	60
query33	548	308	257	257
query34	1202	1189	633	633
query35	752	758	619	619
query36	776	784	706	706
query37	162	112	90	90
query38	1827	1760	1683	1683
query39	848	823	801	801
query39_1	787	771	770	770
query40	261	172	147	147
query41	69	69	67	67
query42	94	93	92	92
query43	317	326	279	279
query44	1499	790	781	781
query45	191	174	162	162
query46	1072	1197	729	729
query47	1532	1516	1460	1460
query48	412	436	314	314
query49	597	413	296	296
query50	1065	455	346	346
query51	10579	10450	10549	10450
query52	90	90	79	79
query53	260	281	202	202
query54	290	253	238	238
query55	77	73	68	68
query56	318	307	316	307
query57	994	995	925	925
query58	295	274	269	269
query59	1573	1613	1393	1393
query60	340	289	272	272
query61	174	174	182	174
query62	402	329	279	279
query63	250	202	206	202
query64	3004	1201	851	851
query65	3862	3818	3776	3776
query66	1825	456	361	361
query67	28186	28125	27986	27986
query68	3202	1567	1037	1037
query69	395	299	262	262
query70	913	795	803	795
query71	381	353	312	312
query72	3044	2656	2375	2375
query73	817	766	458	458
query74	4623	4499	4293	4293
query75	2381	2333	2002	2002
query76	2337	1157	778	778
query77	333	392	270	270
query78	11278	11190	10530	10530
query79	1430	1168	770	770
query80	1234	536	457	457
query81	517	332	281	281
query82	672	181	133	133
query83	388	326	299	299
query84	331	158	131	131
query85	971	616	524	524
query86	401	240	226	226
query87	1982	1980	1841	1841
query88	3737	2819	2782	2782
query89	391	324	287	287
query90	2028	207	204	204
query91	207	193	164	164
query92	62	63	57	57
query93	1771	1526	974	974
query94	719	361	317	317
query95	795	504	565	504
query96	1063	875	353	353
query97	2483	2472	2308	2308
query98	195	184	204	184
query99	728	730	602	602
Total cold run time: 254491 ms
Total hot run time: 166728 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.09	0.05	0.05
query3	0.26	0.14	0.13
query4	1.61	0.14	0.14
query5	0.23	0.22	0.22
query6	1.16	0.82	0.83
query7	0.05	0.01	0.01
query8	0.06	0.04	0.04
query9	0.39	0.31	0.30
query10	0.60	0.54	0.54
query11	0.19	0.14	0.13
query12	0.18	0.14	0.14
query13	0.45	0.47	0.46
query14	0.99	1.00	0.99
query15	0.61	0.59	0.58
query16	0.33	0.31	0.33
query17	1.05	1.11	1.11
query18	0.21	0.19	0.20
query19	2.04	1.96	1.98
query20	0.02	0.02	0.01
query21	15.45	0.22	0.14
query22	4.78	0.05	0.05
query23	16.13	0.30	0.12
query24	3.01	0.43	0.32
query25	0.11	0.05	0.04
query26	0.72	0.20	0.14
query27	0.05	0.04	0.03
query28	3.58	0.80	0.35
query29	12.48	4.02	3.23
query30	0.27	0.15	0.16
query31	2.77	0.55	0.32
query32	3.22	0.58	0.48
query33	3.21	3.29	3.25
query34	15.47	3.91	3.26
query35	3.23	3.20	3.18
query36	0.54	0.41	0.41
query37	0.09	0.06	0.06
query38	0.05	0.04	0.03
query39	0.04	0.03	0.02
query40	0.17	0.16	0.15
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.05	0.03	0.03
Total cold run time: 96.08 s
Total hot run time: 23.96 s

@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/31142089772

Please trigger /review again after that time.

@924060929
924060929 force-pushed the fix/cir-21262-typed-scan-reuse-key branch from ab618f7 to 02b8284 Compare August 7, 2026 03:07
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/31143372312

Please trigger /review again after that time.

@924060929
924060929 force-pushed the fix/cir-21262-typed-scan-reuse-key branch from 02b8284 to a008699 Compare August 7, 2026 09:36
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17827	4048	3974	3974
q2	2125	316	198	198
q3	10282	1361	789	789
q4	4684	476	340	340
q5	7500	872	572	572
q6	183	172	138	138
q7	753	825	608	608
q8	9359	1547	1602	1547
q9	5311	4044	4012	4012
q10	6720	1636	1345	1345
q11	519	351	326	326
q12	702	578	458	458
q13	18115	3196	2745	2745
q14	271	259	244	244
q15	q16	744	732	658	658
q17	941	965	1062	965
q18	6577	5577	5569	5569
q19	1145	1315	1056	1056
q20	814	732	597	597
q21	5601	2663	2320	2320
q22	439	365	306	306
Total cold run time: 100612 ms
Total hot run time: 28767 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4296	4246	4187	4187
q2	294	319	210	210
q3	4552	4924	4335	4335
q4	2159	2246	1411	1411
q5	4216	4104	4143	4104
q6	232	172	131	131
q7	1729	1589	1445	1445
q8	2630	2353	2077	2077
q9	7488	7410	7539	7410
q10	4365	4269	3861	3861
q11	556	444	368	368
q12	721	730	535	535
q13	3070	3412	2881	2881
q14	301	297	261	261
q15	q16	690	740	670	670
q17	1340	1275	1309	1275
q18	12174	11056	11864	11056
q19	1207	1146	1197	1146
q20	2339	2231	1958	1958
q21	5584	4862	4929	4862
q22	546	480	454	454
Total cold run time: 60489 ms
Total hot run time: 54637 ms

### What problem does this PR solve?

Issue Number: None

Related PR: apache#66530

Problem Summary: Statement-scoped connector scan reuse is valuable for repeated external-table aliases but needs an immediate incident escape hatch. The connector SPI receives the default-on switch as an existing string session property and Hive, Hudi, Iceberg, and Paimon bypass their statement memo when it is false. The SPI remains independent of fe-core types.

### Release note

The new session variable enable_external_scan_task_reuse defaults to true. Set it to false to disable statement-scoped external split reuse.

### Check List (For Author)

- Test: Unit Test
    - run-fe-ut.sh with fe-connector-hudi HudiScanReuseKeyTest
- Behavior changed: Yes (a session switch can bypass external split reuse)
- Does this need documentation: No
Issue Number: None

Related PR: apache#66530

Problem Summary: Scan-reuse memos used inline statement-scope namespaces, and Hive used `hive` instead of its connector type `hms`. Since the statement scope is a shared untyped registry, unguarded namespace drift can collide with another owner and return an incompatible memo value. Declare connector-owned namespace constants for Hive, Hudi, Iceberg, and Paimon, and test every prefix against its provider type.

None

- Test: Unit Test
    - HiveScanBatchModeTest
    - HudiScanReuseKeyTest
    - IcebergScanPlanProviderTest
    - PaimonScanPlanProviderTest
    - ./build.sh --fe
- Behavior changed: No
- Does this need documentation: No
Problem Summary:

Mixed-version connector sessions could enable scan-task reuse without an explicit gate, partition batch admission could starve its bounded executor, and split-source shutdown could race final resource cleanup with an active producer.

This change requires an explicit true reuse gate, keeps partition planning in one tracked asynchronous producer with queue backpressure, and separates thread-safe cancellation from producer-owned close.

Release note: None

Test Plan:

- SplitAssignmentTest and PluginDrivenScanNodeBatchModeTest

- HiveScanBatchModeTest, HudiScanReuseKeyTest, IcebergScanPlanProviderTest, and PaimonScanPlanProviderTest

- mvn checkstyle:check -pl fe-core

- ./build.sh --fe
Problem Summary:

Recent review fixes expanded this scan-reuse PR into partition-batch scheduling, streaming split cancellation, generic query callback ordering, and MTMV execution lifecycle changes.

Remove those unrelated changes. Keep only non-batch statement-scoped scan reuse, its explicit mixed-version gate, connector-specific exclusions, SPI compatibility coverage, and the minimal background-task scope cleanup needed to release retained reuse results.

Release note: None

Test Plan:

- Connector reuse and SPI focused unit tests

- TaskProcessorTest

- FE Checkstyle

- ./build.sh --fe
Issue Number: None

Related PR: apache#66530

Problem Summary: Hive, Hudi, Iceberg, and Paimon each parsed the same enable_external_scan_task_reuse session property, which duplicated the engine-owned policy and allowed future connectors to diverge. Expose one fail-closed ConnectorSession method and route all four providers through it. Preserve Iceberg metadata-column reader validation before a statement-reuse cache hit can return ranges planned for ordinary columns. Because current master already serves connector plugin API 7.0, advance the major to 8.0 for the new frozen ConnectorSession method.

None

- Test: Unit Test
    - ConnectorPluginSurfaceTest
    - ConnectorMetadataSurfaceTest
    - ConnectorSessionImplTest
    - HiveScanBatchModeTest
    - HudiScanReuseKeyTest
    - IcebergScanPlanProviderTest
    - PaimonScanPlanProviderTest
    - TaskProcessorTest
    - ./build.sh --fe
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66530

Problem Summary: Paimon and Hudi scan reuse could compute a generation token from one physical table instance, plan file ranges from a newly resolved instance, and serialize scan properties from another instance. A same-path table recreation or schema change could therefore pair generation-A ranges with generation-B schema metadata. Resolve one statement-scoped physical table holder per complete data-table relation identity and pass that exact object through planning and property construction. Keep Paimon system-table wrapper and source state handle-local because system-table split planning bypasses reuse; otherwise equal aliases can combine one alias wrapper with another alias source and ranges. Include Paimon branch and effective scan options plus the Hudi base path in resolution identities. Authenticate the Paimon latest-snapshot lookup because it may read snapshot metadata through a Kerberos-backed FileIO after table resolution has left its authenticated scope. Advance the connector plugin API to 10.0 because ConnectorSession adds the external scan reuse policy method.

### Release note

Fix external Paimon and Hudi scan reuse across table generations.

### Check List (For Author)

- Test: Unit Test and FE build
    - PaimonScanPlanProviderTest: 100 tests passed
    - HudiScanReuseKeyTest
    - ConnectorPluginSurfaceTest
    - FE Maven reactor in ./build.sh --fe --clean -j2: BUILD SUCCESS; generated output packaging then stopped because an existing jdbc.conf makes macOS cp -n return 1
- Behavior changed: Yes, reused scans now stay on one physical table generation within a statement
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66530

Problem Summary: Hive directory-listing failures and Hudi schema-resolution fallbacks can return usable but degraded scan plans. Statement-level scan reuse previously cached those results, preventing a later alias in the same statement from retrying after a transient failure. Track plan completeness and return degraded results without installing them in the statement memo, while preserving the existing tolerant behavior. Add fail-once/succeed-next tests for Hive listing and Hudi per-file schema resolution.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - HiveScanBatchModeTest (25 tests passed)
    - HudiScanReuseKeyTest (14 tests passed)
    - Hive/Hudi FE connector Checkstyle
- Behavior changed: Yes; degraded scan plans are no longer reused within a statement
- Does this need documentation: No
@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@924060929

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.

Static exact-head review of 98f451dd4fa8afb68e98d0e43f2019de2c82001b.

Outcome: request changes for one distinct P2 performance defect in Paimon statement-scoped scan reuse. No other P1/P2 survived the existing-thread duplicate fence and two bounded full-review/risk-review rounds.

Critical checkpoint conclusions:

  • Goal, scope, and tests: the PR consistently adds statement-scoped range-plan reuse across Hive, Hudi, Iceberg, and Paimon, with the necessary SPI, session-variable, and lifecycle plumbing. The targeted tests cover key equality, reuse hits, degraded-plan rejection, generation coupling, and scope cleanup, but the Paimon test currently codifies two generation probes for two equal requests and does not cover live-latest churn or the pinned-empty no-probe path.
  • Correctness, error handling, and concurrency: reuse keys were traced against the inputs actually consumed by each planner. Tolerated Hive/Hudi degradation remains caller-local and is not cached; memoized values are immutable and copied before downstream sampling. No distinct wrong-result, publication, or mutation issue remains.
  • Lifecycle and ownership: foreground query callbacks, worker cleanup, MTMV child scopes, retry/IVM paths, and statement-scope teardown were traced. The changed head has deterministic owned cleanup; the remaining suspicious lifecycle shapes are already covered by existing inline threads.
  • Configuration and compatibility: the forwarded enable_external_scan_task_reuse value, fail-closed SPI default, connector API-major bump, and frozen surface are internally consistent. No separate compatibility issue remains.
  • Parallel paths and performance: Hive batch, Iceberg streaming, transactional, and system-table exclusions preserve their bounded-memory or semantic contracts. The remaining Paimon issue is that fixed/pinned aliases still perform a live remote generation read before the memo lookup, and a concurrent latest-pointer advance can force a redundant retained plan for the same pinned scan. Open-ended incremental/dynamic selectors are explicitly outside this finding.
  • Persistence, protocol, and observability: this change introduces no EditLog/storage-format/data-write change or new FE-BE payload. Existing profiles/logging remain adequate for the changed behavior.

User focus: no additional focus was supplied; the complete changed-file set and related call chains were reviewed. Validation status: static review only, as this review environment prohibited builds and tests; test conclusions above are based on source and diff inspection, not independent execution.

// this, a no-cache catalog or a schema change between two aliases can give alias A's ranges
// to alias B's generation-B serialized table.
Table table = resolveScanTableConsistent(session, paimonHandle);
long generation = resolvePaimonGeneration(table);

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.

[P2] Avoid re-reading live latest for already-fixed scan identities. Normal/latest, snapshot/timestamp, branch, statement-fenced options, and pinned-empty reads reach this method with their scan identity fixed on the handle, but this probe runs before scanReuse.computeIfAbsent. N equal aliases therefore still perform N authenticated snapshot-pointer reads (the changed test explicitly expects two); if latest advances from S1 to S2 between aliases, the generation field also forces another full retained plan even though both requests still scan pinned S1. Derive or memoize the generation for fixed handles, and keep live fencing or bypass reuse only for genuinely latest-dependent selectors such as open-ended @incr. Please cover both cases, plus a pinned-empty path that does not probe latest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 616b309. Fixed snapshot identities now use their pinned snapshot id as the reuse generation, and pinned-empty identities skip the live latest lookup entirely. Latest-dependent selectors such as open-ended incremental scans still read and fence on the live generation. Added coverage for all three paths; PaimonScanPlanProviderTest passes 103/103 and ./build.sh --fe passes.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17620	3836	3757	3757
q2	2211	394	306	306
q3	9998	1426	798	798
q4	4685	479	353	353
q5	7468	823	548	548
q6	183	169	140	140
q7	741	852	593	593
q8	9296	1475	1535	1475
q9	5455	4175	4190	4175
q10	6822	1322	1010	1010
q11	427	261	253	253
q12	630	413	304	304
q13	18043	2601	2001	2001
q14	260	258	235	235
q15	q16	740	710	661	661
q17	1771	1147	1012	1012
q18	6487	5602	5591	5591
q19	1324	1196	1083	1083
q20	485	394	270	270
q21	5754	3235	2956	2956
q22	452	360	310	310
Total cold run time: 100852 ms
Total hot run time: 27831 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4655	4671	4370	4370
q2	750	568	532	532
q3	4699	5117	4603	4603
q4	2179	2382	1427	1427
q5	4628	4358	4603	4358
q6	229	175	121	121
q7	1795	1650	1530	1530
q8	2286	2068	2012	2012
q9	7388	7209	7236	7209
q10	3670	3598	3143	3143
q11	512	368	342	342
q12	712	693	498	498
q13	2265	2594	2001	2001
q14	288	269	254	254
q15	q16	724	675	620	620
q17	7277	6696	6624	6624
q18	11836	11033	11719	11033
q19	1071	979	1007	979
q20	2199	2203	1891	1891
q21	4948	4064	4259	4064
q22	494	445	398	398
Total cold run time: 64605 ms
Total hot run time: 58009 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 151575 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 98f451dd4fa8afb68e98d0e43f2019de2c82001b, data reload: false

query5	4311	603	451	451
query6	426	211	190	190
query7	4803	566	294	294
query8	319	171	161	161
query9	8796	3998	3993	3993
query10	464	307	259	259
query11	5889	3520	3226	3226
query12	147	91	87	87
query13	1300	591	403	403
query14	6547	4469	4202	4202
query14_1	3987	3981	3944	3944
query15	201	200	174	174
query16	989	454	424	424
query17	920	670	524	524
query18	2471	466	327	327
query19	202	184	141	141
query20	83	80	81	80
query21	220	134	115	115
query22	13023	12992	12729	12729
query23	13857	13187	12375	12375
query23_1	12556	12608	12472	12472
query24	7182	1200	645	645
query24_1	687	706	674	674
query25	594	442	370	370
query26	1278	324	173	173
query27	2660	573	342	342
query28	4554	1966	1975	1966
query29	1616	744	537	537
query30	307	216	180	180
query31	890	754	636	636
query32	158	99	97	97
query33	523	314	255	255
query34	1200	1113	633	633
query35	729	749	631	631
query36	782	813	689	689
query37	145	114	96	96
query38	1814	1778	1707	1707
query39	684	687	663	663
query39_1	662	647	642	642
query40	243	122	103	103
query41	72	69	69	69
query42	98	101	95	95
query43	337	340	297	297
query44	1345	750	703	703
query45	183	182	168	168
query46	1092	1161	714	714
query47	1485	1520	1428	1428
query48	391	382	289	289
query49	582	396	279	279
query50	1007	356	252	252
query51	10528	10153	10682	10153
query52	88	86	75	75
query53	238	254	181	181
query54	258	201	182	182
query55	79	72	69	69
query56	230	213	201	201
query57	1368	1437	1284	1284
query58	278	259	251	251
query59	1958	2067	1830	1830
query60	277	241	224	224
query61	149	165	142	142
query62	399	319	285	285
query63	218	180	175	175
query64	2804	1013	811	811
query65	3462	3415	3414	3414
query66	1810	424	311	311
query67	19994	19870	20021	19870
query68	3091	1434	912	912
query69	390	294	261	261
query70	901	827	802	802
query71	306	234	204	204
query72	2561	2594	2193	2193
query73	827	726	425	425
query74	4605	4487	4274	4274
query75	2289	2265	1934	1934
query76	2302	1091	725	725
query77	356	396	285	285
query78	8996	8997	8368	8368
query79	1389	1177	775	775
query80	1224	457	382	382
query81	591	319	276	276
query82	651	157	122	122
query83	304	226	200	200
query84	312	143	114	114
query85	939	483	390	390
query86	410	247	222	222
query87	1993	1956	1846	1846
query88	3652	2724	2684	2684
query89	370	284	242	242
query90	1996	180	186	180
query91	167	156	125	125
query92	100	88	88	88
query93	1385	1462	865	865
query94	704	323	293	293
query95	667	373	413	373
query96	1019	825	321	321
query97	2473	2447	2314	2314
query98	161	148	141	141
query99	710	726	620	620
Total cold run time: 236312 ms
Total hot run time: 151575 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.09	0.05	0.05
query3	0.25	0.14	0.14
query4	1.61	0.14	0.14
query5	0.23	0.22	0.21
query6	1.16	0.90	0.90
query7	0.04	0.01	0.00
query8	0.06	0.04	0.04
query9	0.40	0.33	0.34
query10	0.55	0.55	0.53
query11	0.20	0.13	0.15
query12	0.18	0.15	0.15
query13	0.46	0.45	0.46
query14	0.96	0.94	0.93
query15	0.60	0.59	0.58
query16	0.32	0.31	0.31
query17	1.11	1.05	1.05
query18	0.22	0.20	0.20
query19	1.95	1.97	1.95
query20	0.02	0.01	0.01
query21	15.45	0.22	0.13
query22	4.73	0.05	0.05
query23	16.17	0.30	0.12
query24	2.97	0.42	0.32
query25	0.10	0.04	0.05
query26	0.74	0.21	0.14
query27	0.03	0.04	0.04
query28	3.56	0.81	0.37
query29	12.50	4.10	3.24
query30	0.28	0.15	0.15
query31	2.77	0.56	0.31
query32	3.22	0.58	0.48
query33	3.11	3.15	3.22
query34	15.52	3.95	3.27
query35	3.22	3.23	3.24
query36	0.56	0.44	0.43
query37	0.09	0.06	0.06
query38	0.05	0.04	0.03
query39	0.03	0.03	0.03
query40	0.19	0.16	0.15
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 95.88 s
Total hot run time: 23.94 s

### What problem does this PR solve?

Issue Number: None

Related PR: apache#66530

Problem Summary: Paimon scans whose handles were already pinned to a snapshot, including pinned-empty scans, still read the live latest snapshot before consulting statement-level scan reuse. Equal aliases therefore repeated authenticated metadata I/O, and a concurrent commit could assign different generation keys to aliases that both scan the same pinned snapshot. Use the pinned snapshot as the generation for fixed identities and skip the live probe for pinned-empty identities, while retaining live generation fencing for selectors such as open-ended incremental scans.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - PaimonScanPlanProviderTest (103 tests passed)
    - ./build.sh --fe
- Behavior changed: Yes; fixed Paimon scan identities no longer read the live latest snapshot for reuse-key generation
- Does this need documentation: No
@924060929

Copy link
Copy Markdown
Contributor Author

/review

@924060929

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17741	3906	3850	3850
q2	2200	358	310	310
q3	10057	1477	786	786
q4	4683	484	350	350
q5	7464	827	545	545
q6	182	171	144	144
q7	732	791	611	611
q8	9303	1461	1393	1393
q9	5411	4193	4158	4158
q10	6844	1317	1016	1016
q11	437	272	249	249
q12	634	419	293	293
q13	18060	2614	1983	1983
q14	262	254	229	229
q15	q16	737	714	665	665
q17	1866	1186	1021	1021
q18	6587	5615	5524	5524
q19	1191	1212	1038	1038
q20	495	388	260	260
q21	5421	3142	3095	3095
q22	472	371	308	308
Total cold run time: 100779 ms
Total hot run time: 27828 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4570	4745	4392	4392
q2	745	588	539	539
q3	4776	5219	4610	4610
q4	2205	2372	1457	1457
q5	4517	4403	4583	4403
q6	224	175	125	125
q7	1804	1701	1499	1499
q8	2318	2018	2031	2018
q9	7276	7271	7251	7251
q10	3698	3566	3083	3083
q11	511	376	339	339
q12	702	710	510	510
q13	2287	2596	2010	2010
q14	269	269	246	246
q15	q16	662	676	600	600
q17	7369	6763	6661	6661
q18	11886	11098	11761	11098
q19	1091	1033	1043	1033
q20	2185	2193	1900	1900
q21	4965	4171	4278	4171
q22	503	449	414	414
Total cold run time: 64563 ms
Total hot run time: 58359 ms

@github-actions

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

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

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152562 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 616b309de361b562641ee8f8e5d8e1507a3a446e, data reload: false

query5	4299	614	442	442
query6	422	211	192	192
query7	4816	562	291	291
query8	315	170	159	159
query9	8805	3929	3960	3929
query10	443	286	258	258
query11	5887	3540	3215	3215
query12	143	92	87	87
query13	1268	579	418	418
query14	6506	4591	4214	4214
query14_1	3980	3968	3959	3959
query15	203	202	175	175
query16	1000	490	437	437
query17	917	663	567	567
query18	2425	455	322	322
query19	196	174	132	132
query20	81	79	76	76
query21	215	130	111	111
query22	12945	13046	12863	12863
query23	14036	13097	12465	12465
query23_1	12532	12667	12555	12555
query24	7266	1135	714	714
query24_1	673	709	719	709
query25	540	415	375	375
query26	1275	310	160	160
query27	2670	528	326	326
query28	4564	1978	1960	1960
query29	1623	725	509	509
query30	289	215	184	184
query31	909	753	630	630
query32	142	91	89	89
query33	517	294	239	239
query34	1177	1107	638	638
query35	737	731	639	639
query36	781	818	684	684
query37	151	131	92	92
query38	1817	1756	1661	1661
query39	679	692	652	652
query39_1	668	637	660	637
query40	213	116	99	99
query41	66	64	61	61
query42	96	93	88	88
query43	331	340	297	297
query44	1359	698	713	698
query45	182	175	168	168
query46	1092	1170	712	712
query47	1479	1493	1383	1383
query48	384	388	297	297
query49	590	406	295	295
query50	952	342	254	254
query51	10481	10233	10380	10233
query52	85	84	75	75
query53	237	257	176	176
query54	245	207	185	185
query55	80	72	67	67
query56	227	206	201	201
query57	1455	1459	1403	1403
query58	279	259	248	248
query59	1970	2046	1864	1864
query60	272	244	223	223
query61	146	146	142	142
query62	409	319	269	269
query63	217	174	174	174
query64	2785	1040	943	943
query65	3452	3405	3412	3405
query66	1824	445	314	314
query67	20189	19921	20065	19921
query68	2985	1526	946	946
query69	418	319	270	270
query70	881	837	821	821
query71	299	240	216	216
query72	2775	2656	2367	2367
query73	847	759	418	418
query74	4644	4505	4304	4304
query75	2300	2270	1903	1903
query76	2325	1104	764	764
query77	337	392	294	294
query78	9258	9100	8516	8516
query79	1295	1242	704	704
query80	580	457	358	358
query81	535	320	277	277
query82	622	165	125	125
query83	296	220	192	192
query84	318	143	111	111
query85	824	456	387	387
query86	328	246	217	217
query87	1996	1967	1831	1831
query88	3623	2728	2715	2715
query89	360	282	244	244
query90	1909	185	175	175
query91	167	165	127	127
query92	100	92	87	87
query93	1471	1412	879	879
query94	532	343	305	305
query95	687	370	332	332
query96	1039	767	361	361
query97	2443	2426	2319	2319
query98	159	147	146	146
query99	716	719	616	616
Total cold run time: 235610 ms
Total hot run time: 152562 ms

@hello-stephen

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

query1	0.01	0.00	0.01
query2	0.09	0.05	0.05
query3	0.26	0.14	0.12
query4	1.60	0.13	0.14
query5	0.25	0.22	0.22
query6	1.17	0.94	0.95
query7	0.04	0.00	0.01
query8	0.06	0.04	0.03
query9	0.39	0.33	0.33
query10	0.57	0.54	0.54
query11	0.21	0.14	0.14
query12	0.19	0.15	0.14
query13	0.45	0.45	0.46
query14	0.97	0.93	0.93
query15	0.61	0.58	0.58
query16	0.30	0.31	0.30
query17	1.07	1.08	1.08
query18	0.22	0.20	0.20
query19	2.06	1.91	1.86
query20	0.02	0.01	0.01
query21	15.50	0.22	0.13
query22	4.84	0.06	0.05
query23	16.13	0.30	0.13
query24	2.95	0.42	0.33
query25	0.13	0.05	0.04
query26	0.72	0.19	0.15
query27	0.05	0.05	0.03
query28	3.54	0.85	0.36
query29	12.49	4.00	3.20
query30	0.29	0.17	0.16
query31	2.76	0.58	0.31
query32	3.22	0.59	0.50
query33	3.13	3.16	3.15
query34	15.55	3.91	3.30
query35	3.22	3.20	3.22
query36	0.57	0.43	0.40
query37	0.09	0.07	0.06
query38	0.05	0.04	0.03
query39	0.04	0.03	0.02
query40	0.17	0.15	0.14
query41	0.08	0.04	0.03
query42	0.04	0.03	0.03
query43	0.05	0.04	0.03
Total cold run time: 96.15 s
Total hot run time: 23.83 s

@924060929

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

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

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

@924060929

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.

Static review result: no new non-duplicate actionable findings were found on requested head 616b309de361b562641ee8f8e5d8e1507a3a446e. I did not repost concerns already covered by the live inline threads; this COMMENT does not resolve or supersede those discussions.

Critical checkpoint conclusions:

  • Goal and proof: the change reuses equivalent non-batch external scan range plans within one statement for Hive, Hudi, Iceberg, and Paimon. The new tests exercise live-scope hits, structural filters, disabled/missing settings, transient retry behavior, generation pairing, and cleanup, although this review did not execute them.
  • Scope and focus: the 21 changed files are focused on connector plan reuse, its SPI/configuration surface, statement/task cleanup, and targeted tests. No additional user focus was supplied.
  • Concurrency: connector-private ConcurrentHashMap memos provide same-key single-flight behavior; returned lists/ranges are immutable and engine scan nodes create fresh mutable Split wrappers. Session-derived routing inputs are statement-constant. Existing lifecycle discussions were treated as duplicate fences.
  • Lifecycle: memo ownership follows StatementContext and query-finish cleanup; task contexts unregister query callbacks and close statement resources. I found no new lifecycle mechanism beyond concerns already present in the inline review.
  • Configuration: enable_external_scan_task_reuse defaults on in FE, is forwarded to the planning FE, and the SPI default enables reuse only when the session property is explicitly present and true.
  • Compatibility: the new ConnectorSession surface is frozen in the API baseline and the connector plugin API major moves from 9 to 10, matching the exact-major gate. No new FE/BE wire or storage-format field is introduced.
  • Parallel paths and special cases: Hive partition-batch, Iceberg streaming, Hive transactional scans, and connector system-table scans remain deliberately uncached where reuse would violate resource or side-effect semantics. Iceberg keeps per-call metadata-reader validation; Hive/Hudi incomplete results remain retryable.
  • Tests and results: the changed tests target the principal key, generation, retry, and cleanup contracts. Per the review instructions, no build or test command was run, so author/CI results were not independently validated.
  • Observability: existing scan profiles and contextual warning/info logs cover planning and fallback paths; this statement-local optimization did not expose a distinct missing diagnostic that warrants a review finding.
  • Transactions and persistence: no EditLog, replay, durable metadata, or transaction-commit format is changed.
  • Data writes: no data-write algorithm or atomicity contract is changed; the reviewed behavior is FE-side read planning and resource cleanup.
  • FE/BE variables: the new setting remains an FE planning variable and is forwarded between FEs; existing scan-range/property carriers to BE are reused unchanged.
  • Performance: normal-path duplicate planning and remote metadata work are eliminated while large Hive batch and Iceberg streaming paths stay uncached to preserve bounded memory. Statement-held plans are released with the statement; no new substantiated CPU or memory regression was found.
  • Other/error handling: Hive skipped-directory and Hudi schema-degradation results avoid cache installation so later aliases can retry. Hudi's incremental full-table fallback is an intentional complete alternate plan with the fixed row predicate, not a partial result.

Validation was static only, as required.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants