Skip to content

[fix](fe) Reject non-sortable duplicate keys when adding a rollup - #68195

Open
eldenmoon wants to merge 1 commit into
apache:masterfrom
eldenmoon:fix-rollup-dup-key-type
Open

eldenmoon wants to merge 1 commit into
apache:masterfrom
eldenmoon:fix-rollup-dup-key-type

Conversation

@eldenmoon

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary:

ALTER TABLE ... ADD ROLLUP r (v, id) DUPLICATE KEY(v) is accepted by FE when v is a VARIANT column, but the asynchronous rollup job then fails in BE and ends up CANCELLED:

rollup tasks failed on same tablet reach threshold 1, reason=task type: ALTER,
status_code: NOT_IMPLEMENTED_ERROR, status_message: [NOT_IMPLEMENTED_ERROR] not implemented

Root cause: when the user lists the duplicate keys explicitly, MaterializedViewHandler.checkAndPrepareMaterializedView(AddRollupOp ...) never checks the key column type. The implicit branch stops at the first column that couldBeShortKey() rejects, and CREATE MATERIALIZED VIEW rejects these types too, but the explicit branch lets them through. BE sorts the rollup rows by the duplicate keys and cannot compare these types. Checked on a cluster before the fix:

duplicate key type rollup job result
VARIANT CANCELLED, NOT_IMPLEMENTED_ERROR
ARRAY / MAP / STRUCT CANCELLED, OlapColumnDataConvertor* not support get_data_at
JSON CANCELLED, INTERNAL_ERROR value 65537 cast to type t out of range
STRING / DOUBLE / IPV6 FINISHED

Fix: reject a duplicate key whose type isOnlyMetricType() (hll, bitmap, quantile_state, array, map, struct, jsonb, variant) when the statement is submitted, with the same Type.OnlyMetricTypeErrorMsg that CREATE MATERIALIZED VIEW uses. Types that BE can sort, such as STRING and DOUBLE, keep working as before. The same function also serves the ROLLUP clause of CREATE TABLE, which now reports this reason too.

Release note

ADD ROLLUP with an explicit DUPLICATE KEY on a VARIANT, ARRAY, MAP, STRUCT, JSON, HLL, BITMAP or QUANTILE_STATE column is now rejected immediately instead of creating a job that fails later.

Check List (For Author)

  • Test: Regression test (rollup_p0/test_rollup_dup_key_type)
  • Behavior changed: Yes. These rollups are rejected when submitted instead of being cancelled asynchronously.
  • Does this need documentation: No

🤖 Generated with Claude Code

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary:

`ALTER TABLE ... ADD ROLLUP r (v, id) DUPLICATE KEY(v)` is accepted by FE when `v` is a VARIANT column, but the asynchronous rollup job then fails in BE and ends up CANCELLED:

```
rollup tasks failed on same tablet reach threshold 1, reason=task type: ALTER,
status_code: NOT_IMPLEMENTED_ERROR, status_message: [NOT_IMPLEMENTED_ERROR] not implemented
```

Root cause: when the user lists the duplicate keys explicitly, `MaterializedViewHandler.checkAndPrepareMaterializedView(AddRollupOp ...)` never checks the key column type. The implicit branch stops at the first column that `couldBeShortKey()` rejects, and CREATE MATERIALIZED VIEW rejects these types too, but the explicit branch lets them through. BE sorts the rollup rows by the duplicate keys and cannot compare these types. Checked on a cluster before the fix:

| duplicate key type | rollup job result |
|---|---|
| VARIANT | CANCELLED, NOT_IMPLEMENTED_ERROR |
| ARRAY / MAP / STRUCT | CANCELLED, `OlapColumnDataConvertor* not support get_data_at` |
| JSON | CANCELLED, INTERNAL_ERROR `value 65537 cast to type t out of range` |
| STRING / DOUBLE / IPV6 | FINISHED |

Fix: reject a duplicate key whose type `isOnlyMetricType()` (hll, bitmap, quantile_state, array, map, struct, jsonb, variant) when the statement is submitted, with the same `Type.OnlyMetricTypeErrorMsg` that CREATE MATERIALIZED VIEW uses. Types that BE can sort, such as STRING and DOUBLE, keep working as before. The same function also serves the ROLLUP clause of CREATE TABLE, which now reports this reason too.

### Release note

ADD ROLLUP with an explicit DUPLICATE KEY on a VARIANT, ARRAY, MAP, STRUCT, JSON, HLL, BITMAP or QUANTILE_STATE column is now rejected immediately instead of creating a job that fails later.

### Check List (For Author)

- Test: Regression test (rollup_p0/test_rollup_dup_key_type)
- Behavior changed: Yes. These rollups are rejected when submitted instead of being cancelled asynchronously.
- Does this need documentation: No

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@eldenmoon

Copy link
Copy Markdown
Member Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17794	3830	3781	3781
q2	2285	348	295	295
q3	10015	1372	809	809
q4	4684	481	349	349
q5	7484	817	546	546
q6	178	164	135	135
q7	833	787	607	607
q8	9338	1472	1536	1472
q9	5336	4162	4142	4142
q10	6779	1651	1358	1358
q11	422	264	262	262
q12	627	413	297	297
q13	18077	2618	2017	2017
q14	258	258	236	236
q15	q16	729	717	663	663
q17	1739	1150	1040	1040
q18	6471	5592	5517	5517
q19	1296	1271	1073	1073
q20	475	387	258	258
q21	5911	2996	2618	2618
q22	459	358	312	312
Total cold run time: 101190 ms
Total hot run time: 27787 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4570	4728	4437	4437
q2	821	606	580	580
q3	4894	5118	4706	4706
q4	2201	2307	1451	1451
q5	4540	4334	4414	4334
q6	302	181	127	127
q7	1815	1690	1502	1502
q8	2304	2007	2024	2007
q9	7427	7320	7190	7190
q10	4264	4262	3867	3867
q11	552	388	355	355
q12	715	724	500	500
q13	2288	2624	1995	1995
q14	266	286	247	247
q15	q16	657	675	599	599
q17	7300	6785	6665	6665
q18	11856	11055	11737	11055
q19	1118	998	988	988
q20	2201	2165	1918	1918
q21	5379	4433	4684	4433
q22	515	454	413	413
Total cold run time: 65985 ms
Total hot run time: 59369 ms

@hello-stephen

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

query5	4326	588	461	461
query6	444	184	164	164
query7	4821	513	290	290
query8	321	174	167	167
query9	8787	3972	3976	3972
query10	439	298	262	262
query11	5818	2209	2028	2028
query12	170	100	100	100
query13	1247	595	385	385
query14	6568	4567	4231	4231
query14_1	4030	3976	3983	3976
query15	206	199	178	178
query16	993	452	345	345
query17	950	630	520	520
query18	2455	472	327	327
query19	190	173	135	135
query20	105	99	97	97
query21	217	135	115	115
query22	13134	13014	12838	12838
query23	15786	14870	14330	14330
query23_1	14347	14131	14190	14131
query24	7556	1707	1227	1227
query24_1	1264	1246	1236	1236
query25	503	422	343	343
query26	1262	317	160	160
query27	2740	555	331	331
query28	4581	1949	1969	1949
query29	1025	586	443	443
query30	319	240	201	201
query31	892	747	633	633
query32	147	89	85	85
query33	500	304	233	233
query34	1223	1116	639	639
query35	726	768	644	644
query36	793	802	725	725
query37	152	105	96	96
query38	1845	1769	1740	1740
query39	697	690	668	668
query39_1	643	646	630	630
query40	232	125	104	104
query41	71	72	70	70
query42	94	93	93	93
query43	340	353	300	300
query44	1361	698	705	698
query45	193	181	172	172
query46	1065	1193	723	723
query47	1506	1507	1375	1375
query48	420	397	302	302
query49	585	407	304	304
query50	980	352	249	249
query51	10395	10161	10464	10161
query52	87	90	75	75
query53	247	260	187	187
query54	252	219	216	216
query55	78	75	71	71
query56	243	240	229	229
query57	1477	1487	1379	1379
query58	243	218	215	215
query59	1968	2054	1803	1803
query60	297	252	241	241
query61	169	168	195	168
query62	404	329	267	267
query63	217	185	182	182
query64	3017	1163	1012	1012
query65	3979	3948	3949	3948
query66	1807	431	296	296
query67	20063	20255	19974	19974
query68	3082	1571	914	914
query69	396	322	263	263
query70	939	890	844	844
query71	292	235	209	209
query72	2977	2546	2222	2222
query73	820	795	432	432
query74	4668	4513	4281	4281
query75	2309	2267	1918	1918
query76	2350	1103	699	699
query77	358	384	292	292
query78	9087	8979	8459	8459
query79	1418	1180	792	792
query80	1248	454	378	378
query81	530	280	236	236
query82	649	166	124	124
query83	351	269	247	247
query84	325	143	108	108
query85	889	466	371	371
query86	394	236	231	231
query87	2008	1963	1833	1833
query88	3675	2734	2710	2710
query89	359	289	247	247
query90	1929	182	179	179
query91	165	160	130	130
query92	101	93	90	90
query93	1560	1466	846	846
query94	726	342	288	288
query95	667	456	339	339
query96	1076	779	342	342
query97	2438	2432	2305	2305
query98	195	194	185	185
query99	739	718	613	613
Total cold run time: 242914 ms
Total hot run time: 153899 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 0.00% (0/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17764	3963	3982	3963
q2	2265	338	289	289
q3	10021	1427	796	796
q4	4679	475	345	345
q5	7531	811	552	552
q6	174	165	134	134
q7	721	770	584	584
q8	9324	1584	1490	1490
q9	5442	4191	4164	4164
q10	6814	1586	1357	1357
q11	438	272	243	243
q12	640	405	288	288
q13	18123	2613	1985	1985
q14	255	251	232	232
q15	q16	724	708	665	665
q17	1778	1091	982	982
q18	6509	5593	5512	5512
q19	1201	1191	1120	1120
q20	490	390	269	269
q21	5632	2575	2237	2237
q22	402	348	297	297
Total cold run time: 100927 ms
Total hot run time: 27504 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4183	4093	4155	4093
q2	742	567	535	535
q3	4526	4888	4331	4331
q4	2210	2290	1438	1438
q5	4230	4071	4089	4071
q6	246	171	129	129
q7	1652	1557	1412	1412
q8	2139	2280	2059	2059
q9	7427	7245	7426	7245
q10	4282	4284	3814	3814
q11	551	396	365	365
q12	720	740	507	507
q13	2442	2747	2143	2143
q14	283	307	273	273
q15	q16	692	723	632	632
q17	7909	7134	7016	7016
q18	11848	11055	11871	11055
q19	1190	1097	1080	1080
q20	2216	2198	1935	1935
q21	5817	4767	4541	4541
q22	523	438	399	399
Total cold run time: 65828 ms
Total hot run time: 59073 ms

@hello-stephen

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

query5	4306	594	460	460
query6	435	179	166	166
query7	4877	559	280	280
query8	315	176	167	167
query9	8778	3900	3936	3900
query10	438	309	245	245
query11	5878	2198	2020	2020
query12	150	94	96	94
query13	1252	509	396	396
query14	6561	4546	4229	4229
query14_1	4015	3996	3966	3966
query15	203	198	176	176
query16	972	459	423	423
query17	921	681	539	539
query18	2431	452	327	327
query19	195	179	139	139
query20	109	102	104	102
query21	218	131	117	117
query22	12994	12981	12783	12783
query23	15464	14709	13969	13969
query23_1	14098	14000	14054	14000
query24	7802	1719	1223	1223
query24_1	1246	1211	1248	1211
query25	506	396	337	337
query26	1272	324	161	161
query27	2653	554	324	324
query28	4545	1970	1965	1965
query29	1029	574	464	464
query30	313	233	198	198
query31	896	776	624	624
query32	152	89	91	89
query33	522	306	233	233
query34	1169	1105	626	626
query35	709	761	637	637
query36	779	796	709	709
query37	150	104	93	93
query38	1842	1767	1691	1691
query39	682	665	646	646
query39_1	625	638	643	638
query40	222	120	96	96
query41	66	64	63	63
query42	97	95	93	93
query43	337	341	303	303
query44	1395	678	686	678
query45	190	175	170	170
query46	1053	1174	725	725
query47	1506	1520	1362	1362
query48	399	406	281	281
query49	570	406	291	291
query50	998	333	238	238
query51	10510	10638	10553	10553
query52	85	83	77	77
query53	238	250	174	174
query54	243	204	196	196
query55	76	73	68	68
query56	220	229	201	201
query57	1498	1253	1349	1253
query58	224	211	199	199
query59	1973	2067	1815	1815
query60	264	239	216	216
query61	142	143	137	137
query62	400	319	263	263
query63	221	171	174	171
query64	2866	1112	942	942
query65	4016	3977	3927	3927
query66	1895	437	317	317
query67	19964	19940	19803	19803
query68	3316	1490	841	841
query69	407	311	277	277
query70	987	905	876	876
query71	306	241	214	214
query72	3244	2468	2169	2169
query73	833	737	441	441
query74	4643	4475	4287	4287
query75	2292	2299	1951	1951
query76	2415	1125	701	701
query77	365	386	336	336
query78	9053	9083	8374	8374
query79	1399	1277	742	742
query80	578	459	356	356
query81	476	279	237	237
query82	605	170	125	125
query83	357	269	249	249
query84	323	146	111	111
query85	828	445	370	370
query86	337	231	235	231
query87	1987	1994	1832	1832
query88	3592	2705	2669	2669
query89	359	289	244	244
query90	1901	179	172	172
query91	168	152	121	121
query92	98	91	88	88
query93	1536	1402	899	899
query94	535	330	297	297
query95	682	457	332	332
query96	1078	841	348	348
query97	2458	2447	2310	2310
query98	200	191	186	186
query99	733	723	615	615
Total cold run time: 241502 ms
Total hot run time: 153039 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.08	0.05	0.05
query3	0.26	0.13	0.13
query4	1.62	0.14	0.14
query5	0.24	0.22	0.21
query6	1.16	0.92	0.96
query7	0.04	0.02	0.00
query8	0.06	0.04	0.04
query9	0.39	0.33	0.34
query10	0.54	0.54	0.57
query11	0.20	0.13	0.14
query12	0.18	0.14	0.14
query13	0.47	0.47	0.47
query14	0.94	0.93	0.93
query15	0.62	0.59	0.59
query16	0.34	0.33	0.32
query17	1.11	1.05	1.13
query18	0.21	0.20	0.18
query19	2.01	1.96	1.94
query20	0.03	0.01	0.01
query21	15.43	0.21	0.14
query22	4.84	0.05	0.06
query23	16.16	0.31	0.13
query24	2.98	0.43	0.33
query25	0.10	0.04	0.04
query26	0.72	0.21	0.14
query27	0.05	0.04	0.04
query28	3.58	0.83	0.36
query29	12.49	4.09	3.24
query30	0.29	0.18	0.17
query31	2.77	0.55	0.32
query32	3.23	0.58	0.48
query33	3.17	3.16	3.12
query34	15.56	3.92	3.30
query35	3.22	3.19	3.26
query36	0.54	0.44	0.41
query37	0.09	0.06	0.07
query38	0.05	0.04	0.03
query39	0.04	0.03	0.03
query40	0.16	0.15	0.14
query41	0.09	0.04	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.14 s
Total hot run time: 23.93 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