1 # suite/funcs_1/datadict/is_key_column_usage.inc
3 # Check the layout of information_schema.key_column_usage and the impact of
4 # CREATE/ALTER/DROP TABLE/VIEW/SCHEMA/COLUMN ... 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.
14 # 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of
16 # Create this script based on older scripts and new code.
18 # 2008-06-11 mleich Move t/is_key_column_usage.test to this file and
19 # create variants for embedded/non embedded server.
22 let $engine_type = MEMORY;
24 let $is_table = KEY_COLUMN_USAGE;
26 # The table INFORMATION_SCHEMA.KEY_COLUMN_USAGE must exist
27 eval SHOW TABLES FROM information_schema LIKE
'$is_table';
29 --echo #######################################################################
30 --echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
31 --echo #######################################################################
32 # Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT
33 # statement, just as if it were an ordinary user-defined table.
35 --source suite/funcs_1/datadict/is_table_query.inc
38 --echo #########################################################################
39 --echo # Testcase 3.2.7.1: INFORMATION_SCHEMA.KEY_COLUMN_USAGE layout
40 --echo #########################################################################
41 # Ensure that the INFORMATION_SCHEMA.KEY_COLUMN_USAGE table has the following
42 # columns, in the following order:
44 # CONSTRAINT_CATALOG (always shows NULL),
45 # CONSTRAINT_SCHEMA (shows the database, or schema, in which an accessible
46 # constraint, or index, resides),
47 # CONSTRAINT_NAME (shows the name of the accessible constraint),
48 # TABLE_CATALOG (always shows NULL),
49 # TABLE_SCHEMA (shows the database, or schema, in which the table constrained
50 # by that constraint resides),
51 # TABLE_NAME (shows the name of the table constrained by the constraint),
52 # COLUMN_NAME (shows the name of a column that is the index key, or part of
54 # ORDINAL_POSITION (shows the ordinal position of the column within the
56 # POSITION_IN_UNIQUE_CONSTRAINT (shows, for a foreign key column, the ordinal
57 # position of the referenced column within the referenced unique index;
60 # REFERENCED_TABLE_SCHEMA,
61 # REFERENCED_TABLE_NAME,
62 # REFERENCED_COLUMN_NAME
64 --source suite/funcs_1/datadict/datadict_bug_12777.inc
65 eval DESCRIBE information_schema.$is_table;
66 --source suite/funcs_1/datadict/datadict_bug_12777.inc
67 eval SHOW CREATE
TABLE information_schema.$is_table;
68 --source suite/funcs_1/datadict/datadict_bug_12777.inc
69 eval SHOW COLUMNS FROM information_schema.$is_table;
71 # Note: Retrieval of information within information_schema.columns about
72 # information_schema.key_column_usage is in is_columns_is.test.
74 # Show that CONSTRAINT_CATALOG and TABLE_CATALOG are always NULL.
75 SELECT constraint_catalog, constraint_schema,
constraint_name, table_catalog,
77 FROM information_schema.key_column_usage
78 WHERE constraint_catalog IS NOT NULL OR table_catalog IS NOT NULL;
81 --echo ########################################################################################
82 --echo # Testcase 3.2.7.2 + 3.2.7.3: INFORMATION_SCHEMA.KEY_COLUMN_USAGE accessible information
83 --echo ########################################################################################
84 # 3.2.7.2: Ensure that the table shows the relevant information on every column, defined to
85 # be part of an index key, which is accessible to the current user or to PUBLIC.
86 # 3.2.7.3: Ensure that the table does not show any information on any indexed column that is
87 # not accessible to the current user or PUBLIC.
90 DROP DATABASE IF EXISTS db_datadict;
92 CREATE DATABASE db_datadict;
94 --error 0,ER_CANNOT_USER
95 DROP USER
'testuser1'@
'localhost';
96 CREATE USER
'testuser1'@
'localhost';
97 --error 0,ER_CANNOT_USER
98 DROP USER
'testuser2'@
'localhost';
99 CREATE USER
'testuser2'@
'localhost';
103 --replace_result $engine_type <engine_type>
106 (f1 INT NOT NULL, PRIMARY
KEY(f1),
107 f2 INT, INDEX f2_ind(f2))
108 ENGINE = $engine_type;
109 GRANT SELECT ON t1_1
to 'testuser1'@'localhost';
111 --replace_result $engine_type <engine_type>
114 (f1 INT NOT NULL, PRIMARY
KEY(f1),
115 f2 INT, INDEX f2_ind(f2))
116 ENGINE = $engine_type;
117 GRANT SELECT ON t1_2
to 'testuser2'@'localhost';
118 #FIXME: add foreign keys
120 let $select= SELECT * FROM information_schema.key_column_usage
123 table_catalog, table_schema,
table_name, ordinal_position;
125 # show view of user root
128 --echo # Establish connection testuser1 (user=testuser1)
129 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
130 connect (testuser1, localhost, testuser1, , db_datadict);
133 --echo # Establish connection testuser2 (user=testuser2)
134 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
135 connect (testuser2, localhost, testuser2, , db_datadict);
139 --echo # Switch
to connection
default and close connections testuser1, testuser2
141 disconnect testuser1;
142 disconnect testuser2;
143 DROP USER
'testuser1'@
'localhost';
144 DROP USER
'testuser2'@
'localhost';
147 DROP DATABASE IF EXISTS db_datadict;
150 --echo ########################################################################################
151 --echo # Testcase 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.KEY_COLUMN_USAGE modifications
152 --echo ########################################################################################
153 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
154 # column) automatically inserts all relevant information on that
155 # object into every appropriate INFORMATION_SCHEMA table.
156 # 3.2.1.14: Ensure that the alteration of any existing database object
157 # automatically updates all relevant information on that object in
158 # every appropriate INFORMATION_SCHEMA table.
159 # 3.2.1.15: Ensure that the dropping of any existing database object
160 # automatically deletes all relevant information on that object from
161 # every appropriate INFORMATION_SCHEMA table.
164 DROP DATABASE IF EXISTS db_datadict;
167 CREATE DATABASE db_datadict;
169 SELECT table_name FROM information_schema.key_column_usage
170 WHERE table_name LIKE
't1_my_table%';
171 --replace_result $engine_type <engine_type>
174 (f1 CHAR(12), f2 TIMESTAMP, f4 BIGINT, PRIMARY
KEY(f1,f2))
175 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
176 ENGINE = $engine_type;
177 # Settings used in CREATE TABLE must be visible
178 # in information_schema.key_column_usage.
180 SELECT * FROM information_schema.key_column_usage
181 WHERE table_name =
't1_my_table';
184 # Check modification of TABLE_NAME
185 SELECT DISTINCT table_name FROM information_schema.key_column_usage
186 WHERE table_name LIKE
't1_my_table%';
188 SELECT DISTINCT table_name FROM information_schema.key_column_usage
189 WHERE table_name LIKE
't1_my_table%';
191 # Check modification of TABLE_SCHEMA
192 SELECT DISTINCT table_schema,table_name FROM information_schema.key_column_usage
193 WHERE table_name =
't1_my_tablex';
194 RENAME
TABLE test.t1_my_tablex TO db_datadict.t1_my_tablex;
195 SELECT DISTINCT table_schema,table_name FROM information_schema.key_column_usage
196 WHERE table_name =
't1_my_tablex';
198 # Check modification of COLUMN_NAME
199 SELECT DISTINCT
table_name, column_name FROM information_schema.key_column_usage
200 WHERE table_name =
't1_my_tablex'
202 ALTER
TABLE db_datadict.t1_my_tablex CHANGE COLUMN f1 first_col CHAR(12);
203 SELECT DISTINCT
table_name, column_name FROM information_schema.key_column_usage
204 WHERE table_name =
't1_my_tablex'
207 # Note: The size of the column list and the not very selective qualification
208 # is intended. I want to see that the schema names are equal and
209 # all records about 't1_my_tablex'.
210 let $my_select = SELECT constraint_schema,
constraint_name, table_schema,
212 FROM information_schema.key_column_usage
213 WHERE table_name =
't1_my_tablex'
217 # Check ADD INDEX being not UNIQUE (does not show up in key_column_usage)
219 CREATE INDEX f2 ON db_datadict.t1_my_tablex(f2);
221 DROP INDEX f2 ON db_datadict.t1_my_tablex;
223 # Check ADD UNIQUE INDEX without name explicit assigned
225 ALTER
TABLE db_datadict.t1_my_tablex ADD UNIQUE (f2);
227 DROP INDEX f2 ON db_datadict.t1_my_tablex;
229 # Check ADD UNIQUE INDEX with name explicit assigned
231 ALTER
TABLE db_datadict.t1_my_tablex ADD UNIQUE my_idx (f2);
233 DROP INDEX my_idx ON db_datadict.t1_my_tablex;
235 ALTER
TABLE db_datadict.t1_my_tablex ADD UNIQUE my_idx (f4,first_col);
240 ALTER
TABLE db_datadict.t1_my_tablex
241 DROP COLUMN first_col;
244 # Check impact of DROP TABLE
246 FROM information_schema.key_column_usage
247 WHERE table_name =
't1_my_tablex'
249 DROP
TABLE db_datadict.t1_my_tablex;
251 FROM information_schema.key_column_usage
252 WHERE table_name =
't1_my_tablex';
254 # No UNIQUE CONSTRAINT -> no entry in key_column_usage
255 SELECT table_name FROM information_schema.key_column_usage
256 WHERE table_name =
't1_my_tablex';
257 --replace_result $engine_type <engine_type>
259 CREATE
TABLE db_datadict.t1_my_tablex
260 ENGINE = $engine_type AS
262 SELECT table_name FROM information_schema.key_column_usage
263 WHERE table_name =
't1_my_tablex';
264 # UNIQUE CONSTRAINT -> entry in key_column_usage
265 ALTER
TABLE db_datadict.t1_my_tablex ADD PRIMARY
KEY(f1);
266 SELECT table_name FROM information_schema.key_column_usage
267 WHERE table_name =
't1_my_tablex';
269 # Check impact of DROP SCHEMA
270 SELECT table_name FROM information_schema.key_column_usage
271 WHERE table_name =
't1_my_tablex';
272 DROP DATABASE db_datadict;
273 SELECT table_name FROM information_schema.key_column_usage
274 WHERE table_name =
't1_my_tablex';
278 --echo ########################################################################
279 --echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
280 --echo # DDL on INFORMATION_SCHEMA
table are not supported
281 --echo ########################################################################
282 # 3.2.1.3: Ensure that no user may execute an INSERT statement on any
283 # INFORMATION_SCHEMA table.
284 # 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
285 # INFORMATION_SCHEMA table.
286 # 3.2.1.5: Ensure that no user may execute a DELETE statement on any
287 # INFORMATION_SCHEMA table.
288 # 3.2.1.8: Ensure that no user may create an index on an
289 # INFORMATION_SCHEMA table.
290 # 3.2.1.9: Ensure that no user may alter the definition of an
291 # INFORMATION_SCHEMA table.
292 # 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
293 # 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
295 # 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
296 # in an INFORMATION_SCHEMA table.
299 DROP DATABASE IF EXISTS db_datadict;
300 DROP
TABLE IF EXISTS db_datadict.t1;
302 CREATE DATABASE db_datadict;
303 --replace_result $engine_type <engine_type>
305 CREATE
TABLE db_datadict.t1 (f1 BIGINT)
306 ENGINE = $engine_type;
309 # 1. We can get here different error messages.
310 # 2. We do not want to unify the individual messages to the far to unspecific
311 # 'Got one of the listed errors'.
312 let $my_error_message =
313 ##### The previous statement must fail ######
314 # Server type | expected error name | expected error message
315 # --------------------------------------------------------------------------------------------------------------------
316 # not embedded | ER_DBACCESS_DENIED_ERROR | ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
317 # embedded | ER_NON_INSERTABLE_TABLE | ERROR HY000: The target table schemata of the INSERT is not insertable-into
318 # | or similar | or similar
321 --disable_abort_on_error
322 INSERT INTO information_schema.key_column_usage
323 (constraint_schema, constraint_name, table_name)
324 VALUES (
'mysql',
'primary',
'db');
327 --echo $my_error_message
330 --error ER_DBACCESS_DENIED_ERROR
331 INSERT INTO information_schema.key_column_usage
332 SELECT * FROM information_schema.key_column_usage;
334 --error ER_DBACCESS_DENIED_ERROR
335 UPDATE information_schema.key_column_usage
336 SET table_name =
'db1' WHERE constraint_name =
'primary';
338 --error ER_DBACCESS_DENIED_ERROR
339 DELETE FROM information_schema.key_column_usage WHERE table_name =
't1';
340 --error ER_DBACCESS_DENIED_ERROR
341 TRUNCATE information_schema.key_column_usage;
343 --error ER_DBACCESS_DENIED_ERROR
344 CREATE INDEX i3 ON information_schema.key_column_usage(table_name);
346 --error ER_DBACCESS_DENIED_ERROR
347 ALTER
TABLE information_schema.key_column_usage ADD f1 INT;
349 --error ER_DBACCESS_DENIED_ERROR
350 DROP
TABLE information_schema.key_column_usage;
352 --error ER_DBACCESS_DENIED_ERROR
353 ALTER
TABLE information_schema.key_column_usage
354 RENAME db_datadict.key_column_usage;
355 --error ER_DBACCESS_DENIED_ERROR
356 ALTER
TABLE information_schema.key_column_usage
357 RENAME information_schema.xkey_column_usage;
358 --enable_abort_on_error
361 DROP
TABLE db_datadict.t1;
362 DROP DATABASE db_datadict;