1 # suite/funcs_1/datadict/is_tables.inc 
    3 # Check the layout of information_schema.tables and the impact of 
    4 # CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it. 
    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. 
   15 # 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of 
   17 #                   Create this script based on older scripts and new code. 
   19 # 2008-06-11 mleich Move t/is_tables.test to this file and 
   20 #                   create variants for embedded/non embedded server. 
   23 let $engine_type       = MEMORY;
 
   24 let $other_engine_type = MyISAM;
 
   26 let $is_table = TABLES;
 
   28 # The table INFORMATION_SCHEMA.TABLES must exist 
   29 eval SHOW TABLES FROM information_schema LIKE 
'$is_table';
 
   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. 
   37 --source suite/funcs_1/datadict/is_table_query.inc
 
   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: 
   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, 
   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 
   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 
   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; 
   71 # TABLE_COMMENT (shows the comment added to the table's definition; 
   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;
 
   81 # Note: Retrieval of information within information_schema.columns about 
   82 #       information_schema.tables is in is_columns_is.test. 
   84 # Show that TABLE_CATALOG is always 'def'. 
   86 FROM information_schema.tables WHERE table_catalog IS NULL OR table_catalog <> 
'def';
 
   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. 
   97 # Note: Check of content within information_schema.tables about tables within 
   99 #       mysql               is_tables_mysql.test 
  100 #       information_schema  is_tables_is.test 
  101 #       test%               is_tables_<engine>.test 
  104 DROP DATABASE IF EXISTS db_datadict;
 
  106 CREATE DATABASE db_datadict;
 
  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';
 
  120 --replace_result $engine_type <engine_type>
 
  122 CREATE 
TABLE db_datadict.tb1 (f1 INT, f2 INT, f3 INT)
 
  123 ENGINE = $engine_type;
 
  125 GRANT SELECT ON db_datadict.tb1 TO 
'testuser1'@
'localhost';
 
  126 GRANT ALL    ON db_datadict.tb1 TO 
'testuser2'@
'localhost' WITH GRANT OPTION;
 
  128 let $my_select = SELECT * FROM information_schema.tables
 
  130 let $my_show = SHOW TABLES FROM db_datadict;
 
  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>
 
  138 CREATE 
TABLE tb2 (f1 DECIMAL)
 
  139 ENGINE = $engine_type;
 
  140 --replace_result $engine_type <engine_type>
 
  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';
 
  151 --disable_ps_protocol
 
  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 
  161 # 5 ENGINE           affected by storage engine used 
  163 # 7 ROW_FORMAT       affected by storage engine used 
  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 
  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 (*) 
  175 # 19 CHECKSUM        affected by storage engine used 
  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#" 
  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);
 
  190 --disable_ps_protocol
 
  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#" 
  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);
 
  203 --disable_ps_protocol
 
  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#" 
  211 --echo # Switch 
to connection 
default (user=root)
 
  213 # we see only 'public' tables 
  216 --disable_ps_protocol
 
  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#" 
  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;
 
  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. 
  250 DROP DATABASE IF EXISTS db_datadict;
 
  252 CREATE DATABASE db_datadict;
 
  254 SELECT table_name FROM information_schema.tables
 
  255 WHERE table_name LIKE 
't1_my_table%';
 
  256 --replace_result $engine_type <engine_type>
 
  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. 
  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';
 
  268 # Check modification of TABLE_NAME 
  269 SELECT table_name FROM information_schema.tables
 
  270 WHERE table_name LIKE 
't1_my_table%';
 
  272 SELECT table_name FROM information_schema.tables
 
  273 WHERE table_name LIKE 
't1_my_table%';
 
  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';
 
  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>
 
  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';
 
  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';
 
  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';
 
  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';
 
  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';
 
  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';
 
  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). 
  348 INSERT INTO db_datadict.t1_my_tablex SET f1 = 3;
 
  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';
 
  359 # Information is used later 
  360 SELECT CREATE_TIME INTO @CREATE_TIME FROM information_schema.tables
 
  361 WHERE table_name = 
't1_my_tablex';
 
  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%';
 
  370 # Check "growth" of CREATE_TIME 
  371 --replace_result $other_engine_type <other_engine_type>
 
  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';
 
  382 CREATE VIEW 
test.t1_my_tablex AS SELECT 1;
 
  384 SELECT * FROM information_schema.tables
 
  385 WHERE table_name = 
't1_my_tablex';
 
  387 DROP VIEW 
test.t1_my_tablex;
 
  388 SELECT table_name FROM information_schema.tables
 
  389 WHERE table_name = 
't1_my_tablex';
 
  391 # Check a temporary table 
  392 --replace_result $other_engine_type <other_engine_type>
 
  395 ENGINE = $other_engine_type
 
  398 SELECT 
table_name, table_type FROM information_schema.tables
 
  399 WHERE table_name = 
't1_my_tablex';
 
  403 # Check impact of DROP SCHEMA 
  404 --replace_result $engine_type <engine_type>
 
  406 CREATE 
TABLE db_datadict.t1_my_tablex
 
  407 ENGINE = $engine_type AS
 
  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';
 
  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 
  433 # 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data 
  434 #           in an INFORMATION_SCHEMA table. 
  437 DROP DATABASE IF EXISTS db_datadict;
 
  439 CREATE DATABASE db_datadict;
 
  440 --replace_result $engine_type <engine_type>
 
  442 CREATE 
TABLE db_datadict.t1 (f1 BIGINT)
 
  443 ENGINE = $engine_type;
 
  445 --error ER_DBACCESS_DENIED_ERROR
 
  446 INSERT INTO information_schema.tables
 
  447 SELECT * FROM information_schema.tables;
 
  449 --error ER_DBACCESS_DENIED_ERROR
 
  450 UPDATE information_schema.tables SET table_schema = 
'test' 
  451 WHERE table_name = 
't1';
 
  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;
 
  458 --error ER_DBACCESS_DENIED_ERROR
 
  459 CREATE INDEX my_idx_on_tables ON information_schema.tables(table_schema);
 
  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;
 
  466 --error ER_DBACCESS_DENIED_ERROR
 
  467 DROP 
TABLE information_schema.tables;
 
  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;
 
  475 DROP DATABASE db_datadict;