1
by brian
clean slate |
1 |
# suite/funcs_1/t/is_statistics.test |
2 |
#
|
|
3 |
# Check the layout of information_schema.statistics and the impact of |
|
4 |
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on its content. |
|
5 |
#
|
|
6 |
# Note: |
|
7 |
# This test is not intended |
|
8 |
# - to show information about the all time existing tables |
|
9 |
# within the databases information_schema and mysql |
|
10 |
# - for checking storage engine properties |
|
11 |
# Therefore please do not alter $engine_type and $other_engine_type. |
|
12 |
#
|
|
13 |
# Author: |
|
14 |
# 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of |
|
15 |
# testsuite funcs_1 |
|
16 |
# Create this script based on older scripts and new code. |
|
17 |
#
|
|
18 |
||
19 |
# --source suite/funcs_1/datadict/datadict.pre |
|
20 |
||
21 |
let $engine_type = MEMORY; |
|
22 |
let $other_engine_type = MyISAM; |
|
23 |
||
24 |
let $is_table = STATISTICS; |
|
25 |
||
26 |
# The table INFORMATION_SCHEMA.STATISTICS must exist |
|
27 |
eval SHOW TABLES FROM information_schema LIKE '$is_table'; |
|
28 |
||
29 |
--echo #######################################################################
|
|
30 |
--echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
|
|
31 |
--echo #######################################################################
|
|
32 |
# Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT |
|
33 |
# statement, just as if it were an ordinary user-defined table. |
|
34 |
#
|
|
35 |
--source suite/funcs_1/datadict/is_table_query.inc
|
|
36 |
||
37 |
||
38 |
--echo #########################################################################
|
|
39 |
--echo # Testcase 3.2.14.1: INFORMATION_SCHEMA.STATISTICS layout
|
|
40 |
--echo #########################################################################
|
|
41 |
# Ensure that the INFORMATION_SCHEMA.STATISTICS table has the following columns, |
|
42 |
# in the following order: |
|
43 |
#
|
|
44 |
# TABLE_CATALOG (always shows NULL), |
|
45 |
# TABLE_SCHEMA (shows the database, or schema, in which a table indexed by |
|
46 |
# an accessible index resides), |
|
47 |
# TABLE_NAME (shows the name of the indexed table), |
|
48 |
# NON_UNIQUE (shows whether the index may contain duplicate values; |
|
49 |
# 0 if it cannot, 1 if it can), |
|
50 |
# INDEX_SCHEMA (shows the database, or schema, in which an accessible |
|
51 |
# index resides), |
|
52 |
# INDEX_NAME (shows the name of an index which the current user may access), |
|
53 |
# SEQ_IN_INDEX (shows the ordinal position of an indexed column within |
|
54 |
# the index), |
|
55 |
# COLUMN_NAME (shows the name of a column that comprises some, or all, of an |
|
56 |
# index key), |
|
57 |
# COLLATION (shows how the column is sorted in the index; either A for ascending |
|
58 |
# or NULL for unsorted columns), |
|
59 |
# CARDINALITY (shows the number of unique values in the index), |
|
60 |
# SUB_PART (shows the number of indexed characters if the index is |
|
61 |
# a prefix index), |
|
62 |
# PACKED (shows how the index key is packed), |
|
63 |
# NULLABLE (shows whether the index column may contain NULL values), |
|
64 |
# INDEX_TYPE (shows the index type; either BTREE, FULLTEXT, HASH or RTREE), |
|
65 |
# COMMENT (shows a comment on the index, if any). |
|
66 |
# INDEX_COMMENT |
|
67 |
#
|
|
68 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc
|
|
69 |
eval DESCRIBE information_schema.$is_table; |
|
70 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc
|
|
71 |
eval SHOW CREATE TABLE information_schema.$is_table; |
|
72 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc
|
|
73 |
eval SHOW COLUMNS FROM information_schema.$is_table; |
|
74 |
||
75 |
# Note: Retrieval of information within information_schema.columns about |
|
76 |
# information_schema.statistics is in is_columns_is.test. |
|
77 |
||
78 |
# Show that TABLE_CATALOG is always NULL. |
|
79 |
SELECT table_catalog, table_schema, table_name, index_schema, index_name |
|
80 |
FROM information_schema.statistics WHERE table_catalog IS NOT NULL; |
|
81 |
||
82 |
||
83 |
--echo ####################################################################################
|
|
84 |
--echo # Testcase 3.2.14.2 + 3.2.14.3: INFORMATION_SCHEMA.STATISTICS accessible information
|
|
85 |
--echo ####################################################################################
|
|
86 |
# 3.2.14.2 Ensure that the table shows the relevant information on every index |
|
87 |
# which the current user or PUBLIC may access (usually because |
|
88 |
# privileges on the indexed table have been granted). |
|
89 |
# 3.2.14.3 Ensure that the table does not show any information on any indexes |
|
90 |
# which the current user and PUBLIC may not access. |
|
91 |
#
|
|
92 |
# Note: Check of content within information_schema.statistics about |
|
93 |
# database is in |
|
94 |
# mysql is_statistics_mysql.test |
|
95 |
# information_schema is_statistics_is.test |
|
96 |
#
|
|
97 |
--disable_warnings
|
|
98 |
DROP DATABASE IF EXISTS db_datadict; |
|
99 |
DROP DATABASE IF EXISTS db_datadict_2; |
|
100 |
--enable_warnings
|
|
101 |
CREATE DATABASE db_datadict; |
|
102 |
CREATE DATABASE db_datadict_2; |
|
103 |
||
104 |
--error 0,ER_CANNOT_USER
|
|
105 |
DROP USER 'testuser1'@'localhost'; |
|
106 |
CREATE USER 'testuser1'@'localhost'; |
|
107 |
--error 0,ER_CANNOT_USER
|
|
108 |
DROP USER 'testuser2'@'localhost'; |
|
109 |
CREATE USER 'testuser2'@'localhost'; |
|
110 |
||
111 |
--replace_result $engine_type <engine_type>
|
|
112 |
eval
|
|
113 |
CREATE TABLE db_datadict.t1 |
|
114 |
(f1 INT NOT NULL, PRIMARY KEY(f1), f2 INT, INDEX f2_ind(f2)) |
|
115 |
ENGINE = $engine_type; |
|
116 |
--replace_result $engine_type <engine_type>
|
|
117 |
eval
|
|
118 |
CREATE TABLE db_datadict.t2 |
|
119 |
(f1 INT NOT NULL, PRIMARY KEY(f1), f2 INT, INDEX f2_ind(f2)) |
|
120 |
ENGINE = $engine_type; |
|
121 |
||
122 |
eval
|
|
123 |
CREATE TABLE db_datadict_2.t3 |
|
124 |
(f1 INT NOT NULL, f2 INT, f5 DATE, |
|
125 |
PRIMARY KEY(f1), INDEX f2f1_ind(f2,f1), UNIQUE(f5)) |
|
126 |
ENGINE = $engine_type; |
|
127 |
eval
|
|
128 |
CREATE TABLE db_datadict_2.t4 |
|
129 |
(f1 INT NOT NULL, PRIMARY KEY(f1), f2 INT, INDEX f2_ind(f2)) |
|
130 |
ENGINE = $engine_type; |
|
131 |
||
132 |
let $my_select = SELECT * FROM information_schema.statistics |
|
133 |
WHERE table_schema LIKE 'db_datadict%' |
|
134 |
ORDER BY table_schema,table_name,index_name,seq_in_index,column_name; |
|
135 |
let $my_show1 = SHOW GRANTS FOR 'testuser1'@'localhost'; |
|
136 |
let $my_show2 = SHOW GRANTS FOR 'testuser2'@'localhost'; |
|
137 |
eval $my_select; |
|
138 |
eval $my_show1; |
|
139 |
eval $my_show2; |
|
140 |
||
141 |
--echo # Establish connection testuser1 (user=testuser1)
|
|
142 |
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
|
|
143 |
connect (testuser1, localhost, testuser1, , test); |
|
144 |
# nothing visible for testuser1 |
|
145 |
eval $my_select; |
|
146 |
eval $my_show1; |
|
147 |
--error ER_DBACCESS_DENIED_ERROR
|
|
148 |
eval $my_show2; |
|
149 |
||
150 |
--echo # Establish connection testuser2 (user=testuser2)
|
|
151 |
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
|
|
152 |
connect (testuser2, localhost, testuser2, , test); |
|
153 |
# nothing visible for testuser2 |
|
154 |
eval $my_select; |
|
155 |
--error ER_DBACCESS_DENIED_ERROR
|
|
156 |
eval $my_show1; |
|
157 |
eval $my_show2; |
|
158 |
||
159 |
--echo # Switch to connection default
|
|
160 |
connection default; |
|
161 |
GRANT SELECT ON db_datadict.t1 TO 'testuser1'@'localhost' WITH GRANT OPTION; |
|
162 |
GRANT SELECT(f1,f5) ON db_datadict_2.t3 TO 'testuser1'@'localhost'; |
|
163 |
eval $my_select; |
|
164 |
eval $my_show1; |
|
165 |
eval $my_show2; |
|
166 |
||
167 |
--echo # Switch to connection testuser1
|
|
168 |
connection testuser1; |
|
169 |
eval $my_select; |
|
170 |
eval $my_show1; |
|
171 |
--error ER_DBACCESS_DENIED_ERROR
|
|
172 |
eval $my_show2; |
|
173 |
||
174 |
--echo # Switch to connection testuser2
|
|
175 |
connection testuser2; |
|
176 |
eval $my_select; |
|
177 |
--error ER_DBACCESS_DENIED_ERROR
|
|
178 |
eval $my_show1; |
|
179 |
eval $my_show2; |
|
180 |
||
181 |
--echo # Switch to connection default
|
|
182 |
connection default; |
|
183 |
REVOKE SELECT,GRANT OPTION ON db_datadict.t1 FROM 'testuser1'@'localhost'; |
|
184 |
eval $my_show1; |
|
185 |
||
186 |
--echo # Switch to connection testuser1
|
|
187 |
# nothing visible for testuser1 |
|
188 |
connection testuser1; |
|
189 |
eval $my_select; |
|
190 |
eval $my_show1; |
|
191 |
||
192 |
# Cleanup |
|
193 |
--echo # Switch to connection default and close connections testuser1, testuser2
|
|
194 |
connection default; |
|
195 |
disconnect testuser1; |
|
196 |
disconnect testuser2; |
|
197 |
DROP USER 'testuser1'@'localhost'; |
|
198 |
DROP USER 'testuser2'@'localhost'; |
|
199 |
DROP DATABASE db_datadict; |
|
200 |
DROP DATABASE db_datadict_2; |
|
201 |
||
202 |
||
203 |
--echo #########################################################################
|
|
204 |
--echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.STATISTICS modifications
|
|
205 |
--echo #########################################################################
|
|
206 |
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or |
|
207 |
# column) automatically inserts all relevant information on that |
|
208 |
# object into every appropriate INFORMATION_SCHEMA table. |
|
209 |
# 3.2.1.14: Ensure that the alteration of any existing database object |
|
210 |
# automatically updates all relevant information on that object in |
|
211 |
# every appropriate INFORMATION_SCHEMA table. |
|
212 |
# 3.2.1.15: Ensure that the dropping of any existing database object |
|
213 |
# automatically deletes all relevant information on that object from |
|
214 |
# every appropriate INFORMATION_SCHEMA table. |
|
215 |
#
|
|
216 |
--disable_warnings
|
|
217 |
DROP TABLE IF EXISTS test.t1_my_table; |
|
218 |
DROP DATABASE IF EXISTS db_datadict; |
|
219 |
--enable_warnings
|
|
220 |
CREATE DATABASE db_datadict; |
|
221 |
--replace_result $other_engine_type <other_engine_type>
|
|
222 |
eval
|
|
223 |
CREATE TABLE test.t1_1 (f1 BIGINT, |
|
224 |
f2 TEXT, f2x TEXT, f3 CHAR(10), f3x CHAR(10), f4 BIGINT, f4x BIGINT, |
|
225 |
f5 POINT, f5x POINT NOT NULL) |
|
226 |
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci |
|
227 |
ENGINE = $other_engine_type; |
|
228 |
--replace_result $engine_type <engine_type>
|
|
229 |
eval
|
|
230 |
CREATE TABLE test.t1_2 (f1 BIGINT, f2 BIGINT) |
|
231 |
ENGINE = $engine_type; |
|
232 |
||
233 |
# Tables without primary key or index do not show up |
|
234 |
# in information_schema.statistics. |
|
235 |
SELECT table_name FROM information_schema.statistics |
|
236 |
WHERE table_name LIKE 't1_%'; |
|
237 |
# Check ADD PRIMARY KEY (two columns) |
|
238 |
ALTER TABLE test.t1_1 ADD PRIMARY KEY (f1,f3); |
|
239 |
SELECT * FROM information_schema.statistics |
|
240 |
WHERE table_name LIKE 't1_%' |
|
241 |
ORDER BY table_schema,table_name,index_name,seq_in_index,column_name; |
|
242 |
# Check DROP PRIMARY KEY |
|
243 |
ALTER TABLE test.t1_1 DROP PRIMARY KEY; |
|
244 |
SELECT table_name FROM information_schema.statistics |
|
245 |
WHERE table_name LIKE 't1_%'; |
|
246 |
# Check ADD PRIMARY KEY (one column) |
|
247 |
ALTER TABLE test.t1_1 ADD PRIMARY KEY (f1); |
|
248 |
SELECT * FROM information_schema.statistics |
|
249 |
WHERE table_name LIKE 't1_%'; |
|
250 |
# Some variations on index definitions |
|
251 |
# 1. No name assigned, one column |
|
252 |
ALTER TABLE test.t1_1 ADD INDEX (f4); |
|
253 |
# 2. Name assigned, two columns |
|
254 |
CREATE INDEX f3_f1 ON test.t1_1 (f3,f1); |
|
255 |
# 3. Unique index |
|
256 |
CREATE UNIQUE INDEX f4x_uni ON test.t1_1 (f4x); |
|
257 |
# 4. Index using HASH |
|
258 |
CREATE INDEX f2_hash USING HASH ON test.t1_2 (f2); |
|
259 |
# 5. Index with comment (feature introduced in 5.2) |
|
260 |
--error ER_PARSE_ERROR
|
|
261 |
CREATE INDEX f1_idx ON test.t1_2 (f1) COMMENT = 'COMMENT'; |
|
262 |
# 6. NOT NULL |
|
263 |
CREATE INDEX not_null ON test.t1_1 (f3x); |
|
264 |
# 7. Prefix index |
|
265 |
CREATE INDEX f2_prefix ON test.t1_1 (f2(20)); |
|
266 |
#
|
|
267 |
SELECT * FROM information_schema.statistics |
|
268 |
WHERE table_name LIKE 't1_%' AND index_name <> 'PRIMARY' |
|
269 |
ORDER BY table_schema,table_name,index_name,seq_in_index,column_name; |
|
270 |
--horizontal_results
|
|
271 |
DROP TABLE test.t1_2; |
|
272 |
#
|
|
273 |
# Check modification of TABLE_NAME |
|
274 |
SELECT DISTINCT table_name FROM information_schema.statistics |
|
275 |
WHERE table_name = 't1_1'; |
|
276 |
RENAME TABLE test.t1_1 TO test.t1_1x; |
|
277 |
SELECT DISTINCT table_name FROM information_schema.statistics |
|
278 |
WHERE table_name = 't1_1x'; |
|
279 |
#
|
|
280 |
# Check modification of TABLE_SCHEMA |
|
281 |
SELECT DISTINCT table_schema,table_name FROM information_schema.statistics |
|
282 |
WHERE table_name LIKE 't1_1%'; |
|
283 |
RENAME TABLE test.t1_1x TO db_datadict.t1_1x; |
|
284 |
SELECT DISTINCT table_schema,table_name FROM information_schema.statistics |
|
285 |
WHERE table_name LIKE 't1_1%'; |
|
286 |
#
|
|
287 |
# Check impact of DROP TABLE |
|
288 |
SELECT DISTINCT table_name FROM information_schema.statistics |
|
289 |
WHERE table_name = 't1_1x'; |
|
290 |
DROP TABLE db_datadict.t1_1x; |
|
291 |
SELECT DISTINCT table_name FROM information_schema.statistics |
|
292 |
WHERE table_name = 't1_1x'; |
|
293 |
#
|
|
294 |
# Check a temporary table (not visible) |
|
295 |
--replace_result $engine_type <engine_type>
|
|
296 |
eval
|
|
297 |
CREATE TEMPORARY TABLE test.t1_1x (PRIMARY KEY(f1,f2)) |
|
298 |
ENGINE = $engine_type |
|
299 |
AS SELECT 1 AS f1, 2 AS f2; |
|
300 |
--vertical_results
|
|
301 |
SELECT * FROM information_schema.statistics |
|
302 |
WHERE table_name = 't1_1x'; |
|
303 |
--horizontal_results
|
|
304 |
DROP TEMPORARY TABLE test.t1_1x; |
|
305 |
#
|
|
306 |
# Check impact of DROP SCHEMA |
|
307 |
--replace_result $engine_type <engine_type>
|
|
308 |
eval
|
|
309 |
CREATE TABLE db_datadict.t1_1x (PRIMARY KEY(f1)) |
|
310 |
ENGINE = $engine_type |
|
311 |
AS SELECT 1 AS f1, 2 AS f2; |
|
312 |
SELECT table_name FROM information_schema.statistics |
|
313 |
WHERE table_name = 't1_1x'; |
|
314 |
DROP DATABASE db_datadict; |
|
315 |
SELECT table_name FROM information_schema.statistics |
|
316 |
WHERE table_name = 't1_1x'; |
|
317 |
||
318 |
||
319 |
--echo ########################################################################
|
|
320 |
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
|
|
321 |
--echo # DDL on INFORMATION_SCHEMA tables are not supported
|
|
322 |
--echo ########################################################################
|
|
323 |
# 3.2.1.3: Ensure that no user may execute an INSERT statement on any |
|
324 |
# INFORMATION_SCHEMA table. |
|
325 |
# 3.2.1.4: Ensure that no user may execute an UPDATE statement on any |
|
326 |
# INFORMATION_SCHEMA table. |
|
327 |
# 3.2.1.5: Ensure that no user may execute a DELETE statement on any |
|
328 |
# INFORMATION_SCHEMA table. |
|
329 |
# 3.2.1.8: Ensure that no user may create an index on an |
|
330 |
# INFORMATION_SCHEMA table. |
|
331 |
# 3.2.1.9: Ensure that no user may alter the definition of an |
|
332 |
# INFORMATION_SCHEMA table. |
|
333 |
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table. |
|
334 |
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any |
|
335 |
# other database. |
|
336 |
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data |
|
337 |
# in an INFORMATION_SCHEMA table. |
|
338 |
#
|
|
339 |
--disable_warnings
|
|
340 |
DROP DATABASE IF EXISTS db_datadict; |
|
341 |
--enable_warnings
|
|
342 |
CREATE DATABASE db_datadict; |
|
343 |
--replace_result $engine_type <engine_type>
|
|
344 |
eval
|
|
345 |
CREATE TABLE db_datadict.t1 (f1 BIGINT) |
|
346 |
ENGINE = $engine_type; |
|
347 |
||
348 |
--error ER_DBACCESS_DENIED_ERROR
|
|
349 |
INSERT INTO information_schema.statistics |
|
350 |
SELECT * FROM information_schema.statistics; |
|
351 |
||
352 |
--error ER_DBACCESS_DENIED_ERROR
|
|
353 |
UPDATE information_schema.statistics SET table_schema = 'test' |
|
354 |
WHERE table_name = 't1'; |
|
355 |
||
356 |
--error ER_DBACCESS_DENIED_ERROR
|
|
357 |
DELETE FROM information_schema.statistics WHERE table_name = 't1'; |
|
358 |
--error ER_DBACCESS_DENIED_ERROR
|
|
359 |
TRUNCATE information_schema.statistics; |
|
360 |
||
361 |
--error ER_DBACCESS_DENIED_ERROR
|
|
362 |
CREATE INDEX my_idx_on_statistics |
|
363 |
ON information_schema.statistics(table_schema); |
|
364 |
||
365 |
--error ER_DBACCESS_DENIED_ERROR
|
|
366 |
ALTER TABLE information_schema.statistics DROP PRIMARY KEY; |
|
367 |
--error ER_DBACCESS_DENIED_ERROR
|
|
368 |
ALTER TABLE information_schema.statistics ADD f1 INT; |
|
369 |
||
370 |
--error ER_DBACCESS_DENIED_ERROR
|
|
371 |
DROP TABLE information_schema.statistics; |
|
372 |
||
373 |
--error ER_DBACCESS_DENIED_ERROR
|
|
374 |
ALTER TABLE information_schema.statistics RENAME db_datadict.statistics; |
|
375 |
--error ER_DBACCESS_DENIED_ERROR
|
|
376 |
ALTER TABLE information_schema.statistics RENAME information_schema.xstatistics; |
|
377 |
||
378 |
# Cleanup |
|
379 |
DROP DATABASE db_datadict; |
|
380 |