Skip to content

[fix](fe) Preserve operative slots when deep copying logical relations#63315

Open
foxtail463 wants to merge 1 commit into
apache:masterfrom
foxtail463:fix/logical-plan-deep-copier-operative-slots
Open

[fix](fe) Preserve operative slots when deep copying logical relations#63315
foxtail463 wants to merge 1 commit into
apache:masterfrom
foxtail463:fix/logical-plan-deep-copier-operative-slots

Conversation

@foxtail463
Copy link
Copy Markdown
Contributor

@foxtail463 foxtail463 commented May 16, 2026

problem summary:

When deep copying a LogicalCatalogRelation, LogicalPlanDeepCopier#updateOperativeSlots needs to remap the original relation's operative slots to the corresponding slots in the copied relation.

Before this change, the search range was incorrectly limited by oldOperativeSlots.size() instead of the relation output size. If the operative slot was not located in the first oldOperativeSlots.size() output positions, the copier could not find the matching slot and the copied relation would lose that operative slot.

For example, when a relation has multiple output slots but only one operative slot at index 1, the old logic only checked index 0 and failed to preserve the operative slot.

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

@morrySnow
Copy link
Copy Markdown
Contributor

/review

@englefly
Copy link
Copy Markdown
Contributor

/review

@englefly
Copy link
Copy Markdown
Contributor

run buildall

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label May 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Review opinion: no blocking issues found in this PR.

Critical checkpoint conclusions:

  • Goal and proof: The change fixes deep-copy remapping for operative slots whose index is outside the operative-slot list prefix by searching the full relation output. The added unit test covers a non-first operative slot and would fail on the old bound.
  • Scope: The modification is minimal and focused on the incorrect loop bound plus a narrow regression test.
  • Concurrency and lifecycle: This copier path does not introduce shared mutable state, locks, threads, or non-trivial lifecycle/static-initialization concerns.
  • Configuration and compatibility: No new config, persistence, protocol, storage format, or rolling-upgrade compatibility concern.
  • Parallel paths: The helper is used by LogicalCatalogRelation copy path, so the fix covers catalog scan subclasses that rely on relation output-to-output positional remapping.
  • Conditional checks: No new special conditional logic; existing missing-slot warning behavior is unchanged.
  • Test coverage: A focused FE unit test was added for the bug scenario. I attempted to run ./run-fe-ut.sh --run org.apache.doris.nereids.trees.copier.LogicalPlanDeepCopierTest, but the runner lacks thirdparty/installed/bin/protoc, so generated-code setup failed before executing tests.
  • Observability, transactions, data writes, FE/BE variable passing, and performance: Not applicable to this small copier/test change; no additional issue found.

User focus points: No additional user-provided review focus was present.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

No blocking issues found.

Critical checkpoint conclusions:

  • Goal/test: The change fixes preservation of operative slots whose output position is beyond the number of operative slots, and the new unit test covers the reported non-first-slot case.
  • Scope: The code change is minimal and focused on the incorrect search bound in LogicalPlanDeepCopier.
  • Concurrency/lifecycle/config/compatibility: Not applicable; this is local plan-copy logic with no new shared state, lifecycle management, config, persistence, or wire/storage format change.
  • Parallel paths: The change applies to LogicalCatalogRelation copier handling, which is the affected path for catalog relations with operative slots.
  • Error handling: Existing warning path for unmatched operative slots remains unchanged.
  • Test coverage: Added FE unit coverage for the regression scenario. No additional focus points were provided, and no extra issue was found there.
  • Performance: The loop now scans the relation output instead of the operative-slot subset; this is necessary for correctness and remains small/local to plan copying.
  • Data correctness: Preserving operative slots avoids losing required materialization information after deep copy.

Review context: Existing inline review threads were empty, so no duplicate issues were present.

@hello-stephen
Copy link
Copy Markdown
Contributor

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

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17664	3949	3866	3866
q2	q3	10830	1357	818	818
q4	4681	475	342	342
q5	7557	2299	2089	2089
q6	241	175	137	137
q7	944	808	640	640
q8	9408	1677	1717	1677
q9	5179	4874	4899	4874
q10	6395	2075	1775	1775
q11	440	272	250	250
q12	627	426	296	296
q13	18082	3367	2742	2742
q14	264	262	231	231
q15	q16	822	768	707	707
q17	1000	950	1014	950
q18	6895	5721	5465	5465
q19	1361	1275	1110	1110
q20	518	402	311	311
q21	6565	2783	2753	2753
q22	468	383	311	311
Total cold run time: 99941 ms
Total hot run time: 31344 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4834	4526	4475	4475
q2	q3	4891	5237	4619	4619
q4	2135	2219	1410	1410
q5	4898	4610	4608	4608
q6	245	198	136	136
q7	1874	1735	1536	1536
q8	2356	2036	2118	2036
q9	7667	7390	7220	7220
q10	4458	4406	3996	3996
q11	520	377	349	349
q12	703	713	517	517
q13	3085	3328	2821	2821
q14	275	272	262	262
q15	q16	678	697	600	600
q17	1263	1240	1228	1228
q18	7105	6923	6939	6923
q19	1109	1104	1071	1071
q20	2190	2187	1925	1925
q21	5326	4580	4475	4475
q22	528	489	434	434
Total cold run time: 56140 ms
Total hot run time: 50641 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 168820 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 0720367e506e8b7b51c469cded21d605a5f95fa6, data reload: false

query5	4327	639	513	513
query6	342	207	195	195
query7	4260	546	288	288
query8	338	237	211	211
query9	8797	3968	3976	3968
query10	444	339	289	289
query11	5796	2328	2209	2209
query12	181	125	123	123
query13	1288	614	443	443
query14	5971	5341	5045	5045
query14_1	4384	4287	4337	4287
query15	214	197	184	184
query16	1019	438	450	438
query17	1035	707	568	568
query18	2441	480	346	346
query19	215	201	154	154
query20	146	132	131	131
query21	218	135	116	116
query22	13503	13659	13380	13380
query23	17220	16334	15904	15904
query23_1	16247	16144	16229	16144
query24	7597	1766	1294	1294
query24_1	1297	1292	1308	1292
query25	552	488	417	417
query26	1314	323	169	169
query27	2684	543	331	331
query28	4441	1934	1934	1934
query29	969	598	488	488
query30	299	234	206	206
query31	1104	1055	937	937
query32	98	77	71	71
query33	504	348	288	288
query34	1191	1126	644	644
query35	762	768	679	679
query36	1303	1335	1173	1173
query37	154	102	87	87
query38	3224	3116	3043	3043
query39	938	947	906	906
query39_1	878	875	867	867
query40	227	144	123	123
query41	66	63	62	62
query42	110	108	105	105
query43	324	320	285	285
query44	
query45	213	200	199	199
query46	1040	1176	741	741
query47	2297	2377	2146	2146
query48	395	411	298	298
query49	626	492	400	400
query50	967	348	250	250
query51	4322	4283	4312	4283
query52	104	105	95	95
query53	261	274	207	207
query54	316	262	250	250
query55	92	88	95	88
query56	287	296	318	296
query57	1426	1416	1345	1345
query58	288	271	274	271
query59	1541	1591	1442	1442
query60	334	338	330	330
query61	182	180	176	176
query62	673	629	550	550
query63	245	204	219	204
query64	2482	868	714	714
query65	
query66	1748	493	366	366
query67	30072	29345	29217	29217
query68	
query69	463	338	305	305
query70	1031	1028	990	990
query71	305	274	262	262
query72	2975	2765	2671	2671
query73	856	765	391	391
query74	5054	4956	4735	4735
query75	2663	2578	2253	2253
query76	2283	1136	772	772
query77	390	404	330	330
query78	12204	12014	11668	11668
query79	1242	996	744	744
query80	593	549	453	453
query81	463	279	240	240
query82	238	155	120	120
query83	263	276	250	250
query84	281	137	110	110
query85	845	528	445	445
query86	363	342	321	321
query87	3375	3332	3243	3243
query88	3508	2642	2624	2624
query89	427	387	346	346
query90	2198	178	176	176
query91	176	173	142	142
query92	79	87	72	72
query93	1412	1506	838	838
query94	535	357	327	327
query95	689	397	439	397
query96	1043	814	312	312
query97	2681	2679	2570	2570
query98	233	229	226	226
query99	1125	1098	988	988
Total cold run time: 251149 ms
Total hot run time: 168820 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 5.26% (1/19) 🎉
Increment coverage report
Complete coverage report

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

Labels

approved Indicates a PR has been approved by one committer. dev/4.0.x dev/4.1.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants