Test that caching works only for SELECTs

This commit is contained in:
Robert Schulze 2022-12-15 22:23:50 +00:00
parent 4db33f16e3
commit d4d5cc2825
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
2 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,77 @@
-- { echoOn }
SYSTEM DROP QUERY RESULT CACHE;
DROP TABLE IF EXISTS eligible_test;
DROP TABLE IF EXISTS eligible_test2;
-- enable query result cache session-wide but also force it individually in each of below statements
SET enable_experimental_query_result_cache = true;
-- check that SELECT statements create entries in the query result cache ...
SELECT 1 SETTINGS enable_experimental_query_result_cache = true;
1
SELECT 2 SETTINGS enable_experimental_query_result_cache = true;
2
SELECT count(*) FROM system.queryresult_cache;
2
-- ... EXPLAIN SELECT should not create such an entry ...
EXPLAIN SELECT 2 SETTINGS enable_experimental_query_result_cache = true;
Expression ((Projection + Before ORDER BY))
ReadFromStorage (SystemOne)
SELECT count(*) FROM system.queryresult_cache;
2
SYSTEM DROP QUERY RESULT CACHE;
-- ... and all other statements don't
-- CREATE
CREATE TABLE eligible_test (a String) ENGINE=MergeTree ORDER BY a; -- SETTINGS enable_experimental_query_result_cache = true; -- SETTINGS rejected as unknown
SELECT count(*) FROM system.queryresult_cache;
0
-- ALTER
ALTER TABLE eligible_test ADD COLUMN b String SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
0
-- INSERT
INSERT INTO eligible_test VALUES('a', 'b'); -- SETTINGS enable_experimental_query_result_cache = true; -- SETTINGS rejected as unknown
SELECT count(*) FROM system.queryresult_cache;
0
INSERT INTO eligible_test SELECT * FROM eligible_test SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
0
-- SHOW
SHOW TABLES SETTINGS enable_experimental_query_result_cache = true;
eligible_test
SELECT count(*) FROM system.queryresult_cache;
0
-- CHECK
CHECK TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
1
SELECT count(*) FROM system.queryresult_cache;
0
-- DESCRIBE
DESCRIBE TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
a String
b String
SELECT count(*) FROM system.queryresult_cache;
0
-- EXISTS
EXISTS TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
1
SELECT count(*) FROM system.queryresult_cache;
0
-- KILL
KILL QUERY WHERE query_id='3-857d-4a57-9ee0-3c7da5d60a90' SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
0
-- OPTIMIZE
OPTIMIZE TABLE eligible_test FINAL SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
0
-- TRUNCATE
TRUNCATE TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
0
-- RENAME
RENAME TABLE eligible_test TO eligible_test2 SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
0
SYSTEM DROP QUERY RESULT CACHE;
DROP TABLE eligible_test2;

View File

@ -0,0 +1,71 @@
-- { echoOn }
SYSTEM DROP QUERY RESULT CACHE;
DROP TABLE IF EXISTS eligible_test;
DROP TABLE IF EXISTS eligible_test2;
-- enable query result cache session-wide but also force it individually in each of below statements
SET enable_experimental_query_result_cache = true;
-- check that SELECT statements create entries in the query result cache ...
SELECT 1 SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- ... yet EXPLAIN SELECT should not create such an entry ...
EXPLAIN SELECT 2 SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
SYSTEM DROP QUERY RESULT CACHE;
-- ... and all other statements also should not create entries:
-- CREATE
CREATE TABLE eligible_test (a String) ENGINE=MergeTree ORDER BY a; -- SETTINGS enable_experimental_query_result_cache = true; -- SETTINGS rejected as unknown
SELECT count(*) FROM system.queryresult_cache;
-- ALTER
ALTER TABLE eligible_test ADD COLUMN b String SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- INSERT
INSERT INTO eligible_test VALUES('a', 'b'); -- SETTINGS enable_experimental_query_result_cache = true; -- SETTINGS rejected as unknown
SELECT count(*) FROM system.queryresult_cache;
INSERT INTO eligible_test SELECT * FROM eligible_test SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- SHOW
SHOW TABLES SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- CHECK
CHECK TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- DESCRIBE
DESCRIBE TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- EXISTS
EXISTS TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- KILL
KILL QUERY WHERE query_id='3-857d-4a57-9ee0-3c7da5d60a90' SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- OPTIMIZE
OPTIMIZE TABLE eligible_test FINAL SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- TRUNCATE
TRUNCATE TABLE eligible_test SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
-- RENAME
RENAME TABLE eligible_test TO eligible_test2 SETTINGS enable_experimental_query_result_cache = true;
SELECT count(*) FROM system.queryresult_cache;
SYSTEM DROP QUERY RESULT CACHE;
DROP TABLE eligible_test2;
-- { echoOff }