1 ################### include/grant_cache.inc ####################
3 # Test grants with query cache
5 # Now normal protocol and ps-protocol produces the same result.
6 # (After splitting open and lock tables into different stages,
7 # to be able to prune locks of individual partitions.)
9 # Before this change, the below was true:
10 # Running this test with and without "--ps-protocol" produces different
11 # Qcache_not_cached results because of the following reason:
12 # In normal protocol, a SELECT failing due to insufficient privileges
13 # increments Qcache_not_cached, while in ps-protocol, no.
15 # - In normal protocol,
16 # the "access denied" errors on SELECT are issued at (stack trace):
17 # mysql_parse/mysql_execute_command/execute_sqlcom_select/handle_select/
18 # mysql_select/JOIN::prepare/setup_wild/insert_fields/
19 # check_grant_all_columns/my_error/my_message_sql, which then calls
20 # push_warning/query_cache_abort: at this moment,
21 # query_cache_store_query() has been called, so query exists in cache,
22 # so thd->net.query_cache_query!=NULL, so query_cache_abort() removes
23 # the query from cache, which causes a query_cache.refused++ (thus,
24 # a Qcache_not_cached++).
26 # the error is issued at prepare time;
27 # for this mysql_test_select() is called, not execute_sqlcom_select()
28 # (and that also leads to JOIN::prepare/etc). Thus, as
29 # query_cache_store_query() has not been called,
30 # thd->net.query_cache_query==NULL, so query_cache_abort() does nothing:
31 # Qcache_not_cached is not incremented.
33 # A run of this tests with sp/cursor/view protocol does not make sense
34 # because these protocols serve totally different purposes than this test.
37 --source include/add_anonymous_users.inc
41 drop
table if exists
test.t1,mysqltest.t1,mysqltest.t2;
42 drop database
if exists mysqltest;
45 set GLOBAL query_cache_size=1355776;
49 --echo ----- establish connection root -----
50 connect (root,localhost,root,,
test,$MASTER_MYPORT,$MASTER_MYSOCK);
52 show grants
for current_user;
55 create database
if not exists mysqltest;
58 create
table mysqltest.t1 (a
int,b
int,c
int);
59 create
table mysqltest.t2 (a
int,b
int,c
int);
60 insert into mysqltest.t1 values (1,1,1),(2,2,2);
61 insert into mysqltest.t2 values (3,3,3);
63 insert into
test.t1 values (
"test.t1");
65 --echo ----- establish connection root2 -----
66 connect (root2,localhost,root,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
68 # put queries in cache
73 select * from mysqltest.t1,
test.t1;
74 show status like
"Qcache_queries_in_cache";
75 show status like
"Qcache_hits%";
77 # Create the test users
78 grant SELECT on mysqltest.*
to mysqltest_1@localhost;
79 grant SELECT on mysqltest.t1
to mysqltest_2@localhost;
80 grant SELECT on
test.t1
to mysqltest_2@localhost;
81 grant SELECT(a) on mysqltest.t1
to mysqltest_3@localhost;
83 # The following queries should be fetched from cache
84 --echo ----- establish connection user1 (user=mysqltest_1) -----
85 connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
87 show grants
for current_user();
88 show status like
"Qcache_queries_in_cache";
89 show status like
"Qcache_hits";
90 show status like
"Qcache_not_cached";
92 show status like
"Qcache_queries_in_cache";
93 show status like
"Qcache_hits";
94 show status like
"Qcache_not_cached";
96 show status like
"Qcache_queries_in_cache";
97 show status like
"Qcache_hits";
98 show status like
"Qcache_not_cached";
99 # The pre and end space are intentional
101 show status like
"Qcache_queries_in_cache";
102 show status like
"Qcache_hits";
103 show status like
"Qcache_not_cached";
105 show status like
"Qcache_queries_in_cache";
106 show status like
"Qcache_hits";
107 show status like
"Qcache_not_cached";
110 --echo ----- establish connection unkuser (user=unkuser) -----
111 # Don't use '' as user because it will pick Unix login
112 connect (unkuser,localhost,unkuser,,,$MASTER_MYPORT,$MASTER_MYSOCK);
114 show grants
for current_user();
116 # The following queries should be fetched from cache
117 --echo ----- establish connection user2 (user=mysqltest_2) -----
118 connect (user2,localhost,mysqltest_2,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
124 select * from mysqltest.t1,
test.t1;
125 --replace_result 127.0.0.1 localhost
126 --error ER_TABLEACCESS_DENIED_ERROR
128 show status like
"Qcache_queries_in_cache";
129 show status like
"Qcache_hits";
130 show status like
"Qcache_not_cached";
132 # The following queries should not be fetched from cache
133 --echo ----- establish connection user3 (user=mysqltest_3) -----
134 connect (user3,localhost,mysqltest_3,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
137 --replace_result 127.0.0.1 localhost
138 --error ER_TABLEACCESS_DENIED_ERROR
141 --replace_result 127.0.0.1 localhost
142 --error ER_COLUMNACCESS_DENIED_ERROR
144 --replace_result 127.0.0.1 localhost
145 --error ER_TABLEACCESS_DENIED_ERROR
147 --replace_result 127.0.0.1 localhost
148 --error ER_COLUMNACCESS_DENIED_ERROR
149 select mysqltest.t1.c from
test.t1,mysqltest.t1;
150 show status like
"Qcache_queries_in_cache";
151 show status like
"Qcache_hits";
152 show status like
"Qcache_not_cached";
154 # Connect without a database
155 --echo ----- establish connection user4 (user=mysqltest_1) -----
156 connect (user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK);
160 --error ER_NO_DB_ERROR
162 # The following query is not cached before (different database)
163 select * from mysqltest.t1,
test.t1;
164 # Cache a query with 'no database'
165 select a from mysqltest.t1;
166 select a from mysqltest.t1;
167 show status like
"Qcache_queries_in_cache";
168 show status like
"Qcache_hits";
169 show status like
"Qcache_not_cached";
173 --echo ----- close connections -----
176 --source include/wait_until_disconnected.inc
179 --source include/wait_until_disconnected.inc
182 --source include/wait_until_disconnected.inc
185 --source include/wait_until_disconnected.inc
188 --source include/wait_until_disconnected.inc
191 --source include/wait_until_disconnected.inc
194 --source include/wait_until_disconnected.inc
195 --echo -----
switch to connection
default -----
199 # A temporary 4.1 workaround to make this test pass if
200 # mysql was compiled with other than latin1 --with-charset=XXX.
201 # Without "set names binary" the below queries fail with
202 # "Illegal mix of collations" error.
203 # In 5.0 we will change grant tables to use NCHAR(N) instead
204 # of "CHAR(N) BINARY", and use cast-to-nchar: N'mysqltest_1'.
207 delete from mysql.user where user in (
"mysqltest_1",
"mysqltest_2",
"mysqltest_3");
208 delete from mysql.db where user in (
"mysqltest_1",
"mysqltest_2",
"mysqltest_3");
209 delete from mysql.tables_priv where user in (
"mysqltest_1",
"mysqltest_2",
"mysqltest_3");
210 delete from mysql.columns_priv where user in (
"mysqltest_1",
"mysqltest_2",
"mysqltest_3");
212 drop
table test.t1,mysqltest.t1,mysqltest.t2;
213 drop database mysqltest;
215 set GLOBAL query_cache_size=
default;
217 --source include/delete_anonymous_users.inc