Skip to content

[fix](be) Fix missing decimal precision and scale for legacy decimal data#65419

Open
jacktengg wants to merge 2 commits into
apache:masterfrom
jacktengg:wt-fix-dec-precision
Open

[fix](be) Fix missing decimal precision and scale for legacy decimal data#65419
jacktengg wants to merge 2 commits into
apache:masterfrom
jacktengg:wt-fix-dec-precision

Conversation

@jacktengg

@jacktengg jacktengg commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #26572, #63569

Problem Summary:

Segments written before decimal ColumnMetaPB precision and scale were persisted can miss precision and scale for decimal types in metadata . Regular columns, complex decimal children may then build decimal DataType instances without the logical precision/scale from TabletSchema, and result in error "Wrong precision 0, min: 1, max: 76". This change centralizes decimal metadata recovery from TabletSchema, applies it before ColumnReader/DataType creation.

Release note

Fix reading legacy decimal whose segment metadata is missing decimal precision and scale.

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

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

@jacktengg

Copy link
Copy Markdown
Contributor Author

/review

@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: You've hit your usage limit. Visit https://chatgpt.com/codex/settings/usage to purchase more credits or try again at 11:47 AM.
Workflow run: https://github.com/apache/doris/actions/runs/29009677710

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.


namespace {

void fill_missing_decimal_precision(ColumnMetaPB* meta, const TabletColumn& column) {

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.

一把把输入参数放第一个,返回值放后面

// Segments written before #26572 do not persist decimal precision/frac in
// ColumnMetaPB, so recover the logical p/s from TabletSchema before
// ColumnReader builds DataTypeDecimal.
fill_missing_decimal_precision_from_schema(&meta, _tablet_schema);

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.

如果你再这里修改了,那么上次的fix 还有用没?
另外,这里好像没区分decimalv2还是decimal v3? 比如如果是decimal v2 怎么办?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

上次的fix可以不用了。

}
}
} else if (is_numeric_type(type)) {
} else if (field_is_numeric_type(type)) {

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.

这个变动的原因是?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

删除重复代码is_numeric_type。

@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

// Segments written before #26572 do not persist decimal precision/frac in
// ColumnMetaPB, so recover the logical p/s from TabletSchema before
// ColumnReader builds DataTypeDecimal.
fill_missing_decimal_precision_from_schema(&meta, _tablet_schema);

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.

在Segment::_parse_footer 的时候把里面的ColumnMetaPB 改了就行。

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 90.24% (37/41) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.79% (29973/40074)
Line Coverage 58.86% (328741/558545)
Region Coverage 55.64% (275889/495813)
Branch Coverage 56.90% (121394/213350)

…data

Related PR: apache#26572, apache#63569

Problem Summary:
Segments written before decimal ColumnMetaPB precision and scale were persisted can miss decimal precision and scale in metadata. Regular columns, complex decimal children may then build decimal DataType instances without the logical precision/scale from TabletSchema. This change centralizes decimal metadata recovery from TabletSchema, applies it before ColumnReader/DataType creation.

Fix legacy segment footer parsing to recover missing decimal precision and scale before column readers and data types are created.
@jacktengg jacktengg force-pushed the wt-fix-dec-precision branch from 262cfa2 to 4283283 Compare July 9, 2026 15:18
@jacktengg jacktengg changed the title [fix](be) Fix reading legacy decimal whose segment metadata is missing decimal precision or scale [fix](be) Fix missing decimal precision and scale for legacy decimal data Jul 9, 2026
@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17667	4094	4078	4078
q2	2061	327	204	204
q3	10220	1497	866	866
q4	4683	466	335	335
q5	7544	838	579	579
q6	180	167	135	135
q7	789	828	632	632
q8	9358	1614	1714	1614
q9	5709	4425	4414	4414
q10	6782	1784	1522	1522
q11	503	351	310	310
q12	702	550	434	434
q13	18116	3436	2796	2796
q14	269	266	240	240
q15	q16	791	774	710	710
q17	999	1047	933	933
q18	7096	5955	5555	5555
q19	1307	1390	1067	1067
q20	781	627	580	580
q21	6390	2821	2664	2664
q22	465	376	308	308
Total cold run time: 102412 ms
Total hot run time: 29976 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5214	4893	4844	4844
q2	290	342	219	219
q3	5064	5306	4688	4688
q4	2109	2164	1357	1357
q5	4862	4996	4770	4770
q6	237	180	126	126
q7	1872	1847	1572	1572
q8	2517	2148	2104	2104
q9	7765	7365	7254	7254
q10	4656	4621	4171	4171
q11	528	388	351	351
q12	726	739	531	531
q13	2973	3355	2778	2778
q14	289	291	258	258
q15	q16	679	690	616	616
q17	1291	1284	1276	1276
q18	7472	6893	6851	6851
q19	1070	1077	1045	1045
q20	2227	2212	1951	1951
q21	5420	4646	4435	4435
q22	525	455	406	406
Total cold run time: 57786 ms
Total hot run time: 51603 ms

@hello-stephen

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

query5	4392	640	474	474
query6	484	240	212	212
query7	4855	636	366	366
query8	361	195	180	180
query9	8820	4066	4059	4059
query10	464	334	324	324
query11	5902	2357	2197	2197
query12	172	105	108	105
query13	1261	613	419	419
query14	7059	5331	4934	4934
query14_1	4298	4286	4264	4264
query15	230	205	185	185
query16	1030	483	476	476
query17	1289	783	594	594
query18	2768	472	362	362
query19	315	197	157	157
query20	114	113	109	109
query21	240	164	135	135
query22	13615	13699	13419	13419
query23	17478	16450	16062	16062
query23_1	16367	16318	16241	16241
query24	7478	1744	1299	1299
query24_1	1339	1283	1312	1283
query25	574	481	411	411
query26	1301	365	211	211
query27	2446	607	393	393
query28	4322	2031	2017	2017
query29	1093	641	506	506
query30	335	266	231	231
query31	1132	1111	981	981
query32	112	64	62	62
query33	530	337	260	260
query34	1152	1147	659	659
query35	768	795	673	673
query36	1419	1372	1262	1262
query37	209	113	89	89
query38	1882	1698	1638	1638
query39	919	923	868	868
query39_1	885	874	893	874
query40	246	163	139	139
query41	66	65	62	62
query42	94	93	93	93
query43	317	325	280	280
query44	1405	780	755	755
query45	197	189	179	179
query46	1120	1195	788	788
query47	2332	2321	2184	2184
query48	412	414	299	299
query49	575	423	310	310
query50	1024	435	329	329
query51	10626	10545	10838	10545
query52	86	88	75	75
query53	264	287	194	194
query54	296	241	221	221
query55	76	73	65	65
query56	307	281	296	281
query57	1428	1382	1331	1331
query58	280	261	256	256
query59	1603	1644	1437	1437
query60	302	267	263	263
query61	160	156	154	154
query62	700	647	560	560
query63	245	205	199	199
query64	2770	1076	885	885
query65	4839	4776	4785	4776
query66	1799	532	385	385
query67	29546	29595	29330	29330
query68	3172	1531	1065	1065
query69	453	317	278	278
query70	1055	962	992	962
query71	338	341	311	311
query72	3164	2727	2474	2474
query73	822	738	434	434
query74	5084	4964	4809	4809
query75	2619	2600	2230	2230
query76	2325	1179	786	786
query77	364	388	286	286
query78	12328	12310	11782	11782
query79	1423	1129	777	777
query80	1321	536	443	443
query81	508	335	284	284
query82	566	159	132	132
query83	393	319	289	289
query84	281	165	131	131
query85	975	600	505	505
query86	435	295	303	295
query87	1818	1829	1751	1751
query88	3750	2821	2801	2801
query89	455	404	354	354
query90	1953	205	193	193
query91	200	187	163	163
query92	63	61	55	55
query93	1522	1526	973	973
query94	835	361	313	313
query95	775	582	486	486
query96	1052	826	366	366
query97	2708	2671	2545	2545
query98	216	205	205	205
query99	1160	1172	1019	1019
Total cold run time: 267003 ms
Total hot run time: 180810 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.04	0.04
query3	0.25	0.12	0.12
query4	1.63	0.14	0.13
query5	0.25	0.21	0.22
query6	1.24	1.05	1.10
query7	0.04	0.01	0.01
query8	0.06	0.03	0.03
query9	0.37	0.30	0.32
query10	0.56	0.55	0.54
query11	0.19	0.14	0.14
query12	0.18	0.15	0.14
query13	0.47	0.49	0.48
query14	1.01	1.00	1.02
query15	0.63	0.62	0.59
query16	0.31	0.33	0.31
query17	1.14	1.12	1.08
query18	0.22	0.20	0.22
query19	2.04	1.92	1.99
query20	0.02	0.01	0.02
query21	15.55	0.23	0.14
query22	4.86	0.06	0.05
query23	16.13	0.32	0.12
query24	2.97	0.40	0.31
query25	0.12	0.05	0.03
query26	0.72	0.20	0.15
query27	0.04	0.03	0.04
query28	3.50	0.88	0.54
query29	12.48	4.13	3.34
query30	0.31	0.14	0.15
query31	2.76	0.61	0.31
query32	3.22	0.60	0.48
query33	3.13	3.18	3.19
query34	15.71	4.22	3.51
query35	3.55	3.54	3.51
query36	0.56	0.43	0.41
query37	0.11	0.07	0.06
query38	0.04	0.04	0.03
query39	0.04	0.02	0.02
query40	0.19	0.16	0.14
query41	0.10	0.04	0.03
query42	0.04	0.03	0.02
query43	0.05	0.03	0.03
Total cold run time: 96.9 s
Total hot run time: 24.88 s

@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@yiguolei yiguolei added the usercase Important user case type label label Jul 10, 2026
@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17832	4066	4017	4017
q2	2057	336	200	200
q3	10243	1440	833	833
q4	4683	479	358	358
q5	7540	852	572	572
q6	178	169	136	136
q7	811	836	619	619
q8	9316	1543	1624	1543
q9	5672	4462	4415	4415
q10	6802	1784	1549	1549
q11	495	345	316	316
q12	706	550	424	424
q13	18107	3383	2734	2734
q14	266	260	236	236
q15	q16	794	779	715	715
q17	1014	916	910	910
q18	6947	5845	5742	5742
q19	1155	1165	1084	1084
q20	809	618	525	525
q21	5619	2592	2397	2397
q22	438	353	300	300
Total cold run time: 101484 ms
Total hot run time: 29625 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4370	4342	4310	4310
q2	285	312	214	214
q3	4603	5011	4403	4403
q4	2063	2157	1377	1377
q5	4465	4338	4414	4338
q6	234	176	128	128
q7	1746	1970	1830	1830
q8	2577	2182	2197	2182
q9	8094	8264	7713	7713
q10	4835	4759	4270	4270
q11	581	429	380	380
q12	771	802	554	554
q13	3227	3579	3018	3018
q14	302	302	286	286
q15	q16	709	727	657	657
q17	1352	1323	1341	1323
q18	7912	7405	7395	7395
q19	1140	1141	1097	1097
q20	2214	2224	1935	1935
q21	5274	4567	4461	4461
q22	517	452	405	405
Total cold run time: 57271 ms
Total hot run time: 52276 ms

@hello-stephen

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

query5	4313	642	488	488
query6	466	222	194	194
query7	4830	585	345	345
query8	341	185	175	175
query9	8764	4053	4039	4039
query10	474	366	345	345
query11	5892	2346	2117	2117
query12	158	100	102	100
query13	1249	617	442	442
query14	6260	5282	4932	4932
query14_1	4261	4252	4270	4252
query15	217	206	180	180
query16	1027	471	441	441
query17	900	721	554	554
query18	2422	451	344	344
query19	220	191	143	143
query20	107	107	106	106
query21	225	152	127	127
query22	13657	13639	13332	13332
query23	17386	16551	16232	16232
query23_1	16238	16338	16153	16153
query24	7660	1792	1310	1310
query24_1	1326	1308	1286	1286
query25	586	478	391	391
query26	1346	333	214	214
query27	2664	589	390	390
query28	4598	2013	1995	1995
query29	1077	610	454	454
query30	339	258	219	219
query31	1110	1093	984	984
query32	108	60	67	60
query33	516	307	275	275
query34	1190	1135	648	648
query35	779	780	674	674
query36	1381	1383	1225	1225
query37	155	107	90	90
query38	1876	1717	1660	1660
query39	927	924	914	914
query39_1	870	872	857	857
query40	246	159	138	138
query41	68	63	61	61
query42	92	92	93	92
query43	323	320	275	275
query44	1408	790	791	790
query45	204	193	176	176
query46	1061	1241	725	725
query47	2339	2338	2305	2305
query48	423	392	303	303
query49	568	419	308	308
query50	1059	426	343	343
query51	10720	10787	10746	10746
query52	84	92	74	74
query53	262	304	207	207
query54	275	227	214	214
query55	75	70	65	65
query56	294	283	298	283
query57	1439	1378	1298	1298
query58	283	250	267	250
query59	1570	1633	1400	1400
query60	303	260	252	252
query61	149	171	176	171
query62	706	655	590	590
query63	251	207	209	207
query64	2948	1158	992	992
query65	4856	4790	4809	4790
query66	1822	530	404	404
query67	29854	29473	29353	29353
query68	3265	1607	1015	1015
query69	427	317	278	278
query70	1135	1018	985	985
query71	416	322	303	303
query72	3102	2677	2402	2402
query73	882	784	431	431
query74	5137	4970	4746	4746
query75	2626	2586	2216	2216
query76	2344	1169	773	773
query77	356	384	277	277
query78	12323	12334	11700	11700
query79	1386	1127	761	761
query80	639	526	447	447
query81	450	323	281	281
query82	577	159	121	121
query83	391	317	291	291
query84	322	155	130	130
query85	889	609	491	491
query86	367	297	288	288
query87	1829	1818	1714	1714
query88	3745	2811	2799	2799
query89	464	412	356	356
query90	1866	204	210	204
query91	198	194	159	159
query92	65	60	56	56
query93	1605	1551	1038	1038
query94	562	361	323	323
query95	787	587	464	464
query96	1051	764	372	372
query97	2691	2715	2561	2561
query98	222	212	202	202
query99	1141	1168	1026	1026
Total cold run time: 265133 ms
Total hot run time: 179789 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.05	0.05
query3	0.25	0.13	0.14
query4	1.61	0.15	0.14
query5	0.27	0.22	0.22
query6	1.29	1.06	1.08
query7	0.04	0.01	0.00
query8	0.06	0.04	0.03
query9	0.38	0.31	0.33
query10	0.55	0.56	0.58
query11	0.20	0.15	0.15
query12	0.18	0.15	0.14
query13	0.47	0.47	0.46
query14	1.03	1.00	1.01
query15	0.61	0.58	0.59
query16	0.31	0.32	0.30
query17	1.09	1.11	1.10
query18	0.23	0.21	0.21
query19	2.07	1.98	1.94
query20	0.01	0.02	0.01
query21	15.42	0.22	0.13
query22	4.80	0.06	0.06
query23	16.10	0.31	0.12
query24	2.98	0.40	0.33
query25	0.11	0.05	0.05
query26	0.76	0.20	0.15
query27	0.05	0.03	0.04
query28	3.48	0.89	0.56
query29	12.51	4.11	3.28
query30	0.27	0.15	0.15
query31	2.77	0.60	0.31
query32	3.22	0.59	0.48
query33	3.14	3.24	3.23
query34	15.51	4.25	3.50
query35	3.54	3.52	3.49
query36	0.54	0.43	0.45
query37	0.10	0.07	0.06
query38	0.05	0.04	0.04
query39	0.03	0.03	0.03
query40	0.18	0.16	0.15
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.48 s
Total hot run time: 25.06 s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.0.x dev/4.1.x reviewed usercase Important user case type label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants