Debian Codegraph @

mysql-test/suite/funcs_1/t/is_statistics.test

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