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 23let $engine_type = MEMORY; 24let $other_engine_type = MyISAM; 25 26let $is_table = TABLES; 27 28# The table INFORMATION_SCHEMA.TABLES must exist 29eval 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 75eval DESCRIBE information_schema.$is_table; 76--source suite/funcs_1/datadict/datadict_bug_12777.inc 77eval SHOW CREATE TABLE information_schema.$is_table; 78--source suite/funcs_1/datadict/datadict_bug_12777.inc 79eval 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'. 85SELECT table_catalog, table_schema, table_name 86FROM 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 104DROP DATABASE IF EXISTS db_datadict; 105--enable_warnings 106CREATE DATABASE db_datadict; 107 108--error 0,ER_CANNOT_USER 109DROP USER 'testuser1'@'localhost'; 110CREATE USER 'testuser1'@'localhost'; 111GRANT CREATE, CREATE VIEW, INSERT, SELECT ON db_datadict.* 112 TO 'testuser1'@'localhost' WITH GRANT OPTION; 113--error 0,ER_CANNOT_USER 114DROP USER 'testuser2'@'localhost'; 115CREATE USER 'testuser2'@'localhost'; 116--error 0,ER_CANNOT_USER 117DROP USER 'testuser3'@'localhost'; 118CREATE USER 'testuser3'@'localhost'; 119 120--replace_result $engine_type <engine_type> 121eval 122CREATE TABLE db_datadict.tb1 (f1 INT, f2 INT, f3 INT) 123ENGINE = $engine_type; 124 125GRANT SELECT ON db_datadict.tb1 TO 'testuser1'@'localhost'; 126GRANT ALL ON db_datadict.tb1 TO 'testuser2'@'localhost' WITH GRANT OPTION; 127 128let $my_select = SELECT * FROM information_schema.tables 129WHERE table_schema = 'db_datadict' ORDER BY table_name; 130let $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 134connect (testuser1, localhost, testuser1, , db_datadict); 135# tb2 is not granted to anyone 136--replace_result $engine_type <engine_type> 137eval 138CREATE TABLE tb2 (f1 DECIMAL) 139ENGINE = $engine_type; 140--replace_result $engine_type <engine_type> 141eval 142CREATE TABLE tb3 (f1 VARCHAR(200)) 143ENGINE = $engine_type; 144GRANT SELECT ON db_datadict.tb3 to 'testuser3'@'localhost'; 145GRANT INSERT ON db_datadict.tb3 to 'testuser2'@'localhost'; 146CREATE VIEW v3 AS SELECT * FROM tb3; 147GRANT SELECT ON db_datadict.v3 to 'testuser3'@'localhost'; 148 149if ($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#" 180eval $my_select; 181--enable_ps_protocol 182--sorted_result 183eval $my_show; 184 185--echo # Establish connection testuser2 (user=testuser2) 186--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK 187connect (testuser2, localhost, testuser2, , db_datadict); 188if ($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#" 193eval $my_select; 194--enable_ps_protocol 195--sorted_result 196eval $my_show; 197 198--echo # Establish connection testuser3 (user=testuser3) 199--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK 200connect (testuser3, localhost, testuser3, , db_datadict); 201if ($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#" 206eval $my_select; 207--enable_ps_protocol 208--sorted_result 209eval $my_show; 210 211--echo # Switch to connection default (user=root) 212connection default; 213# we see only 'public' tables 214if ($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#" 219eval $my_select; 220--enable_ps_protocol 221--sorted_result 222eval $my_show; 223 224# Cleanup 225--echo # Close connection testuser1, testuser2, testuser3 226disconnect testuser1; 227disconnect testuser2; 228disconnect testuser3; 229DROP USER 'testuser1'@'localhost'; 230DROP USER 'testuser2'@'localhost'; 231DROP USER 'testuser3'@'localhost'; 232DROP 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 249DROP TABLE IF EXISTS test.t1_my_table; 250DROP DATABASE IF EXISTS db_datadict; 251--enable_warnings 252CREATE DATABASE db_datadict; 253 254SELECT table_name FROM information_schema.tables 255WHERE table_name LIKE 't1_my_table%'; 256--replace_result $engine_type <engine_type> 257eval 258CREATE TABLE test.t1_my_table (f1 BIGINT) 259DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci 260COMMENT = '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#" 264SELECT * FROM information_schema.tables 265WHERE table_name = 't1_my_table'; 266--horizontal_results 267# 268# Check modification of TABLE_NAME 269SELECT table_name FROM information_schema.tables 270WHERE table_name LIKE 't1_my_table%'; 271RENAME TABLE test.t1_my_table TO test.t1_my_tablex; 272SELECT table_name FROM information_schema.tables 273WHERE table_name LIKE 't1_my_table%'; 274# 275# Check modification of TABLE_SCHEMA 276SELECT table_schema,table_name FROM information_schema.tables 277WHERE table_name = 't1_my_tablex'; 278RENAME TABLE test.t1_my_tablex TO db_datadict.t1_my_tablex; 279SELECT table_schema,table_name FROM information_schema.tables 280WHERE table_name = 't1_my_tablex'; 281# 282# Check modification of ENGINE 283--replace_result $engine_type <engine_type> 284SELECT table_name, engine FROM information_schema.tables 285WHERE table_name = 't1_my_tablex'; 286--replace_result $other_engine_type <other_engine_type> 287eval 288ALTER TABLE db_datadict.t1_my_tablex 289ENGINE = $other_engine_type; 290--replace_result $other_engine_type <other_engine_type> 291SELECT table_name, engine FROM information_schema.tables 292WHERE table_name = 't1_my_tablex'; 293# 294# Check modification of TABLE_ROWS 295SELECT table_name, table_rows FROM information_schema.tables 296WHERE table_name = 't1_my_tablex'; 297INSERT INTO db_datadict.t1_my_tablex VALUES(1),(2); 298SELECT table_name, table_rows FROM information_schema.tables 299WHERE table_name = 't1_my_tablex'; 300# 301# Check indirect modification of TABLE_COLLATION 302SELECT table_name, table_collation FROM information_schema.tables 303WHERE table_name = 't1_my_tablex'; 304ALTER TABLE db_datadict.t1_my_tablex DEFAULT CHARACTER SET utf8; 305SELECT table_name, table_collation FROM information_schema.tables 306WHERE table_name = 't1_my_tablex'; 307# Check direct modification of TABLE_COLLATION 308SELECT table_name, table_collation FROM information_schema.tables 309WHERE table_name = 't1_my_tablex'; 310ALTER TABLE db_datadict.t1_my_tablex 311DEFAULT CHARACTER SET latin1 COLLATE latin1_german1_ci; 312SELECT table_name, table_collation FROM information_schema.tables 313WHERE table_name = 't1_my_tablex'; 314# 315# Check modification of TABLE_COMMENT 316SELECT table_name, TABLE_COMMENT FROM information_schema.tables 317WHERE table_name = 't1_my_tablex'; 318ALTER TABLE db_datadict.t1_my_tablex COMMENT 'Changed Comment'; 319SELECT table_name, TABLE_COMMENT FROM information_schema.tables 320WHERE table_name = 't1_my_tablex'; 321# 322# Check modification of AUTO_INCREMENT 323SELECT table_name, AUTO_INCREMENT FROM information_schema.tables 324WHERE table_name = 't1_my_tablex'; 325ALTER TABLE db_datadict.t1_my_tablex 326ADD f2 BIGINT AUTO_INCREMENT, ADD PRIMARY KEY (f2); 327SELECT table_name, AUTO_INCREMENT FROM information_schema.tables 328WHERE table_name = 't1_my_tablex'; 329# 330# Check modification of ROW_FORMAT 331SELECT table_name, ROW_FORMAT FROM information_schema.tables 332WHERE table_name = 't1_my_tablex'; 333ALTER TABLE db_datadict.t1_my_tablex ROW_FORMAT = dynamic; 334SELECT table_name, ROW_FORMAT FROM information_schema.tables 335WHERE table_name = 't1_my_tablex'; 336# 337# Check "growth" of UPDATE_TIME and modification of CHECKSUM 338SELECT table_name, checksum FROM information_schema.tables 339WHERE table_name = 't1_my_tablex'; 340ALTER TABLE db_datadict.t1_my_tablex CHECKSUM = 1; 341SELECT table_name, checksum IS NOT NULL FROM information_schema.tables 342WHERE table_name = 't1_my_tablex'; 343SELECT UPDATE_TIME, checksum INTO @UPDATE_TIME, @checksum 344FROM information_schema.tables 345WHERE table_name = 't1_my_tablex'; 346# Enforce a time difference bigger than the smallest unit (1 second). 347--real_sleep 1.1 348INSERT INTO db_datadict.t1_my_tablex SET f1 = 3; 349FLUSH TABLES; 350SELECT UPDATE_TIME > @UPDATE_TIME 351 AS "Is current UPDATE_TIME bigger than before last INSERT?" 352FROM information_schema.tables 353WHERE table_name = 't1_my_tablex'; 354SELECT checksum <> @checksum 355 AS "Is current CHECKSUM different than before last INSERT?" 356FROM information_schema.tables 357WHERE table_name = 't1_my_tablex'; 358# 359# Information is used later 360SELECT CREATE_TIME INTO @CREATE_TIME FROM information_schema.tables 361WHERE table_name = 't1_my_tablex'; 362# 363# Check impact of DROP TABLE 364SELECT table_name FROM information_schema.tables 365WHERE table_name LIKE 't1_my_table%'; 366DROP TABLE db_datadict.t1_my_tablex; 367SELECT table_name FROM information_schema.tables 368WHERE table_name LIKE 't1_my_table%'; 369# 370# Check "growth" of CREATE_TIME 371--replace_result $other_engine_type <other_engine_type> 372eval 373CREATE TABLE test.t1_my_tablex (f1 BIGINT) 374ENGINE = $other_engine_type; 375SELECT CREATE_TIME > @CREATE_TIME 376 AS "Is current CREATE_TIME bigger than for the old dropped table?" 377FROM information_schema.tables 378WHERE table_name = 't1_my_tablex'; 379DROP TABLE test.t1_my_tablex; 380# 381# Check a VIEW 382CREATE VIEW test.t1_my_tablex AS SELECT 1; 383--vertical_results 384SELECT * FROM information_schema.tables 385WHERE table_name = 't1_my_tablex'; 386--horizontal_results 387DROP VIEW test.t1_my_tablex; 388SELECT table_name FROM information_schema.tables 389WHERE table_name = 't1_my_tablex'; 390# 391# Check a temporary table 392--replace_result $other_engine_type <other_engine_type> 393eval 394CREATE TEMPORARY TABLE test.t1_my_tablex 395ENGINE = $other_engine_type 396 AS SELECT 1; 397--vertical_results 398SELECT table_name, table_type FROM information_schema.tables 399WHERE table_name = 't1_my_tablex'; 400--horizontal_results 401DROP TEMPORARY TABLE test.t1_my_tablex; 402# 403# Check impact of DROP SCHEMA 404--replace_result $engine_type <engine_type> 405eval 406CREATE TABLE db_datadict.t1_my_tablex 407ENGINE = $engine_type AS 408SELECT 1; 409SELECT table_name FROM information_schema.tables 410WHERE table_name = 't1_my_tablex'; 411DROP DATABASE db_datadict; 412SELECT table_name FROM information_schema.tables 413WHERE 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 437DROP DATABASE IF EXISTS db_datadict; 438--enable_warnings 439CREATE DATABASE db_datadict; 440--replace_result $engine_type <engine_type> 441eval 442CREATE TABLE db_datadict.t1 (f1 BIGINT) 443ENGINE = $engine_type; 444 445--error ER_DBACCESS_DENIED_ERROR 446INSERT INTO information_schema.tables 447SELECT * FROM information_schema.tables; 448 449--error ER_DBACCESS_DENIED_ERROR 450UPDATE information_schema.tables SET table_schema = 'test' 451WHERE table_name = 't1'; 452 453--error ER_DBACCESS_DENIED_ERROR 454DELETE FROM information_schema.tables WHERE table_name = 't1'; 455--error ER_DBACCESS_DENIED_ERROR 456TRUNCATE information_schema.tables; 457 458--error ER_DBACCESS_DENIED_ERROR 459CREATE INDEX my_idx_on_tables ON information_schema.tables(table_schema); 460 461--error ER_DBACCESS_DENIED_ERROR 462ALTER TABLE information_schema.tables DROP PRIMARY KEY; 463--error ER_DBACCESS_DENIED_ERROR 464ALTER TABLE information_schema.tables ADD f1 INT; 465 466--error ER_DBACCESS_DENIED_ERROR 467DROP TABLE information_schema.tables; 468 469--error ER_DBACCESS_DENIED_ERROR 470ALTER TABLE information_schema.tables RENAME db_datadict.tables; 471--error ER_DBACCESS_DENIED_ERROR 472ALTER TABLE information_schema.tables RENAME information_schema.xtables; 473 474# Cleanup 475DROP DATABASE db_datadict; 476 477