Browse Source
Merge gbichot@bk-internal.mysql.com:/home/bk/mysql-5.1-runtime
Merge gbichot@bk-internal.mysql.com:/home/bk/mysql-5.1-runtime
into gbichot3.local:/home/mysql_src/mysql-5.1-runtime-735-realfix sql/mysql_priv.h: Auto merged sql/set_var.cc: Auto merged sql/sql_prepare.cc: Auto mergedpull/374/head
17 changed files with 876 additions and 97 deletions
-
12libmysqld/lib_sql.cc
-
3mysql-test/include/have_query_cache.inc
-
23mysql-test/r/query_cache.result
-
204mysql-test/r/query_cache_sql_prepare.result
-
26mysql-test/t/grant_cache.test
-
31mysql-test/t/ndb_cache_multi2.test
-
20mysql-test/t/query_cache.test
-
144mysql-test/t/query_cache_sql_prepare.test
-
8sql/mysql_priv.h
-
73sql/protocol.cc
-
23sql/protocol.h
-
4sql/set_var.cc
-
20sql/sql_cache.cc
-
6sql/sql_class.cc
-
4sql/sql_class.h
-
102sql/sql_prepare.cc
-
270tests/mysql_client_test.c
@ -1,7 +1,4 @@ |
|||
-- require r/have_query_cache.require |
|||
# As PS are not cached we disable them to ensure the we get the right number |
|||
# of query cache hits |
|||
-- disable_ps_protocol |
|||
disable_query_log; |
|||
show variables like "have_query_cache"; |
|||
enable_query_log; |
|||
@ -0,0 +1,204 @@ |
|||
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; |
|||
@ -0,0 +1,144 @@ |
|||
# This is to see how statements prepared via the PREPARE SQL command |
|||
# go into the query cache: if using parameters they cannot; if not |
|||
# using parameters they can. |
|||
# Query cache is abbreviated as "QC" |
|||
|
|||
-- source include/have_query_cache.inc |
|||
|
|||
connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,); |
|||
connection default; |
|||
|
|||
set global query_cache_size=100000; |
|||
flush status; |
|||
create table t1(c1 int); |
|||
insert into t1 values(1),(10),(100); |
|||
|
|||
# Prepared statements has no parameters, query caching should happen |
|||
prepare stmt1 from "select * from t1 where c1=10"; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
# Another prepared statement (same text, same connection), should hit the QC |
|||
prepare stmt2 from "select * from t1 where c1=10"; |
|||
execute stmt2; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt2; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt2; |
|||
show status like 'Qcache_hits'; |
|||
# Another prepared statement (same text, other connection), should hit the QC |
|||
connection con1; |
|||
prepare stmt3 from "select * from t1 where c1=10"; |
|||
execute stmt3; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt3; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt3; |
|||
show status like 'Qcache_hits'; |
|||
connection default; |
|||
# A non-prepared statement (same text, same connection), should hit |
|||
# the QC (as it uses the text protocol like SQL EXECUTE). |
|||
# But if it uses the binary protocol, it will not hit. So we make sure |
|||
# that it uses the text protocol: |
|||
-- disable_ps_protocol |
|||
select * from t1 where c1=10; |
|||
show status like 'Qcache_hits'; |
|||
# A non-prepared statement (same text, other connection), should hit |
|||
# the QC. To test that it hits the result of SQL EXECUTE, we need to |
|||
# empty/repopulate the QC (to remove the result from the non-prepared |
|||
# SELECT just above). |
|||
flush tables; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
connection con1; |
|||
select * from t1 where c1=10; |
|||
show status like 'Qcache_hits'; |
|||
-- enable_ps_protocol |
|||
connection default; |
|||
|
|||
# Prepared statement has parameters, query caching should not happen |
|||
prepare stmt1 from "select * from t1 where c1=?"; |
|||
show status like 'Qcache_hits'; |
|||
set @a=1; |
|||
execute stmt1 using @a; |
|||
show status like 'Qcache_hits'; |
|||
set @a=100; |
|||
execute stmt1 using @a; |
|||
show status like 'Qcache_hits'; |
|||
set @a=10; |
|||
execute stmt1 using @a; |
|||
show status like 'Qcache_hits'; |
|||
|
|||
# See if enabling/disabling the query cache between PREPARE and |
|||
# EXECUTE is an issue; the expected result is that the query cache |
|||
# will not be used. |
|||
# Indeed, decision to read/write the query cache is taken at PREPARE |
|||
# time, so if the query cache was disabled at PREPARE time then no |
|||
# execution of the statement will read/write the query cache. |
|||
# If the query cache was enabled at PREPARE time, but disabled at |
|||
# EXECUTE time, at EXECUTE time the query cache internal functions do |
|||
# nothing so again the query cache is not read/written. But if the |
|||
# query cache is re-enabled before another execution then that |
|||
# execution will read/write the query cache. |
|||
|
|||
# QC is enabled at PREPARE |
|||
prepare stmt1 from "select * from t1 where c1=10"; |
|||
# then QC is disabled at EXECUTE |
|||
set global query_cache_size=0; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
# then QC is re-enabled for more EXECUTE. |
|||
set global query_cache_size=100000; |
|||
# Note that this execution will not hit results from the |
|||
# beginning of the test (because QC has been emptied meanwhile by |
|||
# setting its size to 0). |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
|
|||
# QC is disabled at PREPARE |
|||
set global query_cache_size=0; |
|||
prepare stmt1 from "select * from t1 where c1=10"; |
|||
# then QC is enabled at EXECUTE |
|||
set global query_cache_size=100000; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
execute stmt1; |
|||
show status like 'Qcache_hits'; |
|||
|
|||
# QC is disabled at PREPARE |
|||
set global query_cache_size=0; |
|||
prepare stmt1 from "select * from t1 where c1=?"; |
|||
# then QC is enabled at EXECUTE |
|||
set global query_cache_size=100000; |
|||
show status like 'Qcache_hits'; |
|||
set @a=1; |
|||
execute stmt1 using @a; |
|||
show status like 'Qcache_hits'; |
|||
set @a=100; |
|||
execute stmt1 using @a; |
|||
show status like 'Qcache_hits'; |
|||
set @a=10; |
|||
execute stmt1 using @a; |
|||
show status like 'Qcache_hits'; |
|||
|
|||
|
|||
drop table t1; |
|||
|
|||
set global query_cache_size=0; |
|||
flush status; # reset Qcache status variables for next tests |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue