Skip to content

[fix](view) Prevent invalid alias rewrite in view definitions#63353

Draft
starocean999 wants to merge 2 commits into
apache:masterfrom
starocean999:master_0414
Draft

[fix](view) Prevent invalid alias rewrite in view definitions#63353
starocean999 wants to merge 2 commits into
apache:masterfrom
starocean999:master_0414

Conversation

@starocean999
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Creating a view that expands a subquery alias star over an aggregate subquery could persist an invalid inline view definition. During view SQL rewrite, subquery alias output slots inherited the child slot SQL positions, so inner aggregate columns could be rewritten to self-references such as c.pack_factory. Querying the view then failed with Unknown column in AGGREGATE clause.
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

@starocean999
Copy link
Copy Markdown
Contributor Author

/review

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

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.

Requesting changes for regression-test issues. The view alias-star fix itself is small and has both FE and regression coverage, but the new regression case does not follow Doris regression-test standards and the generated result file is not whitespace-clean.

Critical checkpoint conclusions:

  • Goal/test: the stated CREATE VIEW alias-star aggregate issue is addressed by clearing inherited SQL indexes on subquery alias outputs, with a unit test and regression test.
  • Scope/focus: focused in the canonical PR diff.
  • Concurrency/lifecycle/config/compatibility: no new concurrency, lifecycle, persisted format, config, or FE-BE protocol issue found.
  • Parallel paths: no additional parallel view-rewrite path requiring the same change was found.
  • Tests: coverage was added, but the regression test should hardcode the single view name, drop before use, and preserve the view after completion; the .out also has a git diff --check whitespace error.
  • Observability/performance/transactionality: not applicable to this view rewrite; no additional issue found.
  • User focus: no additional user-provided review focus was supplied.

Comment thread regression-test/data/nereids_rules_p0/bind_relation/bind_view_alias_star_agg.out Outdated
@starocean999
Copy link
Copy Markdown
Contributor Author

/review

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 result: no new blocking issues found in the current PR diff.

Critical checkpoint conclusions:

  • Goal/test coverage: The change targets invalid create-view SQL rewriting when alias-star expansion crosses an aggregate subquery. The FE unit test and regression test cover the reported shape.
  • Scope/focus: The implementation is small and localized to LogicalSubQueryAlias output slot metadata, with focused tests.
  • Concurrency/lifecycle: No new shared mutable state, locks, threads, or lifecycle-sensitive objects are introduced.
  • Configuration/compatibility: No configs, persisted storage formats, protocol fields, or FE-BE compatibility surfaces are changed.
  • Parallel paths: The create-view rewrite path was checked around star expansion, slot binding, and PlanSlotFinder; clearing the inherited child SQL index on alias outputs is consistent with preventing alias-expanded synthetic slots from rewriting inner SQL positions while preserving explicit outer references through rebinding.
  • Conditional checks/error handling: No new error-handling paths or defensive conditionals are introduced.
  • Test result review: The current regression output is deterministic and whitespace-clean; earlier existing comments covered the previous EOF whitespace and test cleanup/naming issues.
  • Observability/performance: No new runtime path requiring logs/metrics; no meaningful performance risk identified.
  • Data correctness/transactions: The change is analyzer metadata only and does not affect transaction, version visibility, delete bitmap, or storage semantics.

User focus points: none were provided, and no additional focus-specific issues were found.

@starocean999
Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31019 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 36bb726e27308fb6b06b9b1a8159d4e785390a58, 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	17743	4077	3982	3982
q2	q3	10762	1345	806	806
q4	4684	467	345	345
q5	7764	2250	2081	2081
q6	264	183	142	142
q7	997	780	630	630
q8	9360	1741	1573	1573
q9	6725	4945	4909	4909
q10	6450	2078	1809	1809
q11	430	275	246	246
q12	694	431	298	298
q13	18150	3388	2798	2798
q14	267	254	237	237
q15	q16	823	765	705	705
q17	1016	952	987	952
q18	6857	5718	5467	5467
q19	1367	1307	1071	1071
q20	499	408	262	262
q21	5572	2551	2398	2398
q22	441	365	308	308
Total cold run time: 100865 ms
Total hot run time: 31019 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	4382	4257	4273	4257
q2	q3	4471	4928	4342	4342
q4	2092	2237	1413	1413
q5	4386	4252	4268	4252
q6	249	313	183	183
q7	1992	1813	1616	1616
q8	2521	2102	2082	2082
q9	7840	7836	7738	7738
q10	4520	4491	4092	4092
q11	772	432	403	403
q12	726	727	518	518
q13	3253	3590	3057	3057
q14	317	327	292	292
q15	q16	714	757	631	631
q17	1339	1364	1321	1321
q18	7872	7281	6970	6970
q19	1081	1067	1061	1061
q20	2226	2203	1948	1948
q21	5291	4626	4444	4444
q22	528	463	412	412
Total cold run time: 56572 ms
Total hot run time: 51032 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 168736 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 36bb726e27308fb6b06b9b1a8159d4e785390a58, data reload: false

query5	4342	662	520	520
query6	350	218	195	195
query7	4331	569	315	315
query8	329	230	218	218
query9	8821	4043	4046	4043
query10	442	342	312	312
query11	5799	2383	2236	2236
query12	186	129	122	122
query13	1265	592	411	411
query14	5948	5367	5088	5088
query14_1	4400	4375	4365	4365
query15	211	207	183	183
query16	990	485	461	461
query17	1158	744	615	615
query18	2539	499	366	366
query19	225	208	167	167
query20	141	130	130	130
query21	215	142	120	120
query22	13615	13565	13485	13485
query23	17141	16407	15822	15822
query23_1	16243	16236	16175	16175
query24	7544	1764	1292	1292
query24_1	1337	1293	1316	1293
query25	540	493	410	410
query26	1301	318	167	167
query27	2723	553	343	343
query28	4448	1933	1924	1924
query29	983	607	498	498
query30	288	236	202	202
query31	1113	1064	942	942
query32	93	76	78	76
query33	527	370	299	299
query34	1172	1124	628	628
query35	771	791	673	673
query36	1309	1330	1175	1175
query37	155	107	91	91
query38	3212	3144	3061	3061
query39	920	934	892	892
query39_1	877	881	866	866
query40	227	149	126	126
query41	66	65	63	63
query42	110	110	107	107
query43	323	327	296	296
query44	
query45	201	232	192	192
query46	1096	1215	728	728
query47	2305	2254	2204	2204
query48	393	408	291	291
query49	648	498	400	400
query50	964	347	251	251
query51	4284	4239	4186	4186
query52	103	107	95	95
query53	259	284	204	204
query54	323	268	254	254
query55	92	90	83	83
query56	301	316	306	306
query57	1406	1383	1324	1324
query58	345	269	271	269
query59	1525	1625	1403	1403
query60	328	329	328	328
query61	160	165	163	163
query62	676	636	544	544
query63	255	207	225	207
query64	2440	820	672	672
query65	
query66	1759	473	365	365
query67	29913	29953	29661	29661
query68	
query69	452	328	307	307
query70	996	985	1010	985
query71	300	273	271	271
query72	2955	2700	2425	2425
query73	863	790	430	430
query74	5071	4876	4719	4719
query75	2665	2586	2259	2259
query76	2286	1143	778	778
query77	401	410	339	339
query78	12303	12122	11645	11645
query79	1437	1024	700	700
query80	653	536	458	458
query81	469	279	242	242
query82	1380	162	120	120
query83	359	273	252	252
query84	273	143	116	116
query85	903	529	452	452
query86	399	342	331	331
query87	3405	3463	3204	3204
query88	3560	2668	2660	2660
query89	438	395	337	337
query90	1866	182	177	177
query91	180	167	142	142
query92	82	79	72	72
query93	1504	1431	836	836
query94	542	360	304	304
query95	678	379	348	348
query96	1050	745	325	325
query97	2697	2698	2564	2564
query98	238	231	226	226
query99	1126	1110	978	978
Total cold run time: 253016 ms
Total hot run time: 168736 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (2/2) 🎉
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants