MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
is_tables.inc
1 # suite/funcs_1/datadict/is_tables.inc
2 #
3 # Check the layout of information_schema.tables and the impact of
4 # CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it.
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 # Some results of the subtests depend on the storage engines assigned.
13 #
14 # Author:
15 # 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of
16 # testsuite funcs_1
17 # Create this script based on older scripts and new code.
18 # Last Change:
19 # 2008-06-11 mleich Move t/is_tables.test to this file and
20 # create variants for embedded/non embedded server.
21 #
22 
23 let $engine_type = MEMORY;
24 let $other_engine_type = MyISAM;
25 
26 let $is_table = TABLES;
27 
28 # The table INFORMATION_SCHEMA.TABLES 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.12.1: INFORMATION_SCHEMA.TABLES layout
42 --echo #########################################################################
43 # Ensure that the INFORMATION_SCHEMA.TABLES table has the following columns,
44 # in the following order:
45 #
46 # TABLE_CATALOG (always shows 'def'),
47 # TABLE_SCHEMA (shows the name of the database, or schema, in which an
48 # accessible table resides),
49 # TABLE_NAME (shows the name of a table which the current user may access),
50 # TABLE_TYPE (shows whether the table is a BASE TABLE, a TEMPORARY table,
51 # or a VIEW),
52 # ENGINE (shows the storage engine used for the table),
53 # VERSION (shows the version number of the table's .frm file),
54 # ROW_FORMAT (shows the table's row storage format; either FIXED, DYNAMIC
55 # or COMPRESSED),
56 # TABLE_ROWS (shows the number of rows in the table),
57 # AVG_ROW_LENGTH (shows the average length of the table's rows),
58 # DATA_LENGTH (shows the length of the table's data file),
59 # MAX_DATA_LENGTH (shows the maximum length of the table's data file),
60 # INDEX_LENGTH (shows the length of the index file associated with the table),
61 # DATA_FREE (shows the number of allocated, unused bytes),
62 # AUTO_INCREMENT (shows the next AUTO_INCREMENT value, where applicable),
63 # CREATE_TIME (shows the timestamp of the time the table was created),
64 # UPDATE_TIME (shows the timestamp of the time the table's data file was
65 # last updated),
66 # CHECK_TIME (shows the timestamp of the time the table was last checked),
67 # TABLE_COLLATION (shows the table's default collation),
68 # CHECKSUM (shows the live checksum value for the table, if any; otherwise NULL),
69 # CREATE_OPTIONS (shows any additional options used in the table's definition;
70 # otherwise NULL),
71 # TABLE_COMMENT (shows the comment added to the table's definition;
72 # otherwise NULL).
73 #
74 --source suite/funcs_1/datadict/datadict_bug_12777.inc
75 eval DESCRIBE information_schema.$is_table;
76 --source suite/funcs_1/datadict/datadict_bug_12777.inc
77 eval SHOW CREATE TABLE information_schema.$is_table;
78 --source suite/funcs_1/datadict/datadict_bug_12777.inc
79 eval SHOW COLUMNS FROM information_schema.$is_table;
80 
81 # Note: Retrieval of information within information_schema.columns about
82 # information_schema.tables is in is_columns_is.test.
83 
84 # Show that TABLE_CATALOG is always 'def'.
85 SELECT table_catalog, table_schema, table_name
86 FROM information_schema.tables WHERE table_catalog IS NULL OR table_catalog <> 'def';
87 
88 
89 --echo ################################################################################
90 --echo # Testcase 3.2.12.2 + 3.2.12.3: INFORMATION_SCHEMA.TABLES accessible information
91 --echo ################################################################################
92 # 3.2.12.2: Ensure that the table shows the relevant information on every base table
93 # and view on which the current user or PUBLIC has privileges.
94 # 3.2.12.3: Ensure that the table does not show any information on any tables
95 # on which the current user and public have no privileges.
96 #
97 # Note: Check of content within information_schema.tables about tables within
98 # database is in
99 # mysql is_tables_mysql.test
100 # information_schema is_tables_is.test
101 # test% is_tables_<engine>.test
102 #
103 --disable_warnings
104 DROP DATABASE IF EXISTS db_datadict;
105 --enable_warnings
106 CREATE DATABASE db_datadict;
107 
108 --error 0,ER_CANNOT_USER
109 DROP USER 'testuser1'@'localhost';
110 CREATE USER 'testuser1'@'localhost';
111 GRANT CREATE, CREATE VIEW, INSERT, SELECT ON db_datadict.*
112  TO 'testuser1'@'localhost' WITH GRANT OPTION;
113 --error 0,ER_CANNOT_USER
114 DROP USER 'testuser2'@'localhost';
115 CREATE USER 'testuser2'@'localhost';
116 --error 0,ER_CANNOT_USER
117 DROP USER 'testuser3'@'localhost';
118 CREATE USER 'testuser3'@'localhost';
119 
120 --replace_result $engine_type <engine_type>
121 eval
122 CREATE TABLE db_datadict.tb1 (f1 INT, f2 INT, f3 INT)
123 ENGINE = $engine_type;
124 
125 GRANT SELECT ON db_datadict.tb1 TO 'testuser1'@'localhost';
126 GRANT ALL ON db_datadict.tb1 TO 'testuser2'@'localhost' WITH GRANT OPTION;
127 
128 let $my_select = SELECT * FROM information_schema.tables
129 WHERE table_schema = 'db_datadict' ORDER BY table_name;
130 let $my_show = SHOW TABLES FROM db_datadict;
131 
132 --echo # Establish connection testuser1 (user=testuser1)
133 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
134 connect (testuser1, localhost, testuser1, , db_datadict);
135 # tb2 is not granted to anyone
136 --replace_result $engine_type <engine_type>
137 eval
138 CREATE TABLE tb2 (f1 DECIMAL)
139 ENGINE = $engine_type;
140 --replace_result $engine_type <engine_type>
141 eval
142 CREATE TABLE tb3 (f1 VARCHAR(200))
143 ENGINE = $engine_type;
144 GRANT SELECT ON db_datadict.tb3 to 'testuser3'@'localhost';
145 GRANT INSERT ON db_datadict.tb3 to 'testuser2'@'localhost';
146 CREATE VIEW v3 AS SELECT * FROM tb3;
147 GRANT SELECT ON db_datadict.v3 to 'testuser3'@'localhost';
148 
149 if ($have_bug_32285)
150 {
151 --disable_ps_protocol
152 }
153 # We do not want to check here values affected by
154 # - the storage engine used
155 # - Operating system / Filesystem
156 # - start time of test
157 # 1 TABLE_CATALOG
158 # 2 TABLE_SCHEMA
159 # 3 TABLE_NAME
160 # 4 TABLE_TYPE
161 # 5 ENGINE affected by storage engine used
162 # 6 VERSION
163 # 7 ROW_FORMAT affected by storage engine used
164 # 8 TABLE_ROWS
165 # 9 AVG_ROW_LENGTH affected by storage engine used
166 # 10 DATA_LENGTH affected by storage engine used and maybe OS
167 # 11 MAX_DATA_LENGTH affected by storage engine used and maybe OS
168 # 12 INDEX_LENGTH affected by storage engine used and maybe OS
169 # 13 DATA_FREE affected by storage engine used and maybe OS
170 # 14 AUTO_INCREMENT
171 # 15 CREATE_TIME depends roughly on start time of test (*)
172 # 16 UPDATE_TIME depends roughly on start time of test (*)
173 # 17 CHECK_TIME depends roughly on start time of test and storage engine (*)
174 # 18 TABLE_COLLATION
175 # 19 CHECKSUM affected by storage engine used
176 # 20 CREATE_OPTIONS
177 # 21 TABLE_COMMENT affected by some storage engines
178 # (*) In case of view or temporary table NULL.
179 --replace_column 5 "#ENG#" 7 "#RF#" 9 "#ARL#" 10 "#DL#" 11 "#MDL#" 12 "#IL#" 13 "#DF#" 15 "#CRT" 16 "#UT#" 17 "#CT#" 19 "#CS#"
180 eval $my_select;
181 --enable_ps_protocol
182 --sorted_result
183 eval $my_show;
184 
185 --echo # Establish connection testuser2 (user=testuser2)
186 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
187 connect (testuser2, localhost, testuser2, , db_datadict);
188 if ($have_bug_32285)
189 {
190 --disable_ps_protocol
191 }
192 --replace_column 5 "#ENG#" 7 "#RF#" 9 "#ARL#" 10 "#DL#" 11 "#MDL#" 12 "#IL#" 13 "#DF#" 15 "#CRT" 16 "#UT#" 17 "#CT#" 19 "#CS#"
193 eval $my_select;
194 --enable_ps_protocol
195 --sorted_result
196 eval $my_show;
197 
198 --echo # Establish connection testuser3 (user=testuser3)
199 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
200 connect (testuser3, localhost, testuser3, , db_datadict);
201 if ($have_bug_32285)
202 {
203 --disable_ps_protocol
204 }
205 --replace_column 5 "#ENG#" 7 "#RF#" 9 "#ARL#" 10 "#DL#" 11 "#MDL#" 12 "#IL#" 13 "#DF#" 15 "#CRT" 16 "#UT#" 17 "#CT#" 19 "#CS#"
206 eval $my_select;
207 --enable_ps_protocol
208 --sorted_result
209 eval $my_show;
210 
211 --echo # Switch to connection default (user=root)
212 connection default;
213 # we see only 'public' tables
214 if ($have_bug_32285)
215 {
216 --disable_ps_protocol
217 }
218 --replace_column 5 "#ENG#" 7 "#RF#" 9 "#ARL#" 10 "#DL#" 11 "#MDL#" 12 "#IL#" 13 "#DF#" 15 "#CRT" 16 "#UT#" 17 "#CT#" 19 "#CS#"
219 eval $my_select;
220 --enable_ps_protocol
221 --sorted_result
222 eval $my_show;
223 
224 # Cleanup
225 --echo # Close connection testuser1, testuser2, testuser3
226 disconnect testuser1;
227 disconnect testuser2;
228 disconnect testuser3;
229 DROP USER 'testuser1'@'localhost';
230 DROP USER 'testuser2'@'localhost';
231 DROP USER 'testuser3'@'localhost';
232 DROP DATABASE db_datadict;
233 
234 
235 --echo #########################################################################
236 --echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.TABLES modifications
237 --echo #########################################################################
238 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
239 # column) automatically inserts all relevant information on that
240 # object into every appropriate INFORMATION_SCHEMA table.
241 # 3.2.1.14: Ensure that the alteration of any existing database object
242 # automatically updates all relevant information on that object in
243 # every appropriate INFORMATION_SCHEMA table.
244 # 3.2.1.15: Ensure that the dropping of any existing database object
245 # automatically deletes all relevant information on that object from
246 # every appropriate INFORMATION_SCHEMA table.
247 #
248 --disable_warnings
249 DROP TABLE IF EXISTS test.t1_my_table;
250 DROP DATABASE IF EXISTS db_datadict;
251 --enable_warnings
252 CREATE DATABASE db_datadict;
253 
254 SELECT table_name FROM information_schema.tables
255 WHERE table_name LIKE 't1_my_table%';
256 --replace_result $engine_type <engine_type>
257 eval
258 CREATE TABLE test.t1_my_table (f1 BIGINT)
259 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
260 COMMENT = 'Initial Comment' ENGINE = $engine_type;
261 # Settings used in CREATE TABLE must be visible in information_schema.tables.
262 --vertical_results
263 --replace_column 5 "#ENG#" 7 "#RF#" 9 "#ARL#" 10 "#DL#" 11 "#MDL#" 12 "#IL#" 13 "#DF#" 15 "#CRT" 16 "#UT#" 17 "#CT#" 19 "#CS#"
264 SELECT * FROM information_schema.tables
265 WHERE table_name = 't1_my_table';
266 --horizontal_results
267 #
268 # Check modification of TABLE_NAME
269 SELECT table_name FROM information_schema.tables
270 WHERE table_name LIKE 't1_my_table%';
271 RENAME TABLE test.t1_my_table TO test.t1_my_tablex;
272 SELECT table_name FROM information_schema.tables
273 WHERE table_name LIKE 't1_my_table%';
274 #
275 # Check modification of TABLE_SCHEMA
276 SELECT table_schema,table_name FROM information_schema.tables
277 WHERE table_name = 't1_my_tablex';
278 RENAME TABLE test.t1_my_tablex TO db_datadict.t1_my_tablex;
279 SELECT table_schema,table_name FROM information_schema.tables
280 WHERE table_name = 't1_my_tablex';
281 #
282 # Check modification of ENGINE
283 --replace_result $engine_type <engine_type>
284 SELECT table_name, engine FROM information_schema.tables
285 WHERE table_name = 't1_my_tablex';
286 --replace_result $other_engine_type <other_engine_type>
287 eval
288 ALTER TABLE db_datadict.t1_my_tablex
289 ENGINE = $other_engine_type;
290 --replace_result $other_engine_type <other_engine_type>
291 SELECT table_name, engine FROM information_schema.tables
292 WHERE table_name = 't1_my_tablex';
293 #
294 # Check modification of TABLE_ROWS
295 SELECT table_name, table_rows FROM information_schema.tables
296 WHERE table_name = 't1_my_tablex';
297 INSERT INTO db_datadict.t1_my_tablex VALUES(1),(2);
298 SELECT table_name, table_rows FROM information_schema.tables
299 WHERE table_name = 't1_my_tablex';
300 #
301 # Check indirect modification of TABLE_COLLATION
302 SELECT table_name, table_collation FROM information_schema.tables
303 WHERE table_name = 't1_my_tablex';
304 ALTER TABLE db_datadict.t1_my_tablex DEFAULT CHARACTER SET utf8;
305 SELECT table_name, table_collation FROM information_schema.tables
306 WHERE table_name = 't1_my_tablex';
307 # Check direct modification of TABLE_COLLATION
308 SELECT table_name, table_collation FROM information_schema.tables
309 WHERE table_name = 't1_my_tablex';
310 ALTER TABLE db_datadict.t1_my_tablex
311 DEFAULT CHARACTER SET latin1 COLLATE latin1_german1_ci;
312 SELECT table_name, table_collation FROM information_schema.tables
313 WHERE table_name = 't1_my_tablex';
314 #
315 # Check modification of TABLE_COMMENT
316 SELECT table_name, TABLE_COMMENT FROM information_schema.tables
317 WHERE table_name = 't1_my_tablex';
318 ALTER TABLE db_datadict.t1_my_tablex COMMENT 'Changed Comment';
319 SELECT table_name, TABLE_COMMENT FROM information_schema.tables
320 WHERE table_name = 't1_my_tablex';
321 #
322 # Check modification of AUTO_INCREMENT
323 SELECT table_name, AUTO_INCREMENT FROM information_schema.tables
324 WHERE table_name = 't1_my_tablex';
325 ALTER TABLE db_datadict.t1_my_tablex
326 ADD f2 BIGINT AUTO_INCREMENT, ADD PRIMARY KEY (f2);
327 SELECT table_name, AUTO_INCREMENT FROM information_schema.tables
328 WHERE table_name = 't1_my_tablex';
329 #
330 # Check modification of ROW_FORMAT
331 SELECT table_name, ROW_FORMAT FROM information_schema.tables
332 WHERE table_name = 't1_my_tablex';
333 ALTER TABLE db_datadict.t1_my_tablex ROW_FORMAT = dynamic;
334 SELECT table_name, ROW_FORMAT FROM information_schema.tables
335 WHERE table_name = 't1_my_tablex';
336 #
337 # Check "growth" of UPDATE_TIME and modification of CHECKSUM
338 SELECT table_name, checksum FROM information_schema.tables
339 WHERE table_name = 't1_my_tablex';
340 ALTER TABLE db_datadict.t1_my_tablex CHECKSUM = 1;
341 SELECT table_name, checksum IS NOT NULL FROM information_schema.tables
342 WHERE table_name = 't1_my_tablex';
343 SELECT UPDATE_TIME, checksum INTO @UPDATE_TIME, @checksum
344 FROM information_schema.tables
345 WHERE table_name = 't1_my_tablex';
346 # Enforce a time difference bigger than the smallest unit (1 second).
347 --real_sleep 1.1
348 INSERT INTO db_datadict.t1_my_tablex SET f1 = 3;
349 FLUSH TABLES;
350 SELECT UPDATE_TIME > @UPDATE_TIME
351  AS "Is current UPDATE_TIME bigger than before last INSERT?"
352 FROM information_schema.tables
353 WHERE table_name = 't1_my_tablex';
354 SELECT checksum <> @checksum
355  AS "Is current CHECKSUM different than before last INSERT?"
356 FROM information_schema.tables
357 WHERE table_name = 't1_my_tablex';
358 #
359 # Information is used later
360 SELECT CREATE_TIME INTO @CREATE_TIME FROM information_schema.tables
361 WHERE table_name = 't1_my_tablex';
362 #
363 # Check impact of DROP TABLE
364 SELECT table_name FROM information_schema.tables
365 WHERE table_name LIKE 't1_my_table%';
366 DROP TABLE db_datadict.t1_my_tablex;
367 SELECT table_name FROM information_schema.tables
368 WHERE table_name LIKE 't1_my_table%';
369 #
370 # Check "growth" of CREATE_TIME
371 --replace_result $other_engine_type <other_engine_type>
372 eval
373 CREATE TABLE test.t1_my_tablex (f1 BIGINT)
374 ENGINE = $other_engine_type;
375 SELECT CREATE_TIME > @CREATE_TIME
376  AS "Is current CREATE_TIME bigger than for the old dropped table?"
377 FROM information_schema.tables
378 WHERE table_name = 't1_my_tablex';
379 DROP TABLE test.t1_my_tablex;
380 #
381 # Check a VIEW
382 CREATE VIEW test.t1_my_tablex AS SELECT 1;
383 --vertical_results
384 SELECT * FROM information_schema.tables
385 WHERE table_name = 't1_my_tablex';
386 --horizontal_results
387 DROP VIEW test.t1_my_tablex;
388 SELECT table_name FROM information_schema.tables
389 WHERE table_name = 't1_my_tablex';
390 #
391 # Check a temporary table
392 --replace_result $other_engine_type <other_engine_type>
393 eval
394 CREATE TEMPORARY TABLE test.t1_my_tablex
395 ENGINE = $other_engine_type
396  AS SELECT 1;
397 --vertical_results
398 SELECT table_name, table_type FROM information_schema.tables
399 WHERE table_name = 't1_my_tablex';
400 --horizontal_results
401 DROP TEMPORARY TABLE test.t1_my_tablex;
402 #
403 # Check impact of DROP SCHEMA
404 --replace_result $engine_type <engine_type>
405 eval
406 CREATE TABLE db_datadict.t1_my_tablex
407 ENGINE = $engine_type AS
408 SELECT 1;
409 SELECT table_name FROM information_schema.tables
410 WHERE table_name = 't1_my_tablex';
411 DROP DATABASE db_datadict;
412 SELECT table_name FROM information_schema.tables
413 WHERE table_name = 't1_my_tablex';
414 
415 
416 --echo ########################################################################
417 --echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
418 --echo # DDL on INFORMATION_SCHEMA tables are not supported
419 --echo ########################################################################
420 # 3.2.1.3: Ensure that no user may execute an INSERT statement on any
421 # INFORMATION_SCHEMA table.
422 # 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
423 # INFORMATION_SCHEMA table.
424 # 3.2.1.5: Ensure that no user may execute a DELETE statement on any
425 # INFORMATION_SCHEMA table.
426 # 3.2.1.8: Ensure that no user may create an index on an
427 # INFORMATION_SCHEMA table.
428 # 3.2.1.9: Ensure that no user may alter the definition of an
429 # INFORMATION_SCHEMA table.
430 # 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
431 # 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
432 # other database.
433 # 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
434 # in an INFORMATION_SCHEMA table.
435 #
436 --disable_warnings
437 DROP DATABASE IF EXISTS db_datadict;
438 --enable_warnings
439 CREATE DATABASE db_datadict;
440 --replace_result $engine_type <engine_type>
441 eval
442 CREATE TABLE db_datadict.t1 (f1 BIGINT)
443 ENGINE = $engine_type;
444 
445 --error ER_DBACCESS_DENIED_ERROR
446 INSERT INTO information_schema.tables
447 SELECT * FROM information_schema.tables;
448 
449 --error ER_DBACCESS_DENIED_ERROR
450 UPDATE information_schema.tables SET table_schema = 'test'
451 WHERE table_name = 't1';
452 
453 --error ER_DBACCESS_DENIED_ERROR
454 DELETE FROM information_schema.tables WHERE table_name = 't1';
455 --error ER_DBACCESS_DENIED_ERROR
456 TRUNCATE information_schema.tables;
457 
458 --error ER_DBACCESS_DENIED_ERROR
459 CREATE INDEX my_idx_on_tables ON information_schema.tables(table_schema);
460 
461 --error ER_DBACCESS_DENIED_ERROR
462 ALTER TABLE information_schema.tables DROP PRIMARY KEY;
463 --error ER_DBACCESS_DENIED_ERROR
464 ALTER TABLE information_schema.tables ADD f1 INT;
465 
466 --error ER_DBACCESS_DENIED_ERROR
467 DROP TABLE information_schema.tables;
468 
469 --error ER_DBACCESS_DENIED_ERROR
470 ALTER TABLE information_schema.tables RENAME db_datadict.tables;
471 --error ER_DBACCESS_DENIED_ERROR
472 ALTER TABLE information_schema.tables RENAME information_schema.xtables;
473 
474 # Cleanup
475 DROP DATABASE db_datadict;
476