Skip to content

[fix](statistics) Use one algorithm decision to pick both params and template in sample analyze - #66578

Open
yujun777 wants to merge 2 commits into
apache:masterfrom
yujun777:fix-duj1-template-param-mismatch
Open

[fix](statistics) Use one algorithm decision to pick both params and template in sample analyze#66578
yujun777 wants to merge 2 commits into
apache:masterfrom
yujun777:fix-duj1-template-param-mismatch

Conversation

@yujun777

@yujun777 yujun777 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Fix sample analyze generating invalid SQL when the DUJ1 template is forced on a small table.

doSample() previously filled SQL params and selected the SQL template through two independent decisions: getSampleParams() decided based on tableRowCount/scanFullTable (filling LINEAR-style params that reference the raw column name), while the template was picked separately via useLinearAnalyzeTemplate(). When useDUJ1Template was forced, the DUJ1 template was chosen but the params were still filled by the FULL-scan branch with ${colName} references. The DUJ1 template's cte1 only exposes col_value/count/column_length, so the generated SQL failed to bind, e.g. Unknown column 'id' in 'table list' in PROJECT clause, which made test_analyze_long_string flaky.

This PR makes the algorithm a single decision: getSampleCollectInfo() decides AnalyzeSampleAlgorithm { FULL, LINEAR, DUJ1 } once, and both param filling and template selection derive from the same algorithm, so params always match the template.

Key changes

  • Add AnalyzeSampleAlgorithm enum (FULL/LINEAR/DUJ1) in BaseAnalysisTask.
  • Rename getAnalyzeAlgorithm to getSampleCollectInfo: decide the algorithm once and return it together with the picked sample tablets.
  • Fill params (getSampleParams/setSampleParamsByAlgorithm) and pick the SQL template (doSample) from the same algorithm decision.
  • Remove the scanFullTable field, its setter/getter, and all related checks.

Unit test

  • Updated OlapAnalysisTaskTest to cover FULL/LINEAR/DUJ1 param filling, template selection driven by the algorithm, and the sample-tablets-not-enough fallback.

…template in sample analyze

Sample analyze used two independent decisions when building the SQL: getSampleParams
filled params based on tableRowCount/scanFullTable, while doSample picked the template
via useLinearAnalyzeTemplate(). When a debug point forced the DUJ1 template on a small
table, the FULL-scan branch still filled LINEAR-style params that referenced the raw
column name, which does not exist in the DUJ1 template's cte1, causing the analyze task
to fail with "Unknown column 'id' in 'table list' in PROJECT clause".

Key changes:
- Add AnalyzeSampleAlgorithm enum (FULL/LINEAR/DUJ1) in BaseAnalysisTask.
- Rename getAnalyzeAlgorithm to getSampleCollectInfo: decide the algorithm once and
  return it together with the picked sample tablets.
- Fill params (getSampleParams/setSampleParamsByAlgorithm) and pick the SQL template
  (doSample) from the same algorithm decision, so params always match the template.
- Remove the scanFullTable field, its setter/getter, and all related checks.

Unit Test:
- Updated OlapAnalysisTaskTest to cover FULL/LINEAR/DUJ1 param filling, template
  selection driven by the algorithm, and the sample-tablets-not-enough fallback.
@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?

@yujun777

yujun777 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17646	4004	4071	4004
q2	2063	323	205	205
q3	10327	1377	772	772
q4	4691	472	342	342
q5	7576	831	539	539
q6	170	162	139	139
q7	742	788	588	588
q8	9409	1538	1679	1538
q9	5686	4075	4037	4037
q10	6731	1629	1336	1336
q11	512	373	329	329
q12	728	563	449	449
q13	18124	3277	2703	2703
q14	266	262	243	243
q15	q16	726	726	655	655
q17	965	1031	959	959
q18	6682	5589	5560	5560
q19	1165	1229	1080	1080
q20	813	666	549	549
q21	5782	2759	2516	2516
q22	448	366	311	311
Total cold run time: 101252 ms
Total hot run time: 28854 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4794	4615	4677	4615
q2	314	330	216	216
q3	5066	5215	4624	4624
q4	2193	2267	1429	1429
q5	4840	4527	4484	4484
q6	229	173	128	128
q7	1767	1764	1552	1552
q8	2308	1977	1882	1882
q9	6746	6647	6649	6647
q10	4241	4152	3782	3782
q11	502	369	339	339
q12	691	702	487	487
q13	3003	3196	2674	2674
q14	277	286	251	251
q15	q16	666	681	597	597
q17	1245	1218	1222	1218
q18	12128	11065	11813	11065
q19	1057	1079	1094	1079
q20	2195	2203	1899	1899
q21	5212	4449	4552	4449
q22	521	463	422	422
Total cold run time: 59995 ms
Total hot run time: 53839 ms

@hello-stephen

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

query5	4295	582	467	467
query6	477	216	206	206
query7	4832	603	325	325
query8	321	168	151	151
query9	8758	4033	4054	4033
query10	477	346	284	284
query11	5792	2196	1993	1993
query12	149	99	94	94
query13	1276	613	440	440
query14	6073	4296	3991	3991
query14_1	3828	3796	3800	3796
query15	206	205	180	180
query16	1043	483	465	465
query17	1085	693	544	544
query18	2439	480	340	340
query19	205	194	138	138
query20	102	99	103	99
query21	230	158	137	137
query22	13037	12962	12812	12812
query23	15729	15074	14587	14587
query23_1	14691	14667	14828	14667
query24	7507	1663	1227	1227
query24_1	1214	1217	1214	1214
query25	516	410	354	354
query26	1315	353	212	212
query27	2632	584	385	385
query28	4557	2027	2014	2014
query29	1104	600	497	497
query30	352	261	227	227
query31	1178	1124	1046	1046
query32	113	61	59	59
query33	517	295	236	236
query34	1213	1132	644	644
query35	718	750	637	637
query36	768	778	730	730
query37	152	108	98	98
query38	1840	1763	1667	1667
query39	827	828	800	800
query39_1	782	785	781	781
query40	260	156	141	141
query41	63	62	64	62
query42	97	93	93	93
query43	320	324	277	277
query44	1427	766	791	766
query45	185	176	174	174
query46	1096	1186	739	739
query47	1523	1531	1427	1427
query48	420	414	319	319
query49	592	414	300	300
query50	1093	473	350	350
query51	10161	10214	10666	10214
query52	89	89	72	72
query53	264	261	198	198
query54	275	225	215	215
query55	73	70	71	70
query56	305	299	290	290
query57	1013	998	933	933
query58	284	265	282	265
query59	1531	1621	1390	1390
query60	299	300	251	251
query61	167	169	175	169
query62	438	325	276	276
query63	239	198	197	197
query64	3005	1142	965	965
query65	3881	3814	3808	3808
query66	1859	498	374	374
query67	20063	20040	19909	19909
query68	3235	1504	1026	1026
query69	426	303	267	267
query70	890	794	782	782
query71	391	327	324	324
query72	3154	2710	2276	2276
query73	858	747	420	420
query74	4642	4516	4331	4331
query75	2358	2349	2011	2011
query76	2343	1157	785	785
query77	331	364	268	268
query78	11241	11136	10534	10534
query79	1366	1127	775	775
query80	1281	540	476	476
query81	527	336	284	284
query82	729	175	132	132
query83	367	327	306	306
query84	287	167	134	134
query85	1043	596	512	512
query86	495	232	220	220
query87	1937	1954	1840	1840
query88	3669	2765	2776	2765
query89	409	317	286	286
query90	1903	212	198	198
query91	204	194	165	165
query92	65	59	54	54
query93	1635	1528	951	951
query94	848	339	304	304
query95	774	588	474	474
query96	1076	742	353	353
query97	2446	2438	2329	2329
query98	198	190	193	190
query99	765	742	636	636
Total cold run time: 245311 ms
Total hot run time: 157825 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.10	0.05	0.05
query3	0.25	0.14	0.13
query4	1.61	0.13	0.14
query5	0.24	0.22	0.22
query6	1.16	0.81	0.78
query7	0.06	0.01	0.01
query8	0.06	0.04	0.04
query9	0.38	0.31	0.31
query10	0.56	0.54	0.57
query11	0.20	0.13	0.14
query12	0.18	0.14	0.13
query13	0.47	0.46	0.46
query14	1.00	0.98	0.97
query15	0.60	0.58	0.59
query16	0.32	0.33	0.33
query17	1.04	1.07	1.11
query18	0.21	0.20	0.20
query19	1.98	1.91	1.95
query20	0.01	0.01	0.02
query21	15.57	0.21	0.13
query22	4.76	0.05	0.05
query23	16.13	0.30	0.12
query24	3.00	0.43	0.34
query25	0.12	0.06	0.03
query26	0.77	0.20	0.16
query27	0.05	0.03	0.03
query28	3.50	0.75	0.31
query29	12.49	4.04	3.15
query30	0.28	0.15	0.15
query31	2.77	0.55	0.32
query32	3.22	0.58	0.49
query33	3.15	3.15	3.16
query34	15.56	3.89	3.31
query35	3.21	3.21	3.22
query36	0.58	0.42	0.43
query37	0.10	0.07	0.06
query38	0.05	0.03	0.03
query39	0.04	0.03	0.03
query40	0.17	0.16	0.15
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 96.12 s
Total hot run time: 23.74 s

…nt FULL fallback

The useDUJ1Template debug point only affected template selection inside
useLinearAnalyzeTemplate. When a small table's row count was not fully
reported to FE yet (tableRowCount <= targetSampleRows), getSampleCollectInfo
returned FULL before reaching that check, so the test's forced DUJ1 path was
skipped and params were filled with LINEAR style while the DUJ1 template was
used, causing "Unknown column" failures. The regression test was flaky because
it depended on BE row count report timing.

Key changes:
- In getSampleCollectInfo, check the useDUJ1Template debug point before the
  row-count based FULL decision and force the DUJ1 algorithm.

Unit Test:
- Extended OlapAnalysisTaskTest.testGetSampleCollectInfo to assert the debug
  point forces DUJ1 even when row count would fall back to a full table scan.
@yujun777

yujun777 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17698	4151	4003	4003
q2	2110	334	205	205
q3	10168	1411	785	785
q4	4684	474	345	345
q5	7537	822	541	541
q6	187	179	141	141
q7	742	793	596	596
q8	9357	1511	1508	1508
q9	5292	4096	4078	4078
q10	6726	1624	1331	1331
q11	499	354	324	324
q12	752	563	464	464
q13	18110	3276	2766	2766
q14	266	260	237	237
q15	q16	741	726	656	656
q17	1034	1014	1094	1014
q18	6538	5618	5616	5616
q19	1312	1124	1071	1071
q20	835	680	573	573
q21	5968	2566	2342	2342
q22	444	364	312	312
Total cold run time: 101000 ms
Total hot run time: 28908 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4443	4342	4322	4322
q2	305	313	220	220
q3	4556	5002	4379	4379
q4	2175	2269	1410	1410
q5	4250	4146	4231	4146
q6	234	175	132	132
q7	1675	1614	1523	1523
q8	2291	1910	1903	1903
q9	6769	6778	6789	6778
q10	4440	4209	3840	3840
q11	549	389	355	355
q12	714	739	518	518
q13	2980	3272	2784	2784
q14	285	297	254	254
q15	q16	670	702	626	626
q17	1258	1245	1232	1232
q18	12108	11064	11864	11064
q19	1095	1097	1081	1081
q20	2230	2211	1895	1895
q21	5312	4609	4555	4555
q22	538	456	413	413
Total cold run time: 58877 ms
Total hot run time: 53430 ms

@hello-stephen

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

query5	4318	583	451	451
query6	467	228	222	222
query7	4901	604	359	359
query8	331	162	145	145
query9	8786	4100	4044	4044
query10	462	362	317	317
query11	5833	2210	2029	2029
query12	152	104	98	98
query13	1265	606	454	454
query14	6110	4282	4038	4038
query14_1	3864	3821	3882	3821
query15	205	199	176	176
query16	1016	475	485	475
query17	969	723	567	567
query18	2446	481	350	350
query19	237	198	159	159
query20	109	106	103	103
query21	246	161	139	139
query22	13038	12973	12782	12782
query23	15918	14979	14514	14514
query23_1	14806	14613	14544	14544
query24	7415	1726	1242	1242
query24_1	1277	1277	1264	1264
query25	567	454	388	388
query26	1328	366	208	208
query27	2586	574	385	385
query28	4575	2071	2050	2050
query29	1111	646	508	508
query30	342	263	230	230
query31	1171	1122	1048	1048
query32	105	65	65	65
query33	552	336	254	254
query34	1226	1212	641	641
query35	752	760	650	650
query36	778	770	675	675
query37	159	130	104	104
query38	1830	1785	1683	1683
query39	825	825	807	807
query39_1	782	797	787	787
query40	254	170	146	146
query41	72	70	70	70
query42	98	96	95	95
query43	331	332	293	293
query44	1432	781	768	768
query45	190	181	181	181
query46	1049	1141	740	740
query47	1549	1541	1449	1449
query48	410	419	276	276
query49	581	442	303	303
query50	1160	421	343	343
query51	10688	10875	10710	10710
query52	88	94	76	76
query53	271	277	196	196
query54	289	235	224	224
query55	74	71	73	71
query56	289	285	298	285
query57	1019	994	904	904
query58	296	264	264	264
query59	1554	1651	1377	1377
query60	300	267	253	253
query61	160	148	158	148
query62	473	320	271	271
query63	236	204	202	202
query64	2856	1077	869	869
query65	3869	3833	3864	3833
query66	1837	487	354	354
query67	20436	20074	19863	19863
query68	3531	1634	983	983
query69	448	308	267	267
query70	872	843	808	808
query71	377	334	314	314
query72	3140	2658	2343	2343
query73	844	751	440	440
query74	4643	4506	4295	4295
query75	2361	2313	2022	2022
query76	2412	1186	766	766
query77	366	391	285	285
query78	11154	11185	10467	10467
query79	1235	1233	769	769
query80	677	547	460	460
query81	482	323	286	286
query82	637	181	135	135
query83	405	340	299	299
query84	337	162	130	130
query85	950	619	525	525
query86	361	234	212	212
query87	1992	1966	1811	1811
query88	3716	2811	2783	2783
query89	385	318	288	288
query90	1890	201	203	201
query91	204	189	165	165
query92	64	64	59	59
query93	1601	1525	1000	1000
query94	545	352	326	326
query95	775	524	455	455
query96	1084	803	385	385
query97	2445	2481	2370	2370
query98	200	186	183	183
query99	734	745	603	603
Total cold run time: 245877 ms
Total hot run time: 158520 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.05	0.05
query3	0.25	0.13	0.13
query4	1.61	0.15	0.14
query5	0.25	0.23	0.23
query6	1.16	0.83	0.80
query7	0.04	0.01	0.01
query8	0.06	0.03	0.04
query9	0.39	0.31	0.32
query10	0.56	0.58	0.55
query11	0.19	0.13	0.13
query12	0.18	0.14	0.14
query13	0.47	0.47	0.48
query14	1.00	0.98	0.99
query15	0.65	0.61	0.61
query16	0.32	0.34	0.32
query17	1.10	1.12	1.12
query18	0.21	0.20	0.19
query19	2.05	1.95	1.91
query20	0.01	0.01	0.02
query21	15.44	0.19	0.14
query22	4.92	0.05	0.06
query23	16.11	0.31	0.12
query24	3.01	0.41	0.35
query25	0.12	0.06	0.05
query26	0.74	0.20	0.15
query27	0.03	0.04	0.04
query28	3.53	0.77	0.37
query29	12.51	3.99	3.17
query30	0.28	0.14	0.15
query31	2.77	0.57	0.31
query32	3.22	0.61	0.48
query33	3.15	3.18	3.15
query34	15.64	3.92	3.28
query35	3.25	3.21	3.24
query36	0.56	0.43	0.44
query37	0.08	0.06	0.06
query38	0.05	0.04	0.03
query39	0.04	0.04	0.03
query40	0.18	0.16	0.15
query41	0.10	0.03	0.03
query42	0.04	0.02	0.03
query43	0.04	0.03	0.03
Total cold run time: 96.42 s
Total hot run time: 23.92 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 38.79% (45/116) 🎉
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