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