mirror of
https://github.com/MariaDB/server.git
synced 2025-11-02 02:53:04 +03:00
Cache".
WL#1569 "Prepared Statements: implement support of Query Cache".
Prepared SELECTs did not look up in the query cache, and their results
were not stored in the query cache. This made them slower than
non-prepared SELECTs in some cases.
The fix is to re-use the expanded query (the prepared query where
"?" placeholders are replaced by their values, at execution time)
for searching/storing in the query cache.
It works fine for statements prepared via mysql_stmt_prepare(), which
are the most commonly used and were the scope of this bugfix and WL.
It works less fine for statements prepared via the SQL command
PREPARE...FROM, which are still not using the query cache if they
have at least one parameter (because then the expanded query contains
names of user variables, and user variables don't work with the
query cache, even in non-prepared queries).
Note that results from prepared SELECTs, which are in the binary
protocol, and results from normal SELECTs, which are in the text
protocol, ignore each other in the query cache, because a result in the
binary protocol should never be served to a SELECT expecting the text
protocol and vice-versa.
Note, after this patch, bug 25843 starts applying to query cache
("changing default database between PREPARE and EXECUTE of statement
breaks binlog"), we need to fix it.
205 lines
3.5 KiB
Plaintext
205 lines
3.5 KiB
Plaintext
set global query_cache_size=100000;
|
|
flush status;
|
|
create table t1(c1 int);
|
|
insert into t1 values(1),(10),(100);
|
|
prepare stmt1 from "select * from t1 where c1=10";
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 0
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 0
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 1
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 2
|
|
prepare stmt2 from "select * from t1 where c1=10";
|
|
execute stmt2;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 3
|
|
execute stmt2;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 4
|
|
execute stmt2;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 5
|
|
prepare stmt3 from "select * from t1 where c1=10";
|
|
execute stmt3;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 6
|
|
execute stmt3;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 7
|
|
execute stmt3;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 8
|
|
select * from t1 where c1=10;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 9
|
|
flush tables;
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 9
|
|
select * from t1 where c1=10;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
prepare stmt1 from "select * from t1 where c1=?";
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
set @a=1;
|
|
execute stmt1 using @a;
|
|
c1
|
|
1
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
set @a=100;
|
|
execute stmt1 using @a;
|
|
c1
|
|
100
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
set @a=10;
|
|
execute stmt1 using @a;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
prepare stmt1 from "select * from t1 where c1=10";
|
|
set global query_cache_size=0;
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
set global query_cache_size=100000;
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 10
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 11
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
set global query_cache_size=0;
|
|
prepare stmt1 from "select * from t1 where c1=10";
|
|
set global query_cache_size=100000;
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
execute stmt1;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
set global query_cache_size=0;
|
|
prepare stmt1 from "select * from t1 where c1=?";
|
|
set global query_cache_size=100000;
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
set @a=1;
|
|
execute stmt1 using @a;
|
|
c1
|
|
1
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
set @a=100;
|
|
execute stmt1 using @a;
|
|
c1
|
|
100
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
set @a=10;
|
|
execute stmt1 using @a;
|
|
c1
|
|
10
|
|
show status like 'Qcache_hits';
|
|
Variable_name Value
|
|
Qcache_hits 12
|
|
drop table t1;
|
|
set global query_cache_size=0;
|
|
flush status;
|