1
################### include/grant_cache.inc ####################
3
# Test grants with query cache
6
# 2007-05-03 ML - Move t/grant_cache.test to include/grant_cache.inc
7
# - Remove the disabling of the ps-protocol
8
# - minor improvements like error names instead of numbers
9
# - Create two toplevel tests sourcing this routine
11
# Running this test with and without "--ps-protocol" produces different
12
# Qcache_not_cached results because of the following reason:
13
# In normal protocol, a SELECT failing due to insufficient privileges
14
# increments Qcache_not_cached, while in ps-protocol, no.
16
# - In normal protocol,
17
# the "access denied" errors on SELECT are issued at (stack trace):
18
# mysql_parse/mysql_execute_command/execute_sqlcom_select/handle_select/
19
# mysql_select/JOIN::prepare/setup_wild/insert_fields/
20
# check_grant_all_columns/my_error/my_message_sql, which then calls
21
# push_warning/query_cache_abort: at this moment,
22
# query_cache_store_query() has been called, so query exists in cache,
23
# so thd->net.query_cache_query!=NULL, so query_cache_abort() removes
24
# the query from cache, which causes a query_cache.refused++ (thus,
25
# a Qcache_not_cached++).
27
# the error is issued at prepare time;
28
# for this mysql_test_select() is called, not execute_sqlcom_select()
29
# (and that also leads to JOIN::prepare/etc). Thus, as
30
# query_cache_store_query() has not been called,
31
# thd->net.query_cache_query==NULL, so query_cache_abort() does nothing:
32
# Qcache_not_cached is not incremented.
34
# A run of this tests with sp/cursor/view protocol does not make sense
35
# because these protocols serve totally different purposes than this test.
38
--source include/add_anonymous_users.inc
42
drop table if exists test.t1,mysqltest.t1,mysqltest.t2;
43
drop database if exists mysqltest;
46
set GLOBAL query_cache_size=1355776;
50
--echo ----- establish connection root -----
51
connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
53
show grants for current_user;
56
create database if not exists mysqltest;
59
create table mysqltest.t1 (a int,b int,c int);
60
create table mysqltest.t2 (a int,b int,c int);
61
insert into mysqltest.t1 values (1,1,1),(2,2,2);
62
insert into mysqltest.t2 values (3,3,3);
63
create table test.t1 (a char (10));
64
insert into test.t1 values ("test.t1");
66
--echo ----- establish connection root2 -----
67
connect (root2,localhost,root,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
69
# put queries in cache
74
select * from mysqltest.t1,test.t1;
75
show status like "Qcache_queries_in_cache";
76
show status like "Qcache_hits%";
78
# Create the test users
79
grant SELECT on mysqltest.* to mysqltest_1@localhost;
80
grant SELECT on mysqltest.t1 to mysqltest_2@localhost;
81
grant SELECT on test.t1 to mysqltest_2@localhost;
82
grant SELECT(a) on mysqltest.t1 to mysqltest_3@localhost;
84
# The following queries should be fetched from cache
85
--echo ----- establish connection user1 (user=mysqltest_1) -----
86
connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
88
show grants for current_user();
89
show status like "Qcache_queries_in_cache";
90
show status like "Qcache_hits";
91
show status like "Qcache_not_cached";
93
show status like "Qcache_queries_in_cache";
94
show status like "Qcache_hits";
95
show status like "Qcache_not_cached";
97
show status like "Qcache_queries_in_cache";
98
show status like "Qcache_hits";
99
show status like "Qcache_not_cached";
100
# The pre and end space are intentional
102
show status like "Qcache_queries_in_cache";
103
show status like "Qcache_hits";
104
show status like "Qcache_not_cached";
106
show status like "Qcache_queries_in_cache";
107
show status like "Qcache_hits";
108
show status like "Qcache_not_cached";
111
--echo ----- establish connection unkuser (user=unkuser) -----
112
# Don't use '' as user because it will pick Unix login
113
connect (unkuser,localhost,unkuser,,,$MASTER_MYPORT,$MASTER_MYSOCK);
115
show grants for current_user();
117
# The following queries should be fetched from cache
118
--echo ----- establish connection user2 (user=mysqltest_2) -----
119
connect (user2,localhost,mysqltest_2,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
125
select * from mysqltest.t1,test.t1;
126
--replace_result localhost localhost
127
--error ER_TABLEACCESS_DENIED_ERROR
129
show status like "Qcache_queries_in_cache";
130
show status like "Qcache_hits";
131
show status like "Qcache_not_cached";
133
# The following queries should not be fetched from cache
134
--echo ----- establish connection user3 (user=mysqltest_3) -----
135
connect (user3,localhost,mysqltest_3,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
138
--replace_result localhost localhost
139
--error ER_COLUMNACCESS_DENIED_ERROR
142
--replace_result localhost localhost
143
--error ER_COLUMNACCESS_DENIED_ERROR
145
--replace_result localhost localhost
146
--error ER_TABLEACCESS_DENIED_ERROR
148
--replace_result localhost localhost
149
--error ER_COLUMNACCESS_DENIED_ERROR
150
select mysqltest.t1.c from test.t1,mysqltest.t1;
151
show status like "Qcache_queries_in_cache";
152
show status like "Qcache_hits";
153
show status like "Qcache_not_cached";
155
# Connect without a database
156
--echo ----- establish connection user4 (user=mysqltest_1) -----
157
connect (user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK);
161
--error ER_NO_DB_ERROR
163
# The following query is not cached before (different database)
164
select * from mysqltest.t1,test.t1;
165
# Cache a query with 'no database'
166
select a from mysqltest.t1;
167
select a from mysqltest.t1;
168
show status like "Qcache_queries_in_cache";
169
show status like "Qcache_hits";
170
show status like "Qcache_not_cached";
174
--echo ----- switch to connection default and close connections -----
185
# A temporary 4.1 workaround to make this test pass if
186
# mysql was compiled with other than latin1 --with-charset=XXX.
187
# Without "set names binary" the below queries fail with
188
# "Illegal mix of collations" error.
189
# In 5.0 we will change grant tables to use NCHAR(N) instead
190
# of "CHAR(N) BINARY", and use cast-to-nchar: N'mysqltest_1'.
193
delete from mysql.user where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
194
delete from mysql.db where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
195
delete from mysql.tables_priv where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
196
delete from mysql.columns_priv where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
198
drop table test.t1,mysqltest.t1,mysqltest.t2;
199
drop database mysqltest;
201
set GLOBAL query_cache_size=default;
203
--source include/delete_anonymous_users.inc