Skip to content

Conversation

@zhiqiang-hhhh
Copy link
Contributor

@zhiqiang-hhhh zhiqiang-hhhh commented Mar 25, 2024

Function truncate can use column as its scale argument. The precision infer rule of truncate is same with mysql:

  1. When using literal as scale, result scale is dependent on the integer literal;
  2. When using column as scale, result will always have same scale with input decimal.

see: https://dbfiddle.uk/Bi891fp4

close #32086

docs update: apache/doris-website#516

@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

@zhiqiang-hhhh
Copy link
Contributor Author

run compile

@zhiqiang-hhhh
Copy link
Contributor Author

run compile

Copy link
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.

clang-tidy made some suggestions

Copy link
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.

clang-tidy made some suggestions

@zhiqiang-hhhh
Copy link
Contributor Author

run compile

zhiqiang-hhhh and others added 2 commits March 25, 2024 12:09
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@zhiqiang-hhhh
Copy link
Contributor Author

run compile

Copy link
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.

clang-tidy made some suggestions

@zhiqiang-hhhh
Copy link
Contributor Author

run compile

Copy link
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.

clang-tidy made some suggestions

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	18095	4441	4358	4358
q2	2232	164	156	156
q3	13171	1146	1254	1146
q4	10852	872	794	794
q5	7690	3110	3065	3065
q6	204	128	126	126
q7	1092	630	581	581
q8	9584	2091	2031	2031
q9	7421	6665	6588	6588
q10	8427	3489	3573	3489
q11	438	223	215	215
q12	367	209	202	202
q13	17809	2899	2875	2875
q14	231	196	202	196
q15	508	461	460	460
q16	508	376	374	374
q17	958	549	608	549
q18	7318	6507	6504	6504
q19	3155	1424	1427	1424
q20	553	269	243	243
q21	3628	2964	3129	2964
q22	364	300	305	300
Total cold run time: 114605 ms
Total hot run time: 38640 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4258	4118	4090	4090
q2	339	234	225	225
q3	2955	2853	2850	2850
q4	1852	1626	1566	1566
q5	5330	5359	5381	5359
q6	196	115	119	115
q7	2250	1872	1843	1843
q8	3177	3326	3303	3303
q9	8757	8764	8799	8764
q10	3814	3822	3765	3765
q11	536	437	446	437
q12	726	568	555	555
q13	16904	2887	2875	2875
q14	269	264	257	257
q15	507	464	465	464
q16	496	422	423	422
q17	1738	1505	1501	1501
q18	7439	7272	7128	7128
q19	1657	1516	1537	1516
q20	1915	1737	1712	1712
q21	4881	4506	4599	4506
q22	565	452	449	449
Total cold run time: 70561 ms
Total hot run time: 53702 ms

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 35.30% (8749/24786)
Line Coverage: 27.12% (71761/264636)
Region Coverage: 26.34% (37212/141264)
Branch Coverage: 23.23% (19027/81902)
Coverage Report: http://coverage.selectdb-in.cc/coverage/6148ec6d0a4732c4be68746bc5ede9f2ba43626f_6148ec6d0a4732c4be68746bc5ede9f2ba43626f/report/index.html

@doris-robot
Copy link

TPC-DS: Total hot run time: 186873 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 6148ec6d0a4732c4be68746bc5ede9f2ba43626f, data reload: false

query1	950	379	366	366
query2	7382	2114	2001	2001
query3	6725	208	217	208
query4	32059	21340	21383	21340
query5	4268	437	423	423
query6	275	186	175	175
query7	4624	293	292	292
query8	234	175	184	175
query9	9503	2294	2266	2266
query10	565	243	254	243
query11	14976	14392	14475	14392
query12	145	98	86	86
query13	1636	423	422	422
query14	13394	10751	10705	10705
query15	262	219	194	194
query16	7852	263	259	259
query17	1940	586	551	551
query18	1345	295	301	295
query19	243	169	165	165
query20	98	92	90	90
query21	203	131	132	131
query22	4947	4767	4774	4767
query23	33612	32808	32974	32808
query24	12035	2873	2880	2873
query25	661	395	372	372
query26	1796	156	158	156
query27	3320	343	355	343
query28	7508	1869	1823	1823
query29	981	650	616	616
query30	309	145	143	143
query31	975	742	745	742
query32	96	63	57	57
query33	769	257	247	247
query34	1101	489	500	489
query35	822	620	613	613
query36	1027	893	874	874
query37	268	74	77	74
query38	3603	3451	3471	3451
query39	1489	1454	1410	1410
query40	295	118	117	117
query41	48	45	46	45
query42	102	94	100	94
query43	481	443	449	443
query44	1155	728	721	721
query45	289	262	248	248
query46	1129	718	724	718
query47	1894	1807	1841	1807
query48	441	369	352	352
query49	1216	340	349	340
query50	764	375	379	375
query51	6797	6628	6591	6591
query52	110	89	88	88
query53	352	282	282	282
query54	319	262	235	235
query55	97	80	77	77
query56	257	228	231	228
query57	1204	1129	1139	1129
query58	229	202	204	202
query59	2914	2713	2711	2711
query60	258	238	246	238
query61	103	110	96	96
query62	648	430	465	430
query63	313	286	282	282
query64	6901	4000	4051	4000
query65	3119	3073	3047	3047
query66	1314	384	376	376
query67	15087	15201	14751	14751
query68	5321	517	521	517
query69	563	385	391	385
query70	1262	1195	1200	1195
query71	442	286	287	286
query72	6604	2909	2703	2703
query73	703	321	325	321
query74	7574	6673	6620	6620
query75	3709	2969	3035	2969
query76	3550	900	896	896
query77	462	265	283	265
query78	10959	10093	10165	10093
query79	8560	511	516	511
query80	1940	405	389	389
query81	532	215	221	215
query82	1115	202	205	202
query83	317	154	145	145
query84	286	82	75	75
query85	1667	329	315	315
query86	493	300	299	299
query87	3775	3567	3527	3527
query88	5216	2314	2291	2291
query89	546	378	383	378
query90	2018	181	181	181
query91	169	135	137	135
query92	62	48	48	48
query93	6971	499	481	481
query94	1219	181	182	181
query95	438	349	331	331
query96	620	271	274	271
query97	3060	2908	2895	2895
query98	235	221	207	207
query99	1228	906	886	886
Total cold run time: 313450 ms
Total hot run time: 186873 ms

@doris-robot
Copy link

Load test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Load test result on commit 6148ec6d0a4732c4be68746bc5ede9f2ba43626f with default session variables
Stream load json:         19 seconds loaded 2358488459 Bytes, about 118 MB/s
Stream load orc:          59 seconds loaded 1101869774 Bytes, about 17 MB/s
Stream load parquet:      31 seconds loaded 861443392 Bytes, about 26 MB/s
Insert into select:       22.3 seconds inserted 10000000 Rows, about 448K ops/s

@zhiqiang-hhhh
Copy link
Contributor Author

run p0

@zhiqiang-hhhh
Copy link
Contributor Author

run p0

@xiaokang xiaokang added usercase Important user case type label dev/2.0.x labels Mar 25, 2024
|| (children.get(1) instanceof CastExpr
&& children.get(1).getChild(0) instanceof IntLiteral),
"2nd argument of function round/floor/ceil/truncate must be literal");
"2nd argument of function round/floor/ceil must be literal");
Copy link
Contributor

Choose a reason for hiding this comment

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

why not support all round family function? if truncate support slot as 2nd arg, other round family function should support this feature too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why not support all round family function? if truncate support slot as 2nd arg, other round family function should support this feature too

Need extra work and many tests on be, maybe one extra week.

This PR completes a lot of basic work, support for other functions will be much easier, so I list them as TODO task.

#32755

