Skip to content

Conversation

@924060929
Copy link
Contributor

Proposed changes

  1. dry run query should not use sql cache
  2. fix test sql cache in cloud mode
  3. enable cache OneRowRelation and EmptyRelation in frontend to skip parse sql

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

@924060929
Copy link
Contributor Author

run buildall

@924060929
Copy link
Contributor Author

run buildall

@924060929
Copy link
Contributor Author

run buildall

morrySnow
morrySnow previously approved these changes Apr 17, 2024
@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added approved Indicates a PR has been approved by one committer. reviewed labels Apr 17, 2024
@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17708	5214	4498	4498
q2	2004	179	180	179
q3	10551	1116	1214	1116
q4	10244	875	763	763
q5	7516	2704	2681	2681
q6	216	130	132	130
q7	1022	603	571	571
q8	9241	2075	2043	2043
q9	7420	6574	6517	6517
q10	8435	3504	3465	3465
q11	443	232	226	226
q12	413	210	215	210
q13	18690	2938	2922	2922
q14	273	246	234	234
q15	511	474	473	473
q16	558	415	393	393
q17	962	696	663	663
q18	7417	6828	6669	6669
q19	7744	1503	1513	1503
q20	641	305	306	305
q21	3374	2711	2859	2711
q22	361	306	308	306
Total cold run time: 115744 ms
Total hot run time: 38578 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4294	4240	4179	4179
q2	362	284	275	275
q3	2994	2683	2729	2683
q4	1850	1612	1531	1531
q5	5347	5358	5270	5270
q6	211	121	124	121
q7	2210	1871	1872	1871
q8	3211	3310	3336	3310
q9	8547	8508	8547	8508
q10	3943	3678	3681	3678
q11	572	467	466	466
q12	748	581	584	581
q13	16431	2954	2938	2938
q14	297	272	272	272
q15	514	457	469	457
q16	471	408	407	407
q17	1750	1456	1472	1456
q18	8060	7824	8063	7824
q19	1677	1611	1612	1611
q20	2023	1850	1867	1850
q21	9564	4930	4886	4886
q22	540	486	489	486
Total cold run time: 75616 ms
Total hot run time: 54660 ms

@924060929
Copy link
Contributor Author

run fe ut

@924060929
Copy link
Contributor Author

run buildall

@github-actions github-actions bot removed the approved Indicates a PR has been approved by one committer. label Apr 17, 2024
@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17598	4351	4180	4180
q2	2016	196	186	186
q3	10436	1179	1154	1154
q4	10182	791	796	791
q5	7557	2703	2591	2591
q6	217	134	133	133
q7	996	607	596	596
q8	9212	2056	2028	2028
q9	7217	6605	6522	6522
q10	8464	3497	3514	3497
q11	436	254	233	233
q12	454	218	218	218
q13	17767	2975	2944	2944
q14	273	223	242	223
q15	521	484	493	484
q16	524	377	372	372
q17	946	664	658	658
q18	7379	6756	6716	6716
q19	5012	1548	1497	1497
q20	643	309	310	309
q21	3441	2795	2823	2795
q22	363	308	301	301
Total cold run time: 111654 ms
Total hot run time: 38428 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4274	4205	4182	4182
q2	382	255	268	255
q3	3014	2767	2754	2754
q4	1917	1564	1549	1549
q5	5378	5355	5316	5316
q6	203	125	124	124
q7	2244	1828	1855	1828
q8	3176	3346	3380	3346
q9	8623	8605	8569	8569
q10	4075	3883	3914	3883
q11	632	516	514	514
q12	777	615	622	615
q13	18530	3223	3257	3223
q14	324	294	279	279
q15	536	512	474	474
q16	484	441	435	435
q17	1817	1525	1492	1492
q18	8102	8049	7760	7760
q19	1668	1536	1616	1536
q20	2050	1847	1843	1843
q21	10357	4964	4994	4964
q22	547	458	458	458
Total cold run time: 79110 ms
Total hot run time: 55399 ms

@doris-robot
Copy link

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

query1	896	369	364	364
query2	6183	2791	2344	2344
query3	6656	202	198	198
query4	23116	21565	21339	21339
query5	4007	404	407	404
query6	266	188	183	183
query7	4591	296	298	296
query8	226	172	172	172
query9	8434	2367	2314	2314
query10	416	251	251	251
query11	14893	14267	14225	14225
query12	133	87	85	85
query13	1628	359	357	357
query14	9994	7633	7662	7633
query15	242	183	185	183
query16	7929	270	272	270
query17	1925	597	565	565
query18	1999	283	259	259
query19	194	147	147	147
query20	88	82	83	82
query21	199	124	123	123
query22	4955	4818	4900	4818
query23	33652	33150	33179	33150
query24	8212	2995	3026	2995
query25	597	388	376	376
query26	742	164	162	162
query27	2373	365	369	365
query28	5870	2130	2100	2100
query29	857	632	618	618
query30	280	187	179	179
query31	991	738	783	738
query32	97	55	51	51
query33	617	257	268	257
query34	882	498	515	498
query35	811	711	720	711
query36	1094	928	913	913
query37	110	70	70	70
query38	3500	3413	3311	3311
query39	1618	1633	1579	1579
query40	173	133	126	126
query41	48	41	44	41
query42	104	96	97	96
query43	600	547	538	538
query44	1102	728	736	728
query45	299	273	281	273
query46	1081	785	767	767
query47	2065	1982	1956	1956
query48	385	302	311	302
query49	842	375	379	375
query50	775	402	397	397
query51	6956	6676	6728	6676
query52	113	86	95	86
query53	343	278	280	278
query54	253	229	227	227
query55	74	69	70	69
query56	235	218	221	218
query57	1215	1090	1117	1090
query58	215	194	190	190
query59	3355	3365	3450	3365
query60	248	233	233	233
query61	89	87	92	87
query62	584	451	452	451
query63	312	275	276	275
query64	4623	4140	3865	3865
query65	3044	2998	3016	2998
query66	742	328	331	328
query67	15455	14903	15147	14903
query68	5153	536	537	536
query69	471	295	307	295
query70	1191	1071	1122	1071
query71	1385	1264	1266	1264
query72	6296	2664	2418	2418
query73	710	320	319	319
query74	6830	6490	6423	6423
query75	3322	2664	2671	2664
query76	2978	1018	1061	1018
query77	393	261	261	261
query78	10993	10214	10259	10214
query79	3768	519	527	519
query80	1789	458	440	440
query81	507	243	247	243
query82	909	97	96	96
query83	312	225	171	171
query84	272	84	86	84
query85	1649	266	258	258
query86	477	300	306	300
query87	3425	3269	3298	3269
query88	4626	2403	2396	2396
query89	471	379	378	378
query90	1930	186	182	182
query91	123	117	96	96
query92	55	45	47	45
query93	5388	509	494	494
query94	1141	182	184	182
query95	394	306	292	292
query96	592	267	261	261
query97	3158	2907	2944	2907
query98	238	214	209	209
query99	1205	855	882	855
Total cold run time: 278754 ms
Total hot run time: 185783 ms

@doris-robot
Copy link

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

query1	0.04	0.03	0.04
query2	0.08	0.04	0.04
query3	0.22	0.05	0.05
query4	1.67	0.08	0.09
query5	0.49	0.52	0.50
query6	1.47	0.71	0.72
query7	0.02	0.01	0.01
query8	0.05	0.04	0.04
query9	0.56	0.51	0.50
query10	0.55	0.57	0.55
query11	0.15	0.11	0.11
query12	0.14	0.12	0.11
query13	0.60	0.58	0.59
query14	0.76	0.77	0.78
query15	0.82	0.81	0.80
query16	0.36	0.36	0.36
query17	0.97	1.02	1.02
query18	0.21	0.27	0.22
query19	1.88	1.77	1.81
query20	0.01	0.01	0.01
query21	15.41	0.66	0.66
query22	4.05	7.12	2.22
query23	18.29	1.39	1.22
query24	1.98	0.21	0.23
query25	0.15	0.09	0.07
query26	0.26	0.16	0.16
query27	0.08	0.07	0.08
query28	13.34	0.99	0.98
query29	12.56	3.30	3.30
query30	0.26	0.08	0.05
query31	2.85	0.38	0.37
query32	3.28	0.45	0.46
query33	2.78	2.85	2.81
query34	17.19	4.40	4.46
query35	4.46	4.44	4.50
query36	0.65	0.47	0.45
query37	0.18	0.15	0.15
query38	0.15	0.14	0.14
query39	0.04	0.04	0.03
query40	0.18	0.14	0.14
query41	0.09	0.06	0.04
query42	0.06	0.05	0.04
query43	0.04	0.03	0.04
Total cold run time: 109.38 s
Total hot run time: 30.69 s

@doris-robot
Copy link

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

Load test result on commit ad4c26a6827e8394f0bce04b01a87bd7e9c99a7b 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:      32 seconds loaded 861443392 Bytes, about 25 MB/s
Insert into select:       13.6 seconds inserted 10000000 Rows, about 735K ops/s

@924060929
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17724	4278	4264	4264
q2	2012	190	192	190
q3	10705	1184	1222	1184
q4	10783	775	842	775
q5	7881	2756	2627	2627
q6	220	134	134	134
q7	1044	654	601	601
q8	9254	2085	2079	2079
q9	7525	6696	6679	6679
q10	8634	3622	3493	3493
q11	466	239	233	233
q12	484	231	220	220
q13	17938	2937	2966	2937
q14	285	219	241	219
q15	535	489	477	477
q16	530	415	389	389
q17	986	698	649	649
q18	7505	6817	6653	6653
q19	3294	1526	1473	1473
q20	636	322	307	307
q21	3507	2722	2802	2722
q22	379	300	312	300
Total cold run time: 112327 ms
Total hot run time: 38605 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4381	4202	4245	4202
q2	370	265	269	265
q3	3011	2729	2751	2729
q4	1862	1574	1584	1574
q5	5332	5371	5323	5323
q6	215	123	128	123
q7	2255	1858	1874	1858
q8	3256	3383	3358	3358
q9	8566	8562	8617	8562
q10	3903	3707	3656	3656
q11	573	484	476	476
q12	779	579	581	579
q13	17404	2969	2937	2937
q14	312	262	285	262
q15	514	470	467	467
q16	462	419	422	419
q17	1777	1476	1476	1476
q18	7773	7543	7327	7327
q19	1630	1566	1511	1511
q20	1949	1759	1765	1759
q21	4999	4826	4904	4826
q22	523	437	443	437
Total cold run time: 71846 ms
Total hot run time: 54126 ms

@doris-robot
Copy link

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

query1	921	373	365	365
query2	6656	2529	2451	2451
query3	6659	202	209	202
query4	25149	21288	21256	21256
query5	4125	406	420	406
query6	268	171	170	170
query7	4577	284	281	281
query8	225	169	163	163
query9	8489	2350	2363	2350
query10	581	275	273	273
query11	14756	14127	14197	14127
query12	135	89	82	82
query13	1624	356	371	356
query14	9065	7967	7452	7452
query15	259	180	187	180
query16	8112	258	258	258
query17	1922	568	544	544
query18	2033	274	261	261
query19	216	149	147	147
query20	90	83	86	83
query21	201	125	127	125
query22	5021	4848	4822	4822
query23	33782	32893	33040	32893
query24	10975	2954	2919	2919
query25	616	359	378	359
query26	1621	146	147	146
query27	3000	307	315	307
query28	7300	2028	2026	2026
query29	977	608	585	585
query30	303	172	169	169
query31	954	707	712	707
query32	85	51	52	51
query33	730	242	235	235
query34	1064	473	473	473
query35	842	698	674	674
query36	1068	872	906	872
query37	130	70	70	70
query38	3306	3196	3149	3149
query39	1559	1506	1515	1506
query40	275	127	121	121
query41	45	39	41	39
query42	104	94	99	94
query43	576	531	527	527
query44	1192	710	710	710
query45	267	270	267	267
query46	1077	736	736	736
query47	1935	1835	1868	1835
query48	363	322	296	296
query49	1161	369	375	369
query50	751	381	389	381
query51	6679	6474	6549	6474
query52	104	85	89	85
query53	351	285	280	280
query54	296	226	219	219
query55	76	68	69	68
query56	241	226	223	223
query57	1209	1127	1129	1127
query58	214	190	208	190
query59	3373	3220	3422	3220
query60	250	229	235	229
query61	92	85	89	85
query62	678	450	445	445
query63	303	273	278	273
query64	6254	3652	3828	3652
query65	3039	3014	3000	3000
query66	1392	336	329	329
query67	15748	15402	14948	14948
query68	5182	529	530	529
query69	490	308	294	294
query70	1181	1112	1143	1112
query71	1376	1262	1257	1257
query72	6638	2646	2427	2427
query73	702	320	328	320
query74	6799	6446	6342	6342
query75	3382	2692	2624	2624
query76	3300	924	1003	924
query77	387	259	256	256
query78	10930	10162	10170	10162
query79	4455	531	512	512
query80	1756	422	435	422
query81	541	247	248	247
query82	1045	103	94	94
query83	263	175	173	173
query84	269	89	89	89
query85	2124	325	254	254
query86	482	285	279	279
query87	3476	3256	3252	3252
query88	4527	2408	2392	2392
query89	502	363	367	363
query90	2003	178	183	178
query91	121	98	95	95
query92	59	47	48	47
query93	5288	522	502	502
query94	1232	181	181	181
query95	390	299	304	299
query96	605	268	264	264
query97	3133	2923	2924	2923
query98	240	220	216	216
query99	1258	892	856	856
Total cold run time: 291577 ms
Total hot run time: 183602 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.03
query2	0.08	0.04	0.04
query3	0.24	0.05	0.05
query4	1.68	0.07	0.07
query5	0.49	0.49	0.52
query6	1.48	0.72	0.72
query7	0.02	0.01	0.01
query8	0.06	0.04	0.04
query9	0.54	0.49	0.49
query10	0.56	0.56	0.55
query11	0.15	0.11	0.12
query12	0.15	0.12	0.12
query13	0.62	0.59	0.59
query14	0.74	0.78	0.77
query15	0.82	0.80	0.80
query16	0.35	0.36	0.35
query17	0.94	1.01	1.00
query18	0.21	0.24	0.20
query19	1.80	1.69	1.72
query20	0.01	0.01	0.02
query21	15.42	0.67	0.65
query22	4.09	7.09	2.14
query23	18.32	1.41	1.26
query24	1.87	0.23	0.19
query25	0.13	0.09	0.08
query26	0.25	0.17	0.17
query27	0.07	0.08	0.07
query28	13.33	0.99	0.98
query29	12.61	3.26	3.25
query30	0.25	0.06	0.05
query31	2.86	0.38	0.38
query32	3.29	0.47	0.46
query33	2.78	2.82	2.82
query34	16.95	4.42	4.48
query35	4.45	4.45	4.46
query36	0.65	0.46	0.47
query37	0.18	0.16	0.16
query38	0.15	0.14	0.15
query39	0.04	0.04	0.03
query40	0.18	0.14	0.14
query41	0.09	0.04	0.04
query42	0.05	0.05	0.04
query43	0.04	0.04	0.04
Total cold run time: 109.03 s
Total hot run time: 30.55 s

@doris-robot
Copy link

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

Load test result on commit ad4c26a6827e8394f0bce04b01a87bd7e9c99a7b 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:       13.5 seconds inserted 10000000 Rows, about 740K ops/s

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

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

Copy link
Contributor

@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

@924060929 924060929 merged commit dc80ecf into apache:master Apr 18, 2024
@924060929 924060929 deleted the dry_run_with_sql_cache branch April 18, 2024 02:43
924060929 added a commit to 924060929/incubator-doris that referenced this pull request Apr 18, 2024
1. dry run query should not use sql cache
2. fix test sql cache in cloud mode
3. enable cache OneRowRelation and EmptyRelation in frontend to skip parse sql

(cherry picked from commit dc80ecf)
yiguolei pushed a commit that referenced this pull request Apr 18, 2024
…ugs (#33852)

* [enhancement](Nereids) Enable parse sql from sql cache (#33262)

Before this pr, the query must pass through parser, analyzer, rewriter, optimizer and translator, then we can check whether this query can use sql cache, if the query is too long, or the number of join tables too big, the plan time usually >= 500ms.

This pr reduce this time by skip the fashion plan path, because we can reuse the previous physical plan and query result if no any changed. In some cases we should not parse sql from sql cache, e.g. table structure changed, data changed, user policies changed, privileges changed, contains non-deterministic functions, and user variables changed.

In my test case: query a view which has lots of join and union, and the tables has empty partition, the query latency is about 3ms. if not parse sql from sql cache, the plan time is about 550ms

## Features
1. use Config.sql_cache_manage_num to control how many sql cache be reused in on fe
2. if explain plan appear some plans contains `LogicalSqlCache` or `PhysicalSqlCache`, it means the query can use sql cache, like this:
```sql
mysql> set enable_sql_cache=true;
Query OK, 0 rows affected (0.00 sec)

mysql> explain physical plan select * from test.t;
+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                  |
+----------------------------------------------------------------------------------+
| cost = 3.135                                                                     |
| PhysicalResultSink[53] ( outputExprs=[c1#0, c2#1] )                              |
| +--PhysicalDistribute[50]@0 ( stats=3, distributionSpec=DistributionSpecGather ) |
|    +--PhysicalOlapScan[t]@0 ( stats=3 )                                          |
+----------------------------------------------------------------------------------+
4 rows in set (0.02 sec)

mysql> select * from test.t;
+------+------+
| c1   | c2   |
+------+------+
|    1 |    2 |
|   -2 |   -2 |
| NULL |   30 |
+------+------+
3 rows in set (0.05 sec)

mysql> explain physical plan select * from test.t;
+-------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                           |
+-------------------------------------------------------------------------------------------+
| cost = 0.0                                                                                |
| PhysicalSqlCache[2] ( queryId=78511f515cda466b-95385d892d6c68d0, backend=127.0.0.1:9050 ) |
| +--PhysicalResultSink[52] ( outputExprs=[c1#0, c2#1] )                                    |
|    +--PhysicalDistribute[49]@0 ( stats=3, distributionSpec=DistributionSpecGather )       |
|       +--PhysicalOlapScan[t]@0 ( stats=3 )                                                |
+-------------------------------------------------------------------------------------------+
5 rows in set (0.01 sec)
```

(cherry picked from commit 03bd2a3)

* fix

* [fix](Nereids) fix some sql cache consistence bug between multiple frontends (#33722)

fix some sql cache consistence bug between multiple frontends which introduced by [enhancement](Nereids) Enable parse sql from sql cache #33262, fix by use row policy as the part of sql cache key.
support dynamic update the num of fe manage sql cache key

(cherry picked from commit 90abd76)

* [fix](Nereids) fix bug of dry run query with sql cache (#33799)

1. dry run query should not use sql cache
2. fix test sql cache in cloud mode
3. enable cache OneRowRelation and EmptyRelation in frontend to skip parse sql

(cherry picked from commit dc80ecf)

* remove cloud mode
924060929 added a commit to 924060929/incubator-doris that referenced this pull request Apr 19, 2024
1. dry run query should not use sql cache
2. fix test sql cache in cloud mode
3. enable cache OneRowRelation and EmptyRelation in frontend to skip parse sql

(cherry picked from commit dc80ecf)
yiguolei pushed a commit that referenced this pull request Apr 19, 2024
…ugs (#33867)

* [enhancement](Nereids) Enable parse sql from sql cache (#33262)

Before this pr, the query must pass through parser, analyzer, rewriter, optimizer and translator, then we can check whether this query can use sql cache, if the query is too long, or the number of join tables too big, the plan time usually >= 500ms.

This pr reduce this time by skip the fashion plan path, because we can reuse the previous physical plan and query result if no any changed. In some cases we should not parse sql from sql cache, e.g. table structure changed, data changed, user policies changed, privileges changed, contains non-deterministic functions, and user variables changed.

In my test case: query a view which has lots of join and union, and the tables has empty partition, the query latency is about 3ms. if not parse sql from sql cache, the plan time is about 550ms

## Features
1. use Config.sql_cache_manage_num to control how many sql cache be reused in on fe
2. if explain plan appear some plans contains `LogicalSqlCache` or `PhysicalSqlCache`, it means the query can use sql cache, like this:
```sql
mysql> set enable_sql_cache=true;
Query OK, 0 rows affected (0.00 sec)

mysql> explain physical plan select * from test.t;
+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                  |
+----------------------------------------------------------------------------------+
| cost = 3.135                                                                     |
| PhysicalResultSink[53] ( outputExprs=[c1#0, c2#1] )                              |
| +--PhysicalDistribute[50]@0 ( stats=3, distributionSpec=DistributionSpecGather ) |
|    +--PhysicalOlapScan[t]@0 ( stats=3 )                                          |
+----------------------------------------------------------------------------------+
4 rows in set (0.02 sec)

mysql> select * from test.t;
+------+------+
| c1   | c2   |
+------+------+
|    1 |    2 |
|   -2 |   -2 |
| NULL |   30 |
+------+------+
3 rows in set (0.05 sec)

mysql> explain physical plan select * from test.t;
+-------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                           |
+-------------------------------------------------------------------------------------------+
| cost = 0.0                                                                                |
| PhysicalSqlCache[2] ( queryId=78511f515cda466b-95385d892d6c68d0, backend=127.0.0.1:9050 ) |
| +--PhysicalResultSink[52] ( outputExprs=[c1#0, c2#1] )                                    |
|    +--PhysicalDistribute[49]@0 ( stats=3, distributionSpec=DistributionSpecGather )       |
|       +--PhysicalOlapScan[t]@0 ( stats=3 )                                                |
+-------------------------------------------------------------------------------------------+
5 rows in set (0.01 sec)
```

(cherry picked from commit 03bd2a3)

* fix

* [fix](Nereids) fix some sql cache consistence bug between multiple frontends (#33722)

fix some sql cache consistence bug between multiple frontends which introduced by [enhancement](Nereids) Enable parse sql from sql cache #33262, fix by use row policy as the part of sql cache key.
support dynamic update the num of fe manage sql cache key

(cherry picked from commit 90abd76)

* [fix](Nereids) fix bug of dry run query with sql cache (#33799)

1. dry run query should not use sql cache
2. fix test sql cache in cloud mode
3. enable cache OneRowRelation and EmptyRelation in frontend to skip parse sql

(cherry picked from commit dc80ecf)

* remove cloud mode

* remove @NotNull
yiguolei pushed a commit that referenced this pull request Apr 19, 2024
…ugs (#33867)

* [enhancement](Nereids) Enable parse sql from sql cache (#33262)

Before this pr, the query must pass through parser, analyzer, rewriter, optimizer and translator, then we can check whether this query can use sql cache, if the query is too long, or the number of join tables too big, the plan time usually >= 500ms.

This pr reduce this time by skip the fashion plan path, because we can reuse the previous physical plan and query result if no any changed. In some cases we should not parse sql from sql cache, e.g. table structure changed, data changed, user policies changed, privileges changed, contains non-deterministic functions, and user variables changed.

In my test case: query a view which has lots of join and union, and the tables has empty partition, the query latency is about 3ms. if not parse sql from sql cache, the plan time is about 550ms

## Features
1. use Config.sql_cache_manage_num to control how many sql cache be reused in on fe
2. if explain plan appear some plans contains `LogicalSqlCache` or `PhysicalSqlCache`, it means the query can use sql cache, like this:
```sql
mysql> set enable_sql_cache=true;
Query OK, 0 rows affected (0.00 sec)

mysql> explain physical plan select * from test.t;
+----------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                  |
+----------------------------------------------------------------------------------+
| cost = 3.135                                                                     |
| PhysicalResultSink[53] ( outputExprs=[c1#0, c2#1] )                              |
| +--PhysicalDistribute[50]@0 ( stats=3, distributionSpec=DistributionSpecGather ) |
|    +--PhysicalOlapScan[t]@0 ( stats=3 )                                          |
+----------------------------------------------------------------------------------+
4 rows in set (0.02 sec)

mysql> select * from test.t;
+------+------+
| c1   | c2   |
+------+------+
|    1 |    2 |
|   -2 |   -2 |
| NULL |   30 |
+------+------+
3 rows in set (0.05 sec)

mysql> explain physical plan select * from test.t;
+-------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                           |
+-------------------------------------------------------------------------------------------+
| cost = 0.0                                                                                |
| PhysicalSqlCache[2] ( queryId=78511f515cda466b-95385d892d6c68d0, backend=127.0.0.1:9050 ) |
| +--PhysicalResultSink[52] ( outputExprs=[c1#0, c2#1] )                                    |
|    +--PhysicalDistribute[49]@0 ( stats=3, distributionSpec=DistributionSpecGather )       |
|       +--PhysicalOlapScan[t]@0 ( stats=3 )                                                |
+-------------------------------------------------------------------------------------------+
5 rows in set (0.01 sec)
```

(cherry picked from commit 03bd2a3)

* fix

* [fix](Nereids) fix some sql cache consistence bug between multiple frontends (#33722)

fix some sql cache consistence bug between multiple frontends which introduced by [enhancement](Nereids) Enable parse sql from sql cache #33262, fix by use row policy as the part of sql cache key.
support dynamic update the num of fe manage sql cache key

(cherry picked from commit 90abd76)

* [fix](Nereids) fix bug of dry run query with sql cache (#33799)

1. dry run query should not use sql cache
2. fix test sql cache in cloud mode
3. enable cache OneRowRelation and EmptyRelation in frontend to skip parse sql

(cherry picked from commit dc80ecf)

* remove cloud mode

* remove @NotNull
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