Skip to content

[opt](config) add max_bucket_num_per_partition config to limit bucket number#61576

Merged
hello-stephen merged 4 commits intoapache:masterfrom
gavinchou:gavin-limit-max-num-bucket
Mar 25, 2026
Merged

[opt](config) add max_bucket_num_per_partition config to limit bucket number#61576
hello-stephen merged 4 commits intoapache:masterfrom
gavinchou:gavin-limit-max-num-bucket

Conversation

@gavinchou
Copy link
Contributor

Proposed changes

Add a new FE config max_bucket_num_per_partition to limit the maximum number of buckets when creating a table or adding a partition.

Changes:

  1. Add max_bucket_num_per_partition config in Config.java, defaulting to autobucket_max_buckets (128) for consistency.
  2. Add bucket number validation in DistributionDescriptor.validate() for CREATE TABLE scenario.
  3. Add bucket number validation in InternalCatalog.addPartition() for ALTER TABLE ADD PARTITION scenario.
  4. Add unit tests for the new validation logic.

Behavior:

  • For user-specified buckets (CREATE TABLE / ALTER TABLE ADD PARTITION): if bucket number exceeds this limit, the operation will be rejected with a helpful error message.
  • For auto-bucket feature (Dynamic Partition): bucket number is capped by autobucket_max_buckets automatically, no change.
  • Set to 0 or negative value to disable this limit.

Error message example:

Number of buckets (200) exceeds the maximum allowed value (128). 
Generally, a large number of buckets is not needed. 
If you have a specific use case requiring more buckets, 
please review your schema design or modify the FE config 
'max_bucket_num_per_partition' to adjust this limit.

Test plan

  • Unit tests added in DistributionDescriptorTest.java
  • Verify CREATE TABLE with bucket number exceeding limit is rejected
  • Verify ALTER TABLE ADD PARTITION with bucket number exceeding limit is rejected
  • Verify auto-bucket is not affected by this limit
  • Verify setting config to 0 disables the limit

@Thearas
Copy link
Contributor

Thearas commented Mar 20, 2026

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?

@gavinchou gavinchou changed the title [feat](config) add max_bucket_num_per_partition config to limit bucket number [opt](config) add max_bucket_num_per_partition config to limit bucket number Mar 20, 2026
@gavinchou
Copy link
Contributor Author

run buildall

…t number

Add a new FE config `max_bucket_num_per_partition` to limit the maximum
number of buckets when creating a table or adding a partition.

Changes:
1. Add `max_bucket_num_per_partition` config in Config.java, defaulting
   to `autobucket_max_buckets` (128) for consistency.
2. Add bucket number validation in DistributionDescriptor.validate() for
   CREATE TABLE scenario.
3. Add bucket number validation in InternalCatalog.addPartition() for
   ALTER TABLE ADD PARTITION scenario.
4. Add unit tests for the new validation logic.

Behavior:
- For user-specified buckets (CREATE TABLE / ALTER TABLE ADD PARTITION):
  if bucket number exceeds this limit, the operation will be rejected.
- For auto-bucket feature (Dynamic Partition): bucket number is capped
  by autobucket_max_buckets automatically.
- Set to 0 or negative value to disable this limit.
@gavinchou gavinchou force-pushed the gavin-limit-max-num-bucket branch from 673630a to aba8238 Compare March 20, 2026 10:42
@gavinchou
Copy link
Contributor Author

run compile

Add DistributionDescriptorTest to test the bucket number limit functionality:
- Test normal bucket number within limit
- Test bucket number exceeds limit throws AnalysisException
- Test disable limit by setting to 0
- Test auto bucket is not limited by this config
- Test random distribution also respects limit
- Test bucket number zero or negative validation
@gavinchou
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 26974 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 2b1855f2ce3d5f462d2253a3a8c60b1cebd4cdd9, 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	17679	4423	4304	4304
q2	q3	10646	779	524	524
q4	4670	359	247	247
q5	7679	1249	1046	1046
q6	178	177	151	151
q7	786	880	680	680
q8	10116	1516	1309	1309
q9	5287	4709	4717	4709
q10	6328	1955	1657	1657
q11	483	252	251	251
q12	764	587	465	465
q13	18049	2942	2207	2207
q14	233	236	209	209
q15	q16	728	748	662	662
q17	754	866	460	460
q18	6068	5436	5194	5194
q19	1487	987	622	622
q20	540	481	371	371
q21	4530	1992	1627	1627
q22	385	360	279	279
Total cold run time: 97390 ms
Total hot run time: 26974 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	4794	4525	4635	4525
q2	q3	3920	4360	3816	3816
q4	881	1213	772	772
q5	4109	4481	4422	4422
q6	198	182	149	149
q7	1822	1636	1547	1547
q8	2520	2762	2607	2607
q9	7665	7421	7275	7275
q10	3764	4061	3662	3662
q11	504	435	415	415
q12	505	606	451	451
q13	2919	3124	2318	2318
q14	338	311	288	288
q15	q16	713	750	738	738
q17	1221	1422	1394	1394
q18	7283	6811	6620	6620
q19	1100	983	948	948
q20	2091	2186	1983	1983
q21	3969	3527	3336	3336
q22	478	415	374	374
Total cold run time: 50794 ms
Total hot run time: 47640 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 168322 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 2b1855f2ce3d5f462d2253a3a8c60b1cebd4cdd9, data reload: false

query5	4329	633	499	499
query6	330	221	210	210
query7	4206	454	265	265
query8	344	230	237	230
query9	8714	2699	2713	2699
query10	531	394	343	343
query11	7054	5087	4867	4867
query12	182	131	126	126
query13	1267	472	367	367
query14	5745	3758	3505	3505
query14_1	2851	2849	2831	2831
query15	207	194	179	179
query16	980	479	447	447
query17	1060	725	623	623
query18	2456	453	356	356
query19	221	218	190	190
query20	137	125	131	125
query21	217	136	111	111
query22	13305	13944	14765	13944
query23	16236	15760	15617	15617
query23_1	16000	15836	15564	15564
query24	7248	1630	1215	1215
query24_1	1222	1226	1254	1226
query25	588	508	397	397
query26	1237	258	153	153
query27	2800	490	293	293
query28	4472	1828	1841	1828
query29	831	558	508	508
query30	298	224	190	190
query31	1006	949	865	865
query32	84	71	69	69
query33	509	338	280	280
query34	878	888	524	524
query35	626	682	613	613
query36	1050	1136	997	997
query37	133	91	83	83
query38	2973	2956	2811	2811
query39	858	819	814	814
query39_1	799	790	808	790
query40	234	154	136	136
query41	62	59	60	59
query42	255	255	257	255
query43	232	253	216	216
query44	
query45	197	193	182	182
query46	896	990	615	615
query47	2127	2120	2053	2053
query48	305	312	229	229
query49	621	453	420	420
query50	691	275	217	217
query51	4117	4064	4065	4064
query52	266	269	261	261
query53	289	343	284	284
query54	317	273	265	265
query55	91	87	86	86
query56	306	324	319	319
query57	1925	1642	1639	1639
query58	281	271	270	270
query59	2791	2942	2747	2747
query60	363	330	337	330
query61	149	156	149	149
query62	642	600	538	538
query63	309	285	279	279
query64	5037	1274	994	994
query65	
query66	1466	450	361	361
query67	24222	24234	24306	24234
query68	
query69	401	315	299	299
query70	951	972	941	941
query71	334	308	302	302
query72	2767	2680	2663	2663
query73	544	563	326	326
query74	9623	9565	9372	9372
query75	2885	2764	2438	2438
query76	2277	1035	692	692
query77	350	363	314	314
query78	10940	10965	10391	10391
query79	3026	782	579	579
query80	1762	614	548	548
query81	571	260	226	226
query82	1022	151	119	119
query83	331	263	251	251
query84	278	121	95	95
query85	921	497	444	444
query86	497	307	295	295
query87	3122	3053	3022	3022
query88	3540	2659	2638	2638
query89	426	367	355	355
query90	2010	177	186	177
query91	172	165	141	141
query92	85	70	74	70
query93	1819	828	491	491
query94	651	315	304	304
query95	602	409	326	326
query96	640	517	226	226
query97	2434	2502	2396	2396
query98	240	223	219	219
query99	1004	965	910	910
Total cold run time: 252651 ms
Total hot run time: 168322 ms

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 54.55% (6/11) 🎉
Increment coverage report
Complete coverage report

Two existing tests use large bucket numbers (2400) which exceed the default
max_bucket_num_per_partition limit. Disable the limit in these tests to
avoid test failures:
- DecommissionTest.testDecommissionBackend
- PartitionExprUtilTest.testAutoBucketLargeDataCalculatesBuckets
@gavinchou
Copy link
Contributor Author

Fixed unit tests in DecommissionTest and PartitionExprUtilTest to disable max_bucket_num_per_partition limit for tests that use large bucket numbers.

The other failing tests (LoadManagerTest, TableQueryPlanActionTest, CountStarSmallestSlotTest) are pre-existing issues unrelated to this change.

@gavinchou
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 26709 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 8fefdb12b5e9b3d7d0782bde2ac678558ade23e5, 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	17610	4459	4290	4290
q2	q3	10648	770	516	516
q4	4675	349	250	250
q5	7547	1180	1010	1010
q6	181	172	145	145
q7	770	832	666	666
q8	9605	1478	1317	1317
q9	4880	4686	4698	4686
q10	6326	1877	1633	1633
q11	459	262	257	257
q12	737	592	464	464
q13	18042	2924	2160	2160
q14	237	243	207	207
q15	q16	762	745	673	673
q17	734	818	471	471
q18	5996	5281	5236	5236
q19	1447	963	626	626
q20	555	498	379	379
q21	4572	1850	1430	1430
q22	534	373	293	293
Total cold run time: 96317 ms
Total hot run time: 26709 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	4864	4627	4586	4586
q2	q3	3874	4327	3810	3810
q4	863	1212	775	775
q5	4014	4355	4306	4306
q6	182	173	141	141
q7	1757	1622	1526	1526
q8	2495	2774	2574	2574
q9	7424	7377	7319	7319
q10	3840	4117	3577	3577
q11	524	432	412	412
q12	512	588	445	445
q13	2706	3559	2350	2350
q14	291	309	286	286
q15	q16	742	772	753	753
q17	1198	1368	1379	1368
q18	7316	6760	6600	6600
q19	948	926	956	926
q20	2064	2467	2049	2049
q21	3981	3485	3374	3374
q22	438	436	405	405
Total cold run time: 50033 ms
Total hot run time: 47582 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 168017 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 8fefdb12b5e9b3d7d0782bde2ac678558ade23e5, data reload: false

query5	4334	660	496	496
query6	336	230	220	220
query7	4234	483	273	273
query8	348	254	234	234
query9	8785	2701	2707	2701
query10	509	395	341	341
query11	7018	5073	4887	4887
query12	189	135	133	133
query13	1277	444	350	350
query14	5767	3654	3458	3458
query14_1	2852	2797	2797	2797
query15	209	195	177	177
query16	986	463	444	444
query17	973	747	627	627
query18	2446	466	365	365
query19	249	223	188	188
query20	132	128	126	126
query21	218	142	108	108
query22	13196	13985	14782	13985
query23	16194	15695	15476	15476
query23_1	15889	15717	15725	15717
query24	7271	1610	1207	1207
query24_1	1238	1224	1254	1224
query25	624	482	416	416
query26	1239	267	143	143
query27	2763	474	299	299
query28	4454	1827	1837	1827
query29	866	577	473	473
query30	297	213	192	192
query31	1025	938	882	882
query32	83	71	70	70
query33	595	337	283	283
query34	980	861	542	542
query35	637	686	598	598
query36	1044	1130	975	975
query37	143	100	78	78
query38	2937	2898	2849	2849
query39	852	837	814	814
query39_1	798	794	793	793
query40	233	150	137	137
query41	64	58	58	58
query42	256	257	254	254
query43	236	254	226	226
query44	
query45	199	193	183	183
query46	882	977	605	605
query47	2115	2196	2040	2040
query48	329	317	223	223
query49	640	460	385	385
query50	684	266	213	213
query51	4022	4017	3946	3946
query52	265	265	259	259
query53	289	333	276	276
query54	295	271	261	261
query55	89	89	79	79
query56	326	331	319	319
query57	1886	1822	1641	1641
query58	278	274	271	271
query59	2770	2940	2751	2751
query60	346	344	328	328
query61	154	158	158	158
query62	624	595	538	538
query63	303	281	270	270
query64	5112	1291	1019	1019
query65	
query66	1465	466	355	355
query67	24209	24197	24135	24135
query68	
query69	404	323	286	286
query70	967	986	939	939
query71	338	311	298	298
query72	2810	2698	2509	2509
query73	552	544	321	321
query74	9616	9551	9355	9355
query75	2842	2732	2475	2475
query76	2310	1017	668	668
query77	362	406	311	311
query78	10872	11025	10436	10436
query79	2950	774	581	581
query80	1740	609	534	534
query81	561	262	237	237
query82	1003	155	116	116
query83	349	262	247	247
query84	304	124	107	107
query85	953	496	460	460
query86	495	306	314	306
query87	3117	3081	3021	3021
query88	3581	2690	2661	2661
query89	432	368	339	339
query90	2005	177	174	174
query91	173	167	142	142
query92	81	81	72	72
query93	1461	838	511	511
query94	661	307	279	279
query95	593	339	379	339
query96	649	526	232	232
query97	2456	2491	2383	2383
query98	243	221	217	217
query99	1044	1008	916	916
Total cold run time: 252308 ms
Total hot run time: 168017 ms

…st configurations

Configure max_bucket_num_per_partition in regression test configs for testing.
@gavinchou
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 26540 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit ff2d8dd5c54206160fa8fe4781532789ae04db36, 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	17623	4421	4313	4313
q2	q3	10642	794	521	521
q4	4670	355	247	247
q5	7552	1216	1028	1028
q6	172	174	147	147
q7	779	838	677	677
q8	9290	1467	1373	1373
q9	4864	4781	4667	4667
q10	6244	1895	1641	1641
q11	463	257	248	248
q12	694	585	468	468
q13	18021	2725	1952	1952
q14	226	236	209	209
q15	q16	749	723	671	671
q17	725	854	419	419
q18	5963	5348	5332	5332
q19	1102	967	608	608
q20	534	504	378	378
q21	4408	1839	1389	1389
q22	354	292	252	252
Total cold run time: 95075 ms
Total hot run time: 26540 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	5063	4795	4596	4596
q2	q3	3873	4372	3842	3842
q4	883	1202	777	777
q5	4084	4384	4369	4369
q6	193	177	145	145
q7	1790	1644	1530	1530
q8	2468	2714	2550	2550
q9	7658	7626	7382	7382
q10	3759	4028	3636	3636
q11	513	443	425	425
q12	484	598	443	443
q13	2449	2960	2095	2095
q14	305	312	286	286
q15	q16	743	757	718	718
q17	1136	1381	1374	1374
q18	7059	6664	6621	6621
q19	874	902	898	898
q20	2070	2130	2017	2017
q21	3923	3490	3299	3299
q22	459	436	376	376
Total cold run time: 49786 ms
Total hot run time: 47379 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 168930 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 ff2d8dd5c54206160fa8fe4781532789ae04db36, data reload: false

query5	4373	625	497	497
query6	332	227	209	209
query7	4219	468	272	272
query8	340	244	230	230
query9	8745	2732	2749	2732
query10	533	376	335	335
query11	6958	5103	4899	4899
query12	181	127	125	125
query13	1275	476	348	348
query14	5718	3722	3498	3498
query14_1	2838	2839	2825	2825
query15	201	193	174	174
query16	974	471	447	447
query17	882	733	629	629
query18	2440	460	356	356
query19	222	215	187	187
query20	144	128	129	128
query21	214	145	118	118
query22	13161	13276	13106	13106
query23	16274	15794	16338	15794
query23_1	16416	16177	16195	16177
query24	8161	1660	1272	1272
query24_1	1267	1266	1270	1266
query25	618	500	440	440
query26	1258	373	161	161
query27	3025	517	340	340
query28	4884	1958	1904	1904
query29	903	584	511	511
query30	311	224	194	194
query31	1125	1061	926	926
query32	88	73	73	73
query33	535	362	301	301
query34	1007	919	572	572
query35	698	722	694	694
query36	1196	1270	1067	1067
query37	150	96	93	93
query38	3005	2999	3146	2999
query39	870	831	822	822
query39_1	795	792	795	792
query40	230	154	133	133
query41	61	57	58	57
query42	258	251	254	251
query43	245	247	223	223
query44	
query45	194	189	182	182
query46	907	984	613	613
query47	2102	2483	2048	2048
query48	318	318	229	229
query49	634	442	375	375
query50	703	284	221	221
query51	4061	4163	4082	4082
query52	272	264	266	264
query53	292	332	288	288
query54	292	280	265	265
query55	93	85	82	82
query56	312	329	304	304
query57	1907	1726	1669	1669
query58	286	271	276	271
query59	2795	2961	2750	2750
query60	355	339	316	316
query61	156	152	154	152
query62	616	592	556	556
query63	317	286	285	285
query64	5180	1295	1002	1002
query65	
query66	1466	456	352	352
query67	24291	24249	24250	24249
query68	
query69	409	312	283	283
query70	978	977	893	893
query71	327	310	295	295
query72	2920	2666	2447	2447
query73	536	557	318	318
query74	9595	9577	9378	9378
query75	2904	2739	2458	2458
query76	2385	1024	695	695
query77	356	370	317	317
query78	10954	11173	10488	10488
query79	1101	781	574	574
query80	688	618	540	540
query81	498	265	230	230
query82	1379	156	114	114
query83	368	266	247	247
query84	301	117	94	94
query85	832	500	446	446
query86	356	323	283	283
query87	3159	3115	3026	3026
query88	3561	2684	2669	2669
query89	422	369	346	346
query90	1966	178	177	177
query91	172	158	134	134
query92	77	72	74	72
query93	929	837	501	501
query94	456	320	304	304
query95	579	397	317	317
query96	647	515	232	232
query97	2445	2518	2409	2409
query98	236	231	240	231
query99	964	1015	895	895
Total cold run time: 251560 ms
Total hot run time: 168930 ms

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 36.36% (4/11) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Contributor

skip buildall

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Mar 25, 2026
@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

Copy link
Collaborator

@deardeng deardeng left a comment

Choose a reason for hiding this comment

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

LGTM

@hello-stephen hello-stephen merged commit 0b5d4d2 into apache:master Mar 25, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants