Skip to content

[fix](topn) Resolve topn lazy materialization column indexes for aliases#65759

Open
hubgeter wants to merge 1 commit into
apache:masterfrom
hubgeter:fix/cir-20978-hive-lazy-materialize-alias
Open

[fix](topn) Resolve topn lazy materialization column indexes for aliases#65759
hubgeter wants to merge 1 commit into
apache:masterfrom
hubgeter:fix/cir-20978-hive-lazy-materialize-alias

Conversation

@hubgeter

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary:
Problem Summary: TopN lazy materialization resolved deferred column indexes with output slot names. Queries that renamed Hive columns therefore produced -1 indexes, and external row-id fetch could fill those columns with NULL when positional reading was used. Resolve the index from the already traced original base column so the descriptor and index share one column identity. Add a focused planner unit test and a Hive ORC Explain regression for the alias path.

Fix incorrect NULL values from aliased external-table columns when TopN lazy materialization is used.

Release note

None

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

Issue Number: None

Related PR: None

Problem Summary: TopN lazy materialization resolved deferred column indexes with output slot names. Queries that renamed Hive columns therefore produced -1 indexes, and external row-id fetch could fill those columns with NULL when positional reading was used. Resolve the index from the already traced original base column so the descriptor and index share one column identity. Add a focused planner unit test and a Hive ORC Explain regression for the alias path.

Fix incorrect NULL values from aliased external-table columns when TopN lazy materialization is used.
@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

Copy link
Copy Markdown
Contributor Author

run buildall

@hubgeter

Copy link
Copy Markdown
Contributor Author

/review

@morrySnow

Copy link
Copy Markdown
Contributor

add related pr please

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Jul 17, 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.

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

Review summary

Requesting changes for one P1 correctness issue. The single-alias physical-index fix is correct, but repeated aliases of the same lazy external column still create duplicate physical transport names and can crash the default positional Hive ORC phase-two reader. The inline comment contains the concrete trigger and fix constraints.

Key checkpoint conclusions

  • Goal and proof: Resolving the ordinal from originalColumn fixes the reported single-alias -1 index, and both added assertions fail before that change. Repeated aliases remain unhandled, so the overall alias-correctness goal is incomplete.
  • Scope and design: The one-line change is focused and correct for one physical occurrence. The phase-two representation also needs either deduplication plus output fan-out or unique transport identities; any deduplication key must retain relation and access-path identity.
  • Concurrency, lifecycle, and configuration: No new locking, lifecycle, static-initialization, or configuration behavior is introduced. The accepted issue is reachable under the existing default hive_orc_use_column_names=false.
  • Compatibility and parallel paths: There is no Thrift/protobuf shape change or new rolling-upgrade incompatibility. CatalogRelation/TVF, joins, nested access paths, partition columns, OLAP fetch, Hive name/position modes, and legacy/v2 reader routing were checked; repeated external physical names are the remaining affected boundary.
  • Tests: The JUnit assertion and Hive EXPLAIN check are valid pre-fix-failing structural coverage for one alias, but neither executes a duplicate-alias external fetch. An executed ORC/Parquet result regression is needed.
  • Persistence, writes, observability, and performance: No persistence, transaction, data-write, or observability path changes. Planning complexity remains one schema lookup per lazy slot, with no distinct material CPU, memory, or I/O regression found.
  • Final missed-case review: Alias chains, bare-plus-aliased output, identical alias text, repeated and distinct nested paths, case/schema identity, joins/self-joins, partition fields, external table formats, request/response fan-out, and OLAP row-store selection were rechecked. No distinct finding beyond the inline P1 remained.
  • User focus: No additional review focus was provided.

Validation was static only, as required by the review runner; no local build or test was run. At submission time, CheckStyle and the available lightweight checks pass, FE UT and compile are pending, and the TeamCity performance job reports failure.

outputBuilder.add(outputSlot);
lazyColumnForRel.add(originalColumn);
lazyBaseColumnIdxForRel.add(relationTable.getBaseColumnIdxByName(lazySlot.getName()));
lazyBaseColumnIdxForRel.add(relationTable.getBaseColumnIdxByName(originalColumn.getName()));

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.

[P1] Handle repeated aliases of one physical lazy column

Project(n1, n2)
  TopN(order by id)
    Project(name AS n1, name AS n2, id)
      HiveScan(id, name)

The aliases have distinct ExprIds, so this loop appends the same originalColumn twice and sends column_descs_lists = [[name, name]] with indices [[1, 1]]. Thrift derives both slot names from the physical Column. In the phase-two positional ORC reader, slot_map consequently has one name entry; the first index erases it and the second dereferences the null inserted by slot_map["name"] (be/src/format/table/hive_reader.cpp:64-83). Parquet has the same sequence at lines 252-272. Thus this valid query can crash even after the single-alias fix. Please deduplicate fetches by relation/base column/access path and fan the value out to both output locations, or preserve unique transport identities, and add an executed duplicate-alias ORC/Parquet regression.

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: This content was flagged for possible cybersecurity risk. If this seems wrong, try rephrasing your request. To get authorized for security work, join the Trusted Access for Cyber program: https://chatgpt.com/cyber
Workflow run: https://github.com/apache/doris/actions/runs/29564191911

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: 29512 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit eb21afa2aaccd7e80efae72fdf3eb63ed9032f27, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17698	4036	4018	4018
q2	1994	335	200	200
q3	10287	1434	792	792
q4	4684	471	339	339
q5	7480	854	558	558
q6	184	173	134	134
q7	781	824	597	597
q8	9345	1515	1630	1515
q9	5530	4341	4364	4341
q10	6736	1768	1475	1475
q11	510	347	332	332
q12	710	580	473	473
q13	18108	3443	2798	2798
q14	262	261	245	245
q15	q16	789	783	724	724
q17	951	980	1046	980
q18	6890	5733	5545	5545
q19	1189	1270	1061	1061
q20	812	666	578	578
q21	5902	2632	2510	2510
q22	423	345	297	297
Total cold run time: 101265 ms
Total hot run time: 29512 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4384	4295	4308	4295
q2	289	320	219	219
q3	4581	4934	4381	4381
q4	2065	2179	1367	1367
q5	4382	4234	4242	4234
q6	238	177	126	126
q7	1717	1631	1916	1631
q8	2640	2214	2227	2214
q9	7953	8233	7720	7720
q10	4687	4739	4221	4221
q11	563	408	388	388
q12	763	772	556	556
q13	3276	3623	2853	2853
q14	299	312	293	293
q15	q16	723	715	657	657
q17	1339	1336	1310	1310
q18	7988	7484	7393	7393
q19	1162	1087	1089	1087
q20	2195	2188	1944	1944
q21	5239	4498	4341	4341
q22	519	453	399	399
Total cold run time: 57002 ms
Total hot run time: 51629 ms

@hello-stephen

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

query5	4342	648	494	494
query6	453	235	209	209
query7	4849	583	351	351
query8	339	192	176	176
query9	8806	4028	4006	4006
query10	520	354	299	299
query11	5865	2291	2114	2114
query12	173	102	101	101
query13	1252	612	409	409
query14	6240	5218	4906	4906
query14_1	4262	4217	4257	4217
query15	217	212	179	179
query16	1014	496	470	470
query17	1134	724	589	589
query18	2494	481	354	354
query19	217	193	156	156
query20	116	111	108	108
query21	233	161	134	134
query22	13445	13459	13324	13324
query23	17413	16517	16056	16056
query23_1	16222	16216	16252	16216
query24	7501	1760	1304	1304
query24_1	1277	1314	1310	1310
query25	567	459	394	394
query26	1338	359	211	211
query27	2533	574	394	394
query28	4430	1993	1998	1993
query29	1065	630	497	497
query30	342	260	225	225
query31	1126	1106	984	984
query32	112	65	63	63
query33	522	322	262	262
query34	1162	1155	644	644
query35	756	794	673	673
query36	1188	1177	1051	1051
query37	154	110	139	110
query38	1872	1682	1646	1646
query39	879	879	848	848
query39_1	834	829	834	829
query40	262	162	148	148
query41	65	62	62	62
query42	93	92	90	90
query43	312	320	277	277
query44	1397	777	756	756
query45	194	180	167	167
query46	1066	1185	719	719
query47	2130	2141	2008	2008
query48	402	416	290	290
query49	580	419	301	301
query50	1070	421	335	335
query51	10849	10388	10550	10388
query52	86	86	78	78
query53	271	278	207	207
query54	285	227	206	206
query55	73	73	63	63
query56	303	298	298	298
query57	1304	1303	1213	1213
query58	298	259	248	248
query59	1517	1647	1366	1366
query60	298	277	260	260
query61	158	149	146	146
query62	531	493	431	431
query63	235	199	198	198
query64	2848	1024	859	859
query65	4759	4643	4637	4637
query66	1839	512	376	376
query67	29336	29173	28818	28818
query68	3210	1532	878	878
query69	396	297	269	269
query70	1055	947	939	939
query71	420	345	316	316
query72	3053	2683	2378	2378
query73	808	754	414	414
query74	5052	4896	4737	4737
query75	2533	2489	2123	2123
query76	2353	1151	777	777
query77	343	376	264	264
query78	11910	11893	11350	11350
query79	1405	1152	741	741
query80	1316	545	485	485
query81	494	329	289	289
query82	572	153	118	118
query83	376	326	300	300
query84	276	164	126	126
query85	951	593	511	511
query86	410	289	280	280
query87	1826	1847	1733	1733
query88	3707	2761	2739	2739
query89	426	369	331	331
query90	2005	200	190	190
query91	199	189	160	160
query92	61	61	53	53
query93	1600	1540	982	982
query94	696	344	326	326
query95	800	537	465	465
query96	1069	791	364	364
query97	2626	2628	2489	2489
query98	219	202	194	194
query99	1080	1093	967	967
Total cold run time: 263395 ms
Total hot run time: 176582 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.08	0.05	0.04
query3	0.25	0.13	0.14
query4	1.60	0.14	0.18
query5	0.23	0.22	0.22
query6	1.24	1.22	1.01
query7	0.04	0.01	0.00
query8	0.06	0.04	0.03
query9	0.38	0.30	0.31
query10	0.54	0.55	0.53
query11	0.19	0.14	0.14
query12	0.17	0.13	0.14
query13	0.47	0.46	0.48
query14	1.03	1.01	1.00
query15	0.62	0.61	0.59
query16	0.31	0.32	0.34
query17	1.06	1.09	1.10
query18	0.22	0.21	0.21
query19	2.05	1.94	1.94
query20	0.02	0.01	0.01
query21	15.44	0.21	0.14
query22	4.90	0.05	0.05
query23	16.15	0.30	0.12
query24	2.92	0.40	0.31
query25	0.12	0.04	0.04
query26	0.71	0.21	0.14
query27	0.04	0.03	0.04
query28	3.53	0.94	0.56
query29	12.49	4.04	3.26
query30	0.27	0.16	0.15
query31	2.77	0.60	0.31
query32	3.24	0.58	0.48
query33	3.24	3.17	3.21
query34	15.54	4.24	3.52
query35	3.56	3.46	3.50
query36	0.55	0.43	0.41
query37	0.09	0.07	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.16	0.15
query41	0.08	0.03	0.03
query42	0.04	0.02	0.03
query43	0.04	0.03	0.04
Total cold run time: 96.56 s
Total hot run time: 24.8 s

@Gabriel39

Copy link
Copy Markdown
Contributor

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

Review summary

No new non-duplicate inline findings were identified on head eb21afa2aaccd7e80efae72fdf3eb63ed9032f27. The existing unresolved P1 repeated-alias thread remains the sole blocking issue: the single-alias ordinal fix is correct, but repeated lazy outputs for one physical external column still create duplicate transport identities and can fail in the active legacy positional reader. This review is comment-only to avoid duplicating that landed inline issue.

Key checkpoint conclusions

  • Goal and proof: Resolving the ordinal from originalColumn fixes the reported single-alias -1 index. The JUnit assertion and Hive EXPLAIN assertion both fail before the change and pass afterward while proving that lazy materialization is present. The broader alias-correctness goal remains incomplete only because of the existing repeated-alias P1.
  • Scope and design: The one-line production change is small, clear, and correct for a single physical occurrence. The remaining case needs deduplication plus output fan-out, or unique transport identities, keyed with relation/base-column/access-path identity as described in the existing thread.
  • Concurrency, lifecycle, static initialization, and configuration: No new locking, shared mutable state, thread entry, object-lifecycle, static-initialization, or configuration behavior is introduced. Existing request metadata is immutable during concurrent RPC/scanner work.
  • Compatibility and parallel paths: No Thrift/protobuf shape, persisted metadata, storage format, or rolling-upgrade contract changes. Catalog and TVF relations, alias chains, joins/self-joins, nested access paths, partition columns, OLAP column/row-store selection, Hive name/position modes, and legacy/v2 reader routing were checked. Duplicate original IDs disable OLAP row-store and safely fall back to distinct-slot column fetch; the remaining live failure is the already-reported legacy external duplicate-identity path.
  • Conditions, errors, and FE-BE transport: The physical Column traced from the same relation is the correct schema key, and getBaseColumnIdxByName resolves it case-insensitively. Descriptor/index/location list cardinality and ordering remain aligned. No new silent error path or unchecked status was introduced.
  • Tests and results: The added tests are valid structural coverage for one alias, but the Hive addition is EXPLAIN-only and does not execute a duplicate-alias ORC/Parquet fetch; that missing runtime case is already requested by the P1. Current CI shows FE UT, External Regression, Compile, CheckStyle, P0, and performance passing; check_coverage_fe is failing. Local validation was static-only, as required by the review runner.
  • Persistence, transactions, writes, observability, and performance: No persistence, EditLog, transaction, data-write, or new observability path is involved. The lookup remains the pre-existing linear schema scan per lazy slot, with no distinct CPU, memory, or I/O regression found.
  • Final convergence: Two normal full-review slices and one separate risk-focused scan all returned NO_NEW_VALUABLE_FINDINGS against the same ledger, existing thread set, and unchanged head. The main final changed-file and unresolved-candidate sweep found no remaining non-duplicate candidate.
  • User focus: No additional user-provided review focus was specified.

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.1.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants