Skip to content

# [fix](topn lazy materialization) Disable topn lazy materialization on non-light-schema-change tables#65415

Open
liutang123 wants to merge 1 commit into
apache:masterfrom
liutang123:fix-topn-lazy-non-lsc-table
Open

# [fix](topn lazy materialization) Disable topn lazy materialization on non-light-schema-change tables#65415
liutang123 wants to merge 1 commit into
apache:masterfrom
liutang123:fix-topn-lazy-non-lsc-table

Conversation

@liutang123

@liutang123 liutang123 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

A top-N query that emits a non-order-by column fails on a non-light-schema-change OLAP table (a table created/upgraded with light_schema_change = false, where every column's uniqueId is -1):

select id, name from tbl order by createdate desc limit 10;
ERROR 1105 (HY000): errCode = 2, detailMessage =
[INTERNAL_ERROR]field name is invalid. field=__DORIS_GLOBAL_ROWID_COL__tbl,
field_name_to_index=[...], col_unique_id=2147483647

Fix: disable topn lazy materialization for non-light-schema-change OLAP tables in MaterializeProbeVisitor and fall back to normal topn (the working two-phase read path). A new helper supportOlapTopnLazyMaterialize() consolidates the existing AGG_KEYS exclusion with the new light_schema_change requirement, applied at visitPhysicalOlapScan, visitPhysicalCatalogRelation and visitPhysicalFilter.

Add regression test topn_lazy_light_schema_change verifying:

  • light_schema_change=false: no lazy materialization in the plan, correct results.
  • light_schema_change=true: lazy materialization still applies, correct results.

Behavior after the fix

Table Plan Result
light_schema_change = false plain PhysicalOlapScan (no lazy) → safe two-phase read correct values
light_schema_change = true PhysicalLazyMaterialize / PhysicalLazyMaterializeOlapScan (unchanged) correct values

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

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

… non-light-schema-change tables

TopN lazy materialization appends a synthetic global row-id column
(__DORIS_GLOBAL_ROWID_COL__<table>) to the OLAP scan. The BE only rebuilds the
tablet schema from FE's columns_desc when columns_desc[0].col_unique_id >= 0,
which only holds for light_schema_change tables. On a non-light-schema-change
table every column's uniqueId is -1, so the synthetic row-id column never enters
the BE tablet schema and the scan fails with:

  field name is invalid. field=__DORIS_GLOBAL_ROWID_COL__<table>

(forcing the column into the scan schema instead makes the second-phase fetch
silently return NULL for the lazily-materialized columns, which is worse).

Fix: disable topn lazy materialization for non-light-schema-change OLAP tables in
MaterializeProbeVisitor and fall back to normal topn (the working two-phase read
path). A new helper supportOlapTopnLazyMaterialize() consolidates the existing
AGG_KEYS exclusion with the new light_schema_change requirement, applied at
visitPhysicalOlapScan, visitPhysicalCatalogRelation and visitPhysicalFilter.

Add regression test topn_lazy_light_schema_change verifying:
- light_schema_change=false: no lazy materialization in the plan, correct results.
- light_schema_change=true: lazy materialization still applies, correct results.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@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?

@liutang123

Copy link
Copy Markdown
Contributor Author

run buildall

@liutang123

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 PR 65415 for TopN lazy materialization gating on non-light-schema-change OLAP tables.

Critical checkpoint conclusions:

  • Goal and coverage: The PR disables OLAP TopN lazy materialization before source selection when the table is AGG_KEYS or has light_schema_change=false, and adds a regression covering explicit false and true table properties.
  • Scope: The change is small and focused on MaterializeProbeVisitor support checks plus one targeted regression suite.
  • Concurrency/lifecycle: No new concurrency, locks, async lifecycle, static initialization, persistence, or transaction paths are introduced.
  • Config/session compatibility: No new config is added. Existing topn_lazy_materialization_threshold and topn_lazy_materialization_using_index paths remain unchanged; the new table-property gate is applied in the normal scan, catalog-relation, and using-index filter probe paths.
  • Parallel paths: The relevant OLAP probe entry points are covered; non-OLAP lazy materialization paths are unchanged.
  • Test coverage: The regression checks both plan shape and query result for light_schema_change=false fallback and light_schema_change=true lazy behavior. I did not run the regression locally in this shallow Actions checkout because thirdparty/installed and thirdparty/installed/bin/protoc are missing; GitHub CI currently has style/license checks passing, with compile/FE UT/performance still pending.
  • User focus: No additional user-provided focus points were supplied.

Subagent conclusions: optimizer-rewrite reported NO_NEW_VALUABLE_FINDINGS; tests-session-config reported NO_NEW_VALUABLE_FINDINGS. No subagent candidate became an inline comment, and none were dismissed or merged as duplicates. Final convergence round 1 ended with both live subagents reporting NO_NEW_VALUABLE_FINDINGS for the same empty inline-comment set and this comment-only review body.

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 6.85% (5/73) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17723	4077	4026	4026
q2	2040	328	198	198
q3	10293	1398	840	840
q4	4676	471	341	341
q5	7481	859	576	576
q6	187	181	137	137
q7	777	856	618	618
q8	9326	1625	1565	1565
q9	5584	4388	4397	4388
q10	6775	1803	1544	1544
q11	510	344	310	310
q12	702	554	436	436
q13	18142	3457	2818	2818
q14	270	266	231	231
q15	q16	795	774	703	703
q17	1011	997	1014	997
q18	6807	5794	5499	5499
q19	1419	1290	1086	1086
q20	768	704	516	516
q21	5902	2701	2478	2478
q22	434	369	304	304
Total cold run time: 101622 ms
Total hot run time: 29611 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4341	4298	4269	4269
q2	293	323	218	218
q3	4539	5011	4399	4399
q4	2070	2165	1359	1359
q5	4464	4308	4317	4308
q6	230	180	132	132
q7	1725	1988	1871	1871
q8	2610	2246	2202	2202
q9	8157	8213	7847	7847
q10	4709	4715	4287	4287
q11	561	432	420	420
q12	745	783	577	577
q13	3259	3616	2948	2948
q14	315	298	272	272
q15	q16	741	742	645	645
q17	1371	1310	1334	1310
q18	8030	7576	7358	7358
q19	1144	1113	1070	1070
q20	2196	2199	1953	1953
q21	5217	4557	4441	4441
q22	535	469	404	404
Total cold run time: 57252 ms
Total hot run time: 52290 ms

@hello-stephen

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

query5	4308	641	495	495
query6	459	231	226	226
query7	4853	606	363	363
query8	333	186	173	173
query9	8786	4093	4074	4074
query10	451	366	306	306
query11	5943	2341	2202	2202
query12	168	102	100	100
query13	1250	621	429	429
query14	6235	5373	5075	5075
query14_1	4363	4443	4341	4341
query15	212	219	197	197
query16	1037	501	423	423
query17	927	705	573	573
query18	2433	464	358	358
query19	205	191	145	145
query20	113	107	100	100
query21	245	163	133	133
query22	13675	13664	13532	13532
query23	17403	16613	16239	16239
query23_1	16335	16230	16240	16230
query24	7593	1796	1279	1279
query24_1	1305	1305	1287	1287
query25	540	442	361	361
query26	1341	352	209	209
query27	2614	576	373	373
query28	4468	2019	1986	1986
query29	1087	612	483	483
query30	340	260	216	216
query31	1112	1090	987	987
query32	115	64	65	64
query33	534	329	257	257
query34	1189	1136	662	662
query35	777	794	677	677
query36	1383	1356	1238	1238
query37	158	115	97	97
query38	1890	1700	1657	1657
query39	931	930	906	906
query39_1	893	881	891	881
query40	245	162	148	148
query41	72	70	70	70
query42	96	95	95	95
query43	333	348	288	288
query44	1438	786	786	786
query45	212	189	181	181
query46	1080	1208	745	745
query47	2319	2281	2154	2154
query48	434	441	315	315
query49	599	436	340	340
query50	1055	432	336	336
query51	10686	11083	10687	10687
query52	90	90	83	83
query53	274	303	204	204
query54	310	245	228	228
query55	76	74	70	70
query56	323	308	323	308
query57	1397	1376	1310	1310
query58	297	284	267	267
query59	1592	1705	1486	1486
query60	313	276	258	258
query61	182	172	175	172
query62	696	648	593	593
query63	252	211	213	211
query64	2976	1056	834	834
query65	4944	4813	4794	4794
query66	1855	497	378	378
query67	29540	29599	29355	29355
query68	3165	1475	945	945
query69	398	302	277	277
query70	1112	989	991	989
query71	354	319	292	292
query72	3020	2767	2394	2394
query73	806	764	437	437
query74	5136	4987	4760	4760
query75	2610	2606	2208	2208
query76	2327	1204	779	779
query77	356	387	293	293
query78	12589	12530	11807	11807
query79	1449	1176	767	767
query80	654	551	459	459
query81	465	325	281	281
query82	586	169	126	126
query83	398	324	296	296
query84	331	159	126	126
query85	914	594	520	520
query86	359	298	288	288
query87	1833	1827	1749	1749
query88	3745	2841	2785	2785
query89	452	408	351	351
query90	1940	213	203	203
query91	208	199	167	167
query92	61	60	58	58
query93	1530	1529	1011	1011
query94	552	348	337	337
query95	794	557	460	460
query96	1073	780	360	360
query97	2662	2681	2540	2540
query98	229	209	203	203
query99	1155	1175	1016	1016
Total cold run time: 265263 ms
Total hot run time: 181189 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.04	0.06
query3	0.26	0.14	0.14
query4	1.63	0.14	0.14
query5	0.24	0.22	0.22
query6	1.25	1.04	1.06
query7	0.04	0.01	0.00
query8	0.06	0.03	0.04
query9	0.38	0.31	0.33
query10	0.54	0.56	0.58
query11	0.20	0.15	0.14
query12	0.18	0.14	0.14
query13	0.46	0.48	0.48
query14	1.02	1.04	1.00
query15	0.62	0.58	0.60
query16	0.32	0.32	0.32
query17	1.08	1.12	1.09
query18	0.23	0.21	0.21
query19	2.06	1.99	1.98
query20	0.02	0.01	0.01
query21	15.47	0.22	0.14
query22	4.92	0.05	0.06
query23	16.14	0.31	0.11
query24	2.97	0.44	0.36
query25	0.12	0.05	0.04
query26	0.73	0.21	0.16
query27	0.05	0.04	0.04
query28	3.56	0.94	0.53
query29	12.48	4.10	3.25
query30	0.27	0.16	0.15
query31	2.77	0.63	0.32
query32	3.23	0.59	0.48
query33	3.22	3.27	3.18
query34	15.44	4.23	3.53
query35	3.57	3.54	3.53
query36	0.56	0.43	0.42
query37	0.09	0.07	0.06
query38	0.05	0.04	0.04
query39	0.03	0.03	0.03
query40	0.17	0.17	0.15
query41	0.08	0.03	0.03
query42	0.04	0.02	0.02
query43	0.05	0.04	0.04
Total cold run time: 96.71 s
Total hot run time: 25.09 s

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.

2 participants