Skip to content

Conversation

@924060929
Copy link
Contributor

Proposed changes

  1. 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.
  2. support dynamic update the num of fe manage sql cache key

@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

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	18081	8575	4342	4342
q2	2606	192	201	192
q3	11546	1196	1154	1154
q4	11371	762	772	762
q5	7617	2773	2727	2727
q6	225	135	139	135
q7	1049	624	598	598
q8	9294	2094	2078	2078
q9	7792	6627	6550	6550
q10	8496	3553	3497	3497
q11	439	233	228	228
q12	408	213	218	213
q13	17783	2940	2921	2921
q14	273	224	227	224
q15	514	495	469	469
q16	526	384	382	382
q17	970	681	644	644
q18	7311	6953	6743	6743
q19	5017	1559	1521	1521
q20	642	321	303	303
q21	3485	2901	2743	2743
q22	360	308	323	308
Total cold run time: 115805 ms
Total hot run time: 38734 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4344	4203	4216	4203
q2	364	263	266	263
q3	2955	2667	2694	2667
q4	1830	1564	1551	1551
q5	5365	5317	5295	5295
q6	208	122	122	122
q7	2239	1809	1836	1809
q8	3187	3350	3343	3343
q9	8624	8576	8591	8576
q10	3838	3723	3680	3680
q11	581	505	457	457
q12	736	580	610	580
q13	16228	2898	2895	2895
q14	300	271	265	265
q15	507	474	483	474
q16	466	410	423	410
q17	1766	1471	1450	1450
q18	7580	7546	7356	7356
q19	1624	1475	1506	1475
q20	1980	1751	1717	1717
q21	4819	4654	4732	4654
q22	516	465	466	465
Total cold run time: 70057 ms
Total hot run time: 53707 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 183943 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 46b8fec1a92ea118da1d6937c1abf647c9fdc9bf, data reload: false

query1	914	362	373	362
query2	6488	2559	2331	2331
query3	6645	200	213	200
query4	27930	21245	21308	21245
query5	4190	410	424	410
query6	270	174	172	172
query7	4586	280	288	280
query8	223	171	180	171
query9	8458	2346	2332	2332
query10	572	238	253	238
query11	14807	14197	14204	14197
query12	142	87	85	85
query13	1631	360	362	360
query14	9888	7915	7534	7534
query15	266	200	181	181
query16	8190	265	278	265
query17	1898	570	541	541
query18	2103	267	262	262
query19	315	143	147	143
query20	92	86	85	85
query21	200	131	124	124
query22	5031	4841	4879	4841
query23	33931	33289	33117	33117
query24	10918	2894	2876	2876
query25	609	364	370	364
query26	1409	150	143	143
query27	2895	299	312	299
query28	7626	2027	2004	2004
query29	932	609	581	581
query30	306	173	169	169
query31	986	707	715	707
query32	94	53	54	53
query33	738	265	240	240
query34	1025	464	473	464
query35	850	700	705	700
query36	1064	902	937	902
query37	129	65	71	65
query38	3376	3154	3181	3154
query39	1558	1542	1534	1534
query40	245	127	122	122
query41	45	45	44	44
query42	101	94	93	93
query43	555	539	546	539
query44	1245	726	715	715
query45	272	271	259	259
query46	1072	717	724	717
query47	1946	1861	1855	1855
query48	366	308	290	290
query49	1075	372	362	362
query50	756	376	380	376
query51	6702	6580	6663	6580
query52	106	85	90	85
query53	345	271	270	270
query54	294	231	229	229
query55	75	71	75	71
query56	235	231	220	220
query57	1219	1113	1143	1113
query58	214	191	194	191
query59	3363	2895	3100	2895
query60	240	226	247	226
query61	87	100	86	86
query62	656	450	439	439
query63	301	268	270	268
query64	5579	3785	3805	3785
query65	3144	3037	3009	3009
query66	1409	353	327	327
query67	15488	14841	15021	14841
query68	5185	533	548	533
query69	483	316	297	297
query70	1224	1200	1088	1088
query71	1373	1268	1267	1267
query72	6323	2626	2399	2399
query73	694	321	319	319
query74	6853	6470	6549	6470
query75	3353	2630	2637	2630
query76	2802	968	982	968
query77	399	253	255	253
query78	10734	10269	10277	10269
query79	2880	523	517	517
query80	1963	431	426	426
query81	540	244	235	235
query82	751	102	94	94
query83	281	163	162	162
query84	264	93	84	84
query85	2064	318	362	318
query86	477	285	279	279
query87	3477	3252	3300	3252
query88	4071	2405	2405	2405
query89	471	377	362	362
query90	1948	182	187	182
query91	125	94	130	94
query92	64	45	47	45
query93	3086	509	496	496
query94	1252	178	177	177
query95	397	303	304	303
query96	588	273	270	270
query97	3125	2931	2920	2920
query98	237	217	211	211
query99	1219	880	886	880
Total cold run time: 289123 ms
Total hot run time: 183943 ms

@doris-robot
Copy link

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

query1	0.04	0.03	0.03
query2	0.08	0.04	0.04
query3	0.23	0.05	0.05
query4	1.67	0.08	0.08
query5	0.50	0.49	0.50
query6	1.48	0.73	0.72
query7	0.01	0.01	0.01
query8	0.05	0.03	0.04
query9	0.54	0.50	0.49
query10	0.54	0.55	0.56
query11	0.16	0.11	0.11
query12	0.14	0.12	0.12
query13	0.59	0.58	0.58
query14	0.77	0.77	0.77
query15	0.82	0.80	0.80
query16	0.36	0.36	0.35
query17	0.97	1.01	1.03
query18	0.21	0.22	0.24
query19	1.74	1.65	1.68
query20	0.02	0.01	0.01
query21	15.42	0.67	0.65
query22	4.24	7.36	2.21
query23	18.30	1.37	1.37
query24	1.40	0.39	0.22
query25	0.13	0.08	0.09
query26	0.27	0.16	0.16
query27	0.08	0.08	0.08
query28	13.35	1.00	0.97
query29	12.64	3.23	3.25
query30	0.27	0.06	0.06
query31	2.87	0.37	0.38
query32	3.29	0.45	0.46
query33	2.81	2.90	2.82
query34	16.82	4.41	4.38
query35	4.47	4.48	4.45
query36	0.66	0.46	0.46
query37	0.18	0.15	0.15
query38	0.15	0.14	0.14
query39	0.04	0.04	0.03
query40	0.17	0.13	0.14
query41	0.09	0.05	0.04
query42	0.06	0.04	0.05
query43	0.04	0.04	0.04
Total cold run time: 108.67 s
Total hot run time: 30.64 s

@doris-robot
Copy link

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

Load test result on commit 46b8fec1a92ea118da1d6937c1abf647c9fdc9bf 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.4 seconds inserted 10000000 Rows, about 746K ops/s

@924060929
Copy link
Contributor Author

run buildall

@924060929 924060929 force-pushed the sql_cache_consistence branch from 46b8fec to 002dc70 Compare April 16, 2024 13:06
@924060929
Copy link
Contributor Author

run buildall

1 similar comment
@924060929
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17619	4284	4283	4283
q2	2021	212	184	184
q3	10425	1194	1174	1174
q4	10198	785	780	780
q5	7500	2677	2569	2569
q6	217	132	135	132
q7	994	610	582	582
q8	9210	2044	2012	2012
q9	7321	6584	6544	6544
q10	8573	3512	3531	3512
q11	444	235	235	235
q12	429	225	219	219
q13	18024	2920	2946	2920
q14	259	231	227	227
q15	531	480	470	470
q16	529	411	381	381
q17	961	768	634	634
q18	7313	6669	6608	6608
q19	6684	1540	1514	1514
q20	645	320	295	295
q21	3542	2719	2702	2702
q22	356	306	312	306
Total cold run time: 113795 ms
Total hot run time: 38283 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4337	4211	4217	4211
q2	366	278	273	273
q3	3021	2712	2730	2712
q4	1880	1593	1577	1577
q5	5302	5325	5294	5294
q6	205	124	125	124
q7	2200	1856	1877	1856
q8	3193	3363	3342	3342
q9	8549	8540	8612	8540
q10	4087	3879	3959	3879
q11	606	501	500	500
q12	803	623	632	623
q13	16140	3362	3164	3164
q14	320	296	281	281
q15	526	466	478	466
q16	525	428	436	428
q17	1812	1539	1547	1539
q18	8039	7811	7866	7811
q19	1695	1638	1586	1586
q20	1966	1734	1809	1734
q21	5126	4990	4798	4798
q22	543	457	476	457
Total cold run time: 71241 ms
Total hot run time: 55195 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 185121 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 002dc70642261c61336115fe5a9447e0187f080d, data reload: false