FunctionRoundingImpl<ScaleMode::Zero>::apply(col->get_data()[i], scale,
vec_res[i]);
} else if (scale_arg > 0) {
size_t scale = int_exp10(col_scale_i32.get_data()[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

col_scale_i32.get_data()[i] seems no need get again, could use scale_arg directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can.

typename ColumnVector<T>::Container& vec_res = col_res->get_data();

for (size_t i = 0; i < intput_rows_cound; ++i) {
const Int16 scale_arg = col_scale_i32.get_data()[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

in apply_vec_vec function, have check all data of scale_arg in [min, max]
here seems not have this check, it's no need or in other function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we need to do the check. I will re-organize the check loop

@doris-robot
Copy link

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

query1	0.04	0.04	0.03
query2	0.07	0.04	0.04
query3	0.23	0.05	0.05
query4	1.67	0.07	0.06
query5	0.49	0.48	0.48
query6	1.14	0.65	0.65
query7	0.02	0.01	0.01
query8	0.06	0.04	0.04
query9	0.58	0.52	0.52
query10	0.56	0.57	0.56
query11	0.15	0.11	0.11
query12	0.14	0.11	0.11
query13	0.62	0.59	0.58
query14	0.77	0.78	0.79
query15	0.85	0.83	0.85
query16	0.35	0.34	0.35
query17	0.96	0.99	1.00
query18	0.26	0.25	0.25
query19	1.82	1.74	1.70
query20	0.01	0.00	0.00
query21	15.42	0.77	0.69
query22	3.12	5.09	2.56
query23	17.76	1.25	1.14
query24	1.37	0.37	0.24
query25	0.12	0.09	0.09
query26	0.30	0.17	0.17
query27	0.08	0.08	0.07
query28	13.51	0.94	0.92
query29	12.79	3.64	3.37
query30	0.25	0.06	0.06
query31	2.87	0.38	0.39
query32	3.28	0.48	0.47
query33	2.86	2.88	2.91
query34	15.50	4.32	4.34
query35	4.37	4.39	4.37
query36	0.67	0.47	0.47
query37	0.19	0.18	0.16
query38	0.17	0.16	0.16
query39	0.04	0.05	0.04
query40	0.18	0.16	0.17
query41	0.10	0.05	0.05
query42	0.06	0.04	0.04
query43	0.04	0.05	0.04
Total cold run time: 105.84 s
Total hot run time: 30.98 s

@doris-robot
Copy link

Load test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Load test result on commit a82faae91257390f564a7d03f817d36f8f7e6d1c with default session variables
Stream load json:         18 seconds loaded 2358488459 Bytes, about 124 MB/s
Stream load orc:          58 seconds loaded 1101869774 Bytes, about 18 MB/s
Stream load parquet:      33 seconds loaded 861443392 Bytes, about 24 MB/s
Insert into select:       16.2 seconds inserted 10000000 Rows, about 617K ops/s


if (scale_arg > std::numeric_limits<Int16>::max() ||
scale_arg < std::numeric_limits<Int16>::min()) {
throw doris::Exception(ErrorCode::OUT_OF_BOUND,
Copy link
Contributor

Choose a reason for hiding this comment

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

throw maybe will break auto-vectorization. basing on we prefer correct path's performance than wrong path, maybe a flag bool is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update: actually this loop is separated from the loop that processes the data block, so the exception will not break the auto vectorization.

} else if (children.size() == 2) {
Expr scaleExpr = children.get(1);
if (scaleExpr instanceof IntLiteral
|| (scaleExpr instanceof CastExpr && scaleExpr.getChild(0) instanceof IntLiteral)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why consider castexpr here specially? what if it's other exprs which result is constexpr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For expr whose result is constexpr, we will go to branch in L146.

public:
static FunctionPtr create() { return std::make_shared<FunctionTruncate>(); }

ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; }
Copy link
Contributor

Choose a reason for hiding this comment

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

if {}, no need to override this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It must be override. Since function_rounding, instread of IFuntion, is the base class and it has already implemented another retrun result.

is_column_const(*block.get_by_position(arguments[1]).column)) {
// truncate(ColumnConst, ColumnConst)
auto col_general = assert_cast<const ColumnConst&>(*column_general.column)
.get_data_column()
Copy link
Contributor

Choose a reason for hiding this comment

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

get_data_column_ptr directly? no clone_resized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense

@github-actions github-actions bot removed the approved Indicates a PR has been approved by one committer. label Apr 1, 2024
Copy link
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.

clang-tidy made some suggestions

// should NOT behave like two column arguments, so we can not use const column default implementation
bool use_default_implementation_for_constants() const override { return false; }

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'execute_impl' exceeds recommended size/complexity thresholds [readability-function-size]

    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
           ^
Additional context

be/src/vec/functions/function_truncate.h:79: 159 lines including whitespace and comments (threshold 80)

    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
           ^

if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
using FieldType = typename DataType::FieldType;
res = Dispatcher<FieldType, RoundingMode::Trunc,
TieBreakingMode::Auto>::apply_vec_const(col_general,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]

be/src/vec/functions/function_truncate.h:102:

-                 if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
-                     using FieldType = typename DataType::FieldType;
-                     res = Dispatcher<FieldType, RoundingMode::Trunc,
-                                      TieBreakingMode::Auto>::apply_vec_const(col_general, scale_arg);
-                     return true;
-                 }
- 
-                 return false;
+                 return IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>;


if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
using FieldType = typename DataType::FieldType;
res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]

be/src/vec/functions/function_truncate.h:178:

-                 if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
-                     using FieldType = typename DataType::FieldType;
-                     res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
-                             apply_const_vec(&const_col_general, column_scale.column.get());
-                     return true;
-                 }
- 
-                 return false;
+                 return IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>;


if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
using FieldType = typename DataType::FieldType;
res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]

be/src/vec/functions/function_truncate.h:211:

-                 if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
-                     using FieldType = typename DataType::FieldType;
-                     res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
-                             apply_vec_vec(column_general.column.get(), column_scale.column.get());
-                     return true;
-                 }
-                 return false;
+                 return IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>;

Copy link
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.

clang-tidy made some suggestions

// should NOT behave like two column arguments, so we can not use const column default implementation
bool use_default_implementation_for_constants() const override { return false; }

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'execute_impl' exceeds recommended size/complexity thresholds [readability-function-size]

    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
           ^
Additional context

be/src/vec/functions/function_truncate.h:79: 161 lines including whitespace and comments (threshold 80)

    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
           ^

res = Dispatcher<FieldType, RoundingMode::Trunc,
TieBreakingMode::Auto>::apply_vec_const(col_general,
scale_arg);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]

be/src/vec/functions/function_truncate.h:103:

-                 if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
-                     using FieldType = typename DataType::FieldType;
-                     res = Dispatcher<FieldType, RoundingMode::Trunc,
-                                      TieBreakingMode::Auto>::apply_vec_const(col_general,
-                                                                              scale_arg);
-                     return true;
-                 }
- 
-                 return false;
+                 return IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>;

using FieldType = typename DataType::FieldType;
res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
apply_vec_const(column_general.column.get(), scale_arg);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]

be/src/vec/functions/function_truncate.h:145:

-                 if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
-                     using FieldType = typename DataType::FieldType;
-                     res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
-                             apply_vec_const(column_general.column.get(), scale_arg);
-                     return true;
-                 }
- 
-                 return false;
+                 return IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>;

using FieldType = typename DataType::FieldType;
res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
apply_const_vec(&const_col_general, column_scale.column.get());
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]

be/src/vec/functions/function_truncate.h:180:

-                 if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
-                     using FieldType = typename DataType::FieldType;
-                     res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
-                             apply_const_vec(&const_col_general, column_scale.column.get());
-                     return true;
-                 }
- 
-                 return false;
+                 return IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>;

using FieldType = typename DataType::FieldType;
res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
apply_vec_vec(column_general.column.get(), column_scale.column.get());
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]

be/src/vec/functions/function_truncate.h:213:

-                 if constexpr (IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>) {
-                     using FieldType = typename DataType::FieldType;
-                     res = Dispatcher<FieldType, RoundingMode::Trunc, TieBreakingMode::Auto>::
-                             apply_vec_vec(column_general.column.get(), column_scale.column.get());
-                     return true;
-                 }
-                 return false;
+                 return IsDataTypeNumber<DataType> || IsDataTypeDecimal<DataType>;

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 35.59% (8857/24889)
Line Coverage: 27.34% (72736/266078)
Region Coverage: 26.52% (37628/141884)
Branch Coverage: 23.33% (19188/82252)
Coverage Report: http://coverage.selectdb-in.cc/coverage/f93f5895e30ab69fd8ebb0ef025cdb52e1011f8b_f93f5895e30ab69fd8ebb0ef025cdb52e1011f8b/report/index.html

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17687	4271	4174	4174
q2	1987	180	170	170
q3	10494	1244	1394	1244
q4	10211	900	1063	900
q5	7506	2966	2919	2919
q6	217	136	132	132
q7	1086	612	623	612
q8	9396	2035	2033	2033
q9	6706	6201	6155	6155
q10	8463	3497	3469	3469
q11	420	239	234	234
q12	390	233	213	213
q13	17777	2871	2887	2871
q14	278	241	242	241
q15	526	488	475	475
q16	457	382	384	382
q17	958	916	919	916
q18	7260	6439	6409	6409
q19	1606	1555	1528	1528
q20	599	336	316	316
q21	3568	3126	3075	3075
q22	359	310	316	310
Total cold run time: 107951 ms
Total hot run time: 38778 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4103	4097	4068	4068
q2	325	217	216	216
q3	2954	2974	2938	2938
q4	1866	1836	1838	1836
q5	5245	5210	5207	5207
q6	209	127	129	127
q7	2226	1802	1804	1802
q8	3212	3279	3306	3279
q9	8457	8431	8464	8431
q10	3729	3792	3793	3792
q11	540	449	455	449
q12	702	574	551	551
q13	16804	2908	2917	2908
q14	286	262	275	262
q15	518	474	477	474
q16	438	416	397	397
q17	1688	1690	1690	1690
q18	7672	7813	7525	7525
q19	1729	1688	1688	1688
q20	2063	1874	1837	1837
q21	5339	4970	4977	4970
q22	511	456	454	454
Total cold run time: 70616 ms
Total hot run time: 54901 ms

Copy link
Contributor

@zclllyybb zclllyybb left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Apr 2, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2024

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

@zhangstar333 zhangstar333 merged commit a36e088 into apache:master Apr 2, 2024
@zhiqiang-hhhh zhiqiang-hhhh deleted the opt-truncate branch April 2, 2024 06:59
zhiqiang-hhhh added a commit to zhiqiang-hhhh/doris that referenced this pull request Apr 2, 2024
…ument (apache#32746)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@xiaokang xiaokang removed the dev/2.0.x label Apr 3, 2024
yiguolei pushed a commit that referenced this pull request Apr 10, 2024
…ument (#32746)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
yiguolei pushed a commit that referenced this pull request Apr 10, 2024
…ument (#32746)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@yiguolei yiguolei mentioned this pull request Apr 26, 2024
1 task
924060929 added a commit that referenced this pull request Aug 5, 2025
1. fix compute wrong scale of
round_bankers/truncate/round/dround/floor/dfloor/ceil/dceil, introduced
by #32746 and #34391

this sql will throw exception:
```sql
create table test_round_bankers_scale(
  id bigint,
  a decimal(32,6)
)
properties ("replication_num" = "1");

select round_bankers(a, 1-2)
from test_round_bankers_scale
order by id

(1105, 'errCode = 2, detailMessage = (172.20.48.119)[INTERNAL_ERROR]output type not match expr type  , col name  , expected type Nullable(Decimal(32, 6)) , real type Nullable(Decimal(32, 0))')
```

The scale of return type of the round_bankers function depends on the
type of its arguments. If the second argument is an integer constant,
that constant is used as the scale. If it is not a constant, the scale
of the first argument is used instead. This leads to a problem: for
expressions like `1 - 2`, the scale used in the computation differs
before and after constant folding, which can cause the Backend to throw
an exception: type mismatch

So we need to fold the arguments into constants before binding the
function, to ensure that the scale will not change

2. keep idempotent of function signature. when we select a signature for
a function, we should not change signature after do some rewrite
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. reviewed usercase Important user case type label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants