~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
################### include/grant_cache.inc ####################
2
#
3
# Test grants with query cache
4
#
5
# Last update:
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
10
#
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.
15
# In detail:
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++).
26
# - In ps-protocol,
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.
33
#
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.
36
#
37
38
--source include/add_anonymous_users.inc
39
40
#
41
--disable_warnings
42
drop table if exists test.t1,mysqltest.t1,mysqltest.t2;
43
drop database if exists mysqltest;
44
--enable_warnings
45
46
set GLOBAL query_cache_size=1355776;
47
48
reset query cache;
49
flush status;
50
--echo ----- establish connection root -----
51
connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
52
connection root;
53
show grants for current_user;
54
show grants;
55
--disable_warnings
56
create database if not exists mysqltest;
57
--enable_warnings
58
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");
65
select * from t1;
66
--echo ----- establish connection root2 -----
67
connect (root2,localhost,root,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
68
connection root2;
69
# put queries in cache
70
select * from t1;
71
select a from t1;
72
select c from t1;
73
select * from t2;
74
select * from mysqltest.t1,test.t1;
75
show status like "Qcache_queries_in_cache";
76
show status like "Qcache_hits%";
77
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;
83
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);
87
connection user1;
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";
92
select "user1";
93
show status like "Qcache_queries_in_cache";
94
show status like "Qcache_hits";
95
show status like "Qcache_not_cached";
96
select * from t1;
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
101
 select a from t1 ;
102
show status like "Qcache_queries_in_cache";
103
show status like "Qcache_hits";
104
show status like "Qcache_not_cached";
105
select c from t1;
106
show status like "Qcache_queries_in_cache";
107
show status like "Qcache_hits";
108
show status like "Qcache_not_cached";
109
110
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);
114
connection unkuser;
115
show grants for current_user();
116
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);
120
connection user2;
121
select "user2";
122
select * from t1;
123
select a from t1;
124
select c from t1;
125
select * from mysqltest.t1,test.t1;
126
--replace_result 127.0.0.1 localhost
127
--error ER_TABLEACCESS_DENIED_ERROR
128
select * from t2;
129
show status like "Qcache_queries_in_cache";
130
show status like "Qcache_hits";
131
show status like "Qcache_not_cached";
132
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);
136
connection user3;
137
select "user3";
138
--replace_result 127.0.0.1 localhost
139
--error ER_COLUMNACCESS_DENIED_ERROR
140
select * from t1;
141
select a from t1;
142
--replace_result 127.0.0.1 localhost
143
--error ER_COLUMNACCESS_DENIED_ERROR
144
select c from t1;
145
--replace_result 127.0.0.1 localhost
146
--error ER_TABLEACCESS_DENIED_ERROR
147
select * from t2;
148
--replace_result 127.0.0.1 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";
154
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);
158
connection user4;
159
select "user4";
160
show grants;
161
--error ER_NO_DB_ERROR
162
select a from t1;
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";
171
172
# Cleanup
173
174
--echo ----- switch to connection default and close connections -----
175
connection default;
176
disconnect root;
177
disconnect root2;
178
disconnect user1;
179
disconnect user2;
180
disconnect user3;
181
disconnect user4;
182
disconnect unkuser;
183
184
#
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'.
191
#
192
set names binary;
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");
197
flush privileges;
198
drop table test.t1,mysqltest.t1,mysqltest.t2;
199
drop database mysqltest;
200
201
set GLOBAL query_cache_size=default;
202
203
--source include/delete_anonymous_users.inc