query1	905	364	353	353
query2	6206	2603	2341	2341
query3	6643	200	197	197
query4	22992	21304	21300	21300
query5	4144	402	409	402
query6	270	173	168	168
query7	4587	291	295	291
query8	239	179	180	179
query9	8634	2369	2346	2346
query10	417	248	260	248
query11	14887	14157	14240	14157
query12	140	95	87	87
query13	1649	364	365	364
query14	10133	7707	7901	7707
query15	261	183	192	183
query16	8120	272	262	262
query17	1900	567	565	565
query18	1984	284	273	273
query19	215	155	153	153
query20	93	85	87	85
query21	199	132	131	131
query22	5022	4874	4764	4764
query23	33675	33165	33264	33165
query24	6651	2964	3037	2964
query25	551	376	376	376
query26	681	162	147	147
query27	2019	359	358	358
query28	3818	2096	2052	2052
query29	898	627	614	614
query30	275	187	183	183
query31	1014	752	802	752
query32	91	50	51	50
query33	494	235	232	232
query34	894	487	502	487
query35	780	700	729	700
query36	1038	935	902	902
query37	109	68	73	68
query38	3519	3337	3475	3337
query39	1634	1557	1562	1557
query40	177	133	131	131
query41	46	45	45	45
query42	102	96	95	95
query43	582	543	542	542
query44	1122	732	759	732
query45	299	244	287	244
query46	1113	770	732	732
query47	2086	1907	1954	1907
query48	367	307	292	292
query49	715	383	369	369
query50	759	406	380	380
query51	6827	6767	6830	6767
query52	97	87	89	87
query53	362	276	282	276
query54	249	244	238	238
query55	78	76	74	74
query56	255	244	231	231
query57	1252	1168	1159	1159
query58	222	198	201	198
query59	3413	3482	3069	3069
query60	249	220	229	220
query61	88	86	83	83
query62	536	429	435	429
query63	295	276	275	275
query64	4618	3849	3897	3849
query65	3034	3032	3028	3028
query66	745	335	325	325
query67	15438	14954	14882	14882
query68	5404	528	538	528
query69	509	297	301	297
query70	1168	1199	1155	1155
query71	1403	1261	1262	1261
query72	6319	2600	2463	2463
query73	728	319	319	319
query74	6837	6335	6429	6335
query75	3417	2668	2588	2588
query76	3386	908	985	908
query77	609	261	256	256
query78	11004	10277	10242	10242
query79	8122	516	523	516
query80	1805	415	431	415
query81	500	244	237	237
query82	1467	97	95	95
query83	336	162	159	159
query84	256	82	79	79
query85	1158	270	258	258
query86	468	295	299	295
query87	3481	3250	3353	3250
query88	5213	2413	2429	2413
query89	475	369	372	369
query90	1967	183	183	183
query91	120	155	95	95
query92	59	47	48	47
query93	6648	506	497	497
query94	1058	176	172	172
query95	375	296	290	290
query96	611	269	268	268
query97	3129	2929	2941	2929
query98	224	223	228	223
query99	1253	871	820	820
Total cold run time: 282416 ms
Total hot run time: 185121 ms

@doris-robot
Copy link

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

query1	0.04	0.03	0.03
query2	0.09	0.03	0.04
query3	0.23	0.05	0.06
query4	1.67	0.07	0.07
query5	0.49	0.51	0.50
query6	1.46	0.72	0.71
query7	0.02	0.01	0.01
query8	0.04	0.04	0.04
query9	0.55	0.50	0.49
query10	0.55	0.55	0.55
query11	0.17	0.12	0.11
query12	0.14	0.11	0.12
query13	0.62	0.59	0.58
query14	0.75	0.77	0.78
query15	0.83	0.80	0.81
query16	0.38	0.36	0.37
query17	1.03	0.95	1.04
query18	0.23	0.23	0.24
query19	1.86	1.68	1.64
query20	0.01	0.01	0.00
query21	15.41	0.66	0.66
query22	4.26	7.98	1.69
query23	18.30	1.37	1.31
query24	1.69	0.25	0.22
query25	0.14	0.09	0.09
query26	0.27	0.17	0.16
query27	0.07	0.08	0.07
query28	13.39	1.00	0.97
query29	12.65	3.27	3.25
query30	0.27	0.08	0.06
query31	2.86	0.37	0.38
query32	3.30	0.46	0.47
query33	2.85	2.82	2.81
query34	17.08	4.36	4.45
query35	4.48	4.46	4.48
query36	0.64	0.46	0.45
query37	0.18	0.15	0.15
query38	0.16	0.14	0.15
query39	0.05	0.03	0.03
query40	0.18	0.15	0.14
query41	0.10	0.05	0.08
query42	0.05	0.04	0.05
query43	0.04	0.04	0.04
Total cold run time: 109.58 s
Total hot run time: 30.01 s

@doris-robot
Copy link

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

Load test result on commit 002dc70642261c61336115fe5a9447e0187f080d 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
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.

Copy link
Contributor

@yiguolei yiguolei left a comment

Choose a reason for hiding this comment

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

Sync between multi FEs is very difficult.
We could simply using consistency hash like memcache to solve the problem.

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

924060929 commented Apr 17, 2024

Sync between multi FEs is very difficult. We could simply using consistency hash like memcache to solve the problem.

there is no any sync logic in this pr, and the consistency hash is not changed

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

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

@yiguolei yiguolei merged commit 90abd76 into apache:master Apr 17, 2024
@924060929 924060929 deleted the sql_cache_consistence branch April 17, 2024 12:16
924060929 added a commit to 924060929/incubator-doris that referenced this pull request Apr 18, 2024
…ontends (apache#33722)

fix some sql cache consistence bug between multiple frontends which introduced by [enhancement](Nereids) Enable parse sql from sql cache apache#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)
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
…ontends (apache#33722)

fix some sql cache consistence bug between multiple frontends which introduced by [enhancement](Nereids) Enable parse sql from sql cache apache#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)
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.

4 participants