Skip to content

Conversation

@hubgeter
Copy link
Contributor

What problem does this PR solve?

Related PR: #36053 && #53209

Problem Summary:

Fixed the issue that the result of dry_run_query=true is wrong in multi-be scenarios (the number of rows is less)

I think this may be related to the multi result sink introduced in pr #36053 && #53209.
Reason:

vmysql_result_writer.cpp
GetResultBatchCtx::on_close() {
    ...
    statistics->set_returned_rows(returned_rows);  // Set only once per result_writer.
    ...
}
if (connectContext != null && connectContext.getSessionVariable().dryRunQuery) {
    if (resultBatch.isEos()) {     // This will only be counted once. 
        numReceivedRows += resultBatch.getQueryStatistics().getReturnedRows();
    }
} else if (resultBatch.getBatch() != null) {
    numReceivedRows += resultBatch.getBatch().getRowsSize();
}

If there are multiple be, there will be multiple result sinks, and each result sink will update its own row count at the end. Since resultBatch.isEos() is only triggered once, the row count information is less.

Release note

None

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

@hubgeter
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17575	5224	5037	5037
q2	1938	309	213	213
q3	10253	1284	700	700
q4	10224	1003	506	506
q5	7515	2426	2322	2322
q6	189	188	140	140
q7	925	776	623	623
q8	9345	1313	1099	1099
q9	7644	5166	5106	5106
q10	6966	2380	1965	1965
q11	494	304	291	291
q12	357	368	243	243
q13	17780	3646	3126	3126
q14	247	243	247	243
q15	608	519	518	518
q16	443	446	404	404
q17	603	867	374	374
q18	7560	7235	7081	7081
q19	1576	982	609	609
q20	350	338	229	229
q21	3734	3133	2388	2388
q22	1071	1064	1014	1014
Total cold run time: 107397 ms
Total hot run time: 34231 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5349	5090	5116	5090
q2	260	350	242	242
q3	2171	2668	2292	2292
q4	1355	1752	1334	1334
q5	4344	4428	4507	4428
q6	214	175	137	137
q7	2110	1948	1808	1808
q8	2664	2500	2442	2442
q9	7295	7333	7273	7273
q10	3097	3351	2898	2898
q11	569	537	507	507
q12	692	755	618	618
q13	3681	3996	3581	3581
q14	312	334	326	326
q15	557	510	507	507
q16	487	505	464	464
q17	1214	1526	1441	1441
q18	8101	7999	7515	7515
q19	833	800	993	800
q20	1946	2035	1929	1929
q21	4940	4440	4325	4325
q22	1090	1036	1003	1003
Total cold run time: 53281 ms
Total hot run time: 50960 ms

@doris-robot
Copy link

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

query1	992	405	414	405
query2	6573	1655	1650	1650
query3	6743	234	223	223
query4	27116	23506	23697	23506
query5	4497	751	591	591
query6	330	251	231	231
query7	4653	508	308	308
query8	385	343	337	337
query9	8660	2911	2903	2903
query10	513	381	329	329
query11	15960	15083	14883	14883
query12	176	140	135	135
query13	1687	603	453	453
query14	9763	6068	5893	5893
query15	212	217	177	177
query16	7668	618	486	486
query17	1344	722	597	597
query18	2064	448	332	332
query19	210	209	172	172
query20	145	137	133	133
query21	236	144	127	127
query22	4139	4120	4248	4120
query23	34817	33257	33371	33257
query24	8142	2450	2431	2431
query25	548	511	433	433
query26	836	281	171	171
query27	2703	533	359	359
query28	4369	2206	2161	2161
query29	679	592	476	476
query30	300	237	205	205
query31	972	877	824	824
query32	101	94	100	94
query33	580	428	374	374
query34	823	855	542	542
query35	808	863	801	801
query36	963	1025	921	921
query37	137	117	95	95
query38	4199	4144	4141	4141
query39	1540	1483	1478	1478
query40	238	146	131	131
query41	108	104	100	100
query42	130	124	133	124
query43	512	523	480	480
query44	1369	879	871	871
query45	191	188	189	188
query46	851	1027	662	662
query47	1791	1911	1763	1763
query48	433	458	333	333
query49	753	563	482	482
query50	727	720	431	431
query51	5627	5589	5696	5589
query52	126	118	112	112
query53	253	290	219	219
query54	630	628	565	565
query55	94	97	101	97
query56	371	350	342	342
query57	1225	1214	1187	1187
query58	354	314	328	314
query59	2538	2609	2508	2508
query60	381	382	378	378
query61	155	156	152	152
query62	827	737	675	675
query63	256	226	224	224
query64	3623	1102	750	750
query65	4328	4237	4187	4187
query66	1050	589	524	524
query67	16049	15899	15584	15584
query68	7936	905	536	536
query69	532	367	313	313
query70	1251	1102	1205	1102
query71	500	370	341	341
query72	5809	4708	4890	4708
query73	721	663	381	381
query74	9022	9264	8694	8694
query75	3954	3144	2672	2672
query76	3626	1146	759	759
query77	863	468	394	394
query78	10030	10197	9387	9387
query79	3042	843	591	591
query80	742	604	547	547
query81	500	275	244	244
query82	466	148	117	117
query83	314	291	281	281
query84	319	122	99	99
query85	811	399	365	365
query86	351	357	327	327
query87	4461	4418	4391	4391
query88	3692	2409	2368	2368
query89	433	347	305	305
query90	1967	240	242	240
query91	161	161	129	129
query92	97	84	77	77
query93	2047	941	595	595
query94	697	454	324	324
query95	413	362	331	331
query96	513	592	291	291
query97	2766	2759	2681	2681
query98	267	237	217	217
query99	1517	1420	1286	1286
Total cold run time: 281393 ms
Total hot run time: 190819 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.03
query2	0.08	0.04	0.05
query3	0.25	0.07	0.07
query4	1.62	0.11	0.11
query5	0.41	0.42	0.41
query6	1.18	0.68	0.67
query7	0.03	0.03	0.02
query8	0.05	0.04	0.04
query9	0.60	0.52	0.50
query10	0.58	0.59	0.57
query11	0.16	0.11	0.12
query12	0.16	0.12	0.12
query13	0.64	0.61	0.61
query14	0.80	0.82	0.82
query15	0.90	0.88	0.87
query16	0.40	0.39	0.40
query17	1.09	1.04	1.06
query18	0.22	0.21	0.22
query19	1.92	1.82	1.82
query20	0.02	0.01	0.02
query21	15.39	0.94	0.54
query22	0.79	1.02	0.73
query23	14.99	1.39	0.64
query24	7.42	1.19	0.53
query25	0.54	0.23	0.17
query26	0.52	0.17	0.14
query27	0.05	0.06	0.05
query28	9.86	0.93	0.46
query29	12.59	4.00	3.30
query30	3.21	3.13	3.10
query31	2.82	0.59	0.40
query32	3.26	0.57	0.49
query33	3.03	3.03	3.05
query34	16.07	5.45	4.80
query35	4.88	4.91	4.86
query36	0.70	0.50	0.50
query37	0.10	0.08	0.08
query38	0.06	0.05	0.05
query39	0.04	0.04	0.03
query40	0.18	0.15	0.15
query41	0.09	0.03	0.04
query42	0.05	0.03	0.04
query43	0.04	0.05	0.05
Total cold run time: 107.83 s
Total hot run time: 32.62 s

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Jul 22, 2025
@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.

@BiteTheDDDDt
Copy link
Contributor

Can you add some test case for this problem?

@hubgeter
Copy link
Contributor Author

hubgeter commented Jul 22, 2025

Can you add some test case for this problem?

There is already p2 case.
external_table_p2/hive/test_parquet_complex_cross_page.groovy

// statistics->set_returned_rows(returned_rows);
// In a multi-mysql_result_writer scenario, since each mysql_result_writer will set this rows, in order
// to avoid missing rows when dry_run_query = true, they should all be added up.
numReceivedRows += resultBatch.getQueryStatistics().getReturnedRows();
Copy link
Contributor

Choose a reason for hiding this comment

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

If one backend returns multiple batches, does it will the repeated calculation lead to result row number more than real?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it will happen. returned_rows set by BE will only be increased during the close phase of ResultBlockBuffer. Reference:
src/runtime/result_block_buffer.cpp:ResultBlockBuffer<ResultCtxType>::close(....)

@BiteTheDDDDt BiteTheDDDDt merged commit 99df231 into apache:master Jul 23, 2025
30 of 36 checks passed
w41ter pushed a commit to w41ter/incubator-doris that referenced this pull request Jul 30, 2025
… and dry_run_query=true. (apache#53653)

Related PR: apache#36053 && apache#53209

Problem Summary:

Fixed the issue that the result of `dry_run_query=true` is wrong in
multi-be scenarios (the number of rows is less)

I think this may be related to the multi result sink introduced in pr
apache#36053 && apache#53209.
Reason:
```cpp
vmysql_result_writer.cpp
GetResultBatchCtx::on_close() {
    ...
    statistics->set_returned_rows(returned_rows);  // Set only once per result_writer.
    ...
}
```
``` java
if (connectContext != null && connectContext.getSessionVariable().dryRunQuery) {
    if (resultBatch.isEos()) {     // This will only be counted once. 
        numReceivedRows += resultBatch.getQueryStatistics().getReturnedRows();
    }
} else if (resultBatch.getBatch() != null) {
    numReceivedRows += resultBatch.getBatch().getRowsSize();
}
```
If there are multiple be, there will be multiple result sinks, and each
result sink will update its own row count at the end. Since
`resultBatch.isEos()` is only triggered once, the row count information
is less.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants