1
# suite/funcs_1/t/is_columns.test
3
# Check the layout of information_schema.columns and the impact of
4
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA/COLUMN ... on its content.
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.
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.
19
# --source suite/funcs_1/datadict/datadict.pre
21
let $engine_type = MEMORY;
22
let $other_engine_type = MyISAM;
24
let $is_table = COLUMNS;
26
# The table INFORMATION_SCHEMA.COLUMNS 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.6.1: INFORMATION_SCHEMA.COLUMNS layout
40
--echo #########################################################################
41
# Ensure that the INFORMATION_SCHEMA.COLUMNS table has the following columns,
42
# in the following order:
44
# TABLE_CATALOG (always shows NULL),
45
# TABLE_SCHEMA (shows the name of the database, or schema, in which an
46
# accessible table resides),
47
# TABLE_NAME (shows the name of an accessible table),
48
# COLUMN_NAME (shows the name of a column within that table),
49
# ORDINAL_POSITION (shows the ordinal position of that column in that table),
50
# COLUMN_DEFAULT (shows the column's default value),
51
# IS_NULLABLE (shows whether the column may accept NULL values),
52
# DATA_TYPE (shows the column's defined data type; keyword only),
53
# CHARACTER_MAXIMUM_LENGTH (shows, for a string column, the column's defined
54
# maximum length in characters; otherwise NULL),
55
# CHARACTER_OCTET_LENGTH (shows, for a string column, the column's defined
56
# maximum length in octets; otherwise NULL),
57
# NUMERIC_PRECISION (shows, for a numeric column, the column's or data type's
58
# defined precision; otherwise NULL),
59
# NUMERIC_SCALE (shows, for a numeric column, the column's or data type's
60
# defined scale; otherwise NULL),
61
# CHARACTER_SET_NAME (shows, for a character string column, the column's default
62
# character set; otherwise NULL),
63
# COLLATION_NAME (shows, for a character string column, the column's default
64
# collation; otherwise NULL),
65
# COLUMN_TYPE (shows the column's complete, defined data type),
66
# COLUMN_KEY (shows whether the column is indexed; possible values are PRI if
67
# the column is part of a PRIMARY KEY, UNI if the column is part of a
68
# UNIQUE key, MUL if the column is part of an index key that allows
70
# EXTRA (shows any additional column definition information, e.g. whether the
71
# column was defined with the AUTO_INCREMENT attribute),
72
# PRIVILEGES (shows the privileges available to the user on the column),
73
# COLUMN_COMMENT (shows the comment, if any, defined for the comment;
75
# STORAGE (NDB specific)
76
# FORMAT (NDB specific)
78
--source suite/funcs_1/datadict/datadict_bug_12777.inc
79
eval DESCRIBE information_schema.$is_table;
80
--source suite/funcs_1/datadict/datadict_bug_12777.inc
81
eval SHOW CREATE TABLE information_schema.$is_table;
82
--source suite/funcs_1/datadict/datadict_bug_12777.inc
83
eval SHOW COLUMNS FROM information_schema.$is_table;
85
# Note: Retrieval of information within information_schema.columns about
86
# information_schema.columns is in is_columns_is.test.
88
# Show that TABLE_CATALOG is always NULL.
89
SELECT table_catalog, table_schema, table_name, column_name
90
FROM information_schema.columns WHERE table_catalog IS NOT NULL;
93
--echo ###############################################################################
94
--echo # Testcase 3.2.6.2 + 3.2.6.3: INFORMATION_SCHEMA.COLUMNS accessible information
95
--echo ###############################################################################
96
# 3.2.6.2: Ensure that the table shows the relevant information on the columns
97
# of every table that is accessible to the current user or to PUBLIC.
98
# 3.2.6.3: Ensure that the table does not show any information on the columns
99
# of any table which is not accessible to the current user or PUBLIC.
101
# Note: Check of content within information_schema.columns about
103
# mysql is_columns_mysql.test
104
# information_schema is_columns_is.test
105
# test% is_columns_<engine>.test
108
DROP DATABASE IF EXISTS db_datadict;
110
CREATE DATABASE db_datadict;
112
--error 0,ER_CANNOT_USER
113
DROP USER 'testuser1'@'localhost';
114
CREATE USER 'testuser1'@'localhost';
115
--error 0,ER_CANNOT_USER
116
DROP USER 'testuser2'@'localhost';
117
CREATE USER 'testuser2'@'localhost';
119
--replace_result $other_engine_type <other_engine_type>
121
CREATE TABLE db_datadict.t1
122
(f1 CHAR(10), f2 TEXT, f3 DATE, f4 INT AUTO_INCREMENT,
123
UNIQUE INDEX MUL_IDX(f1,f3), PRIMARY KEY (f4))
124
ENGINE = $other_engine_type;
125
CREATE VIEW db_datadict.v1 AS SELECT 1 AS f1, 1 AS f2;
126
GRANT SELECT(f1, f2) ON db_datadict.t1 TO 'testuser1'@'localhost';
127
GRANT SELECT(f2) ON db_datadict.v1 TO 'testuser1'@'localhost';
129
--replace_result $other_engine_type <other_engine_type>
131
CREATE TABLE db_datadict.t2
132
(f1 CHAR(10), f2 TEXT, f3 DATE, f4 INT, PRIMARY KEY (f1,f4))
133
ENGINE = $other_engine_type;
134
GRANT INSERT(f1, f2) ON db_datadict.t2 TO 'testuser2'@'localhost';
136
let $my_select= SELECT * FROM information_schema.columns
137
WHERE table_schema = 'db_datadict'
138
ORDER BY table_schema, table_name, ordinal_position;
139
let $my_show1 = SHOW COLUMNS FROM db_datadict.t1;
140
let $my_show2 = SHOW COLUMNS FROM db_datadict.t2;
141
let $my_show3 = SHOW COLUMNS FROM db_datadict.v1;
143
# Point of view of user root.
144
--source suite/funcs_1/datadict/datadict_bug_12777.inc
150
--echo # Establish connection testuser1 (user=testuser1)
151
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
152
connect (testuser1, localhost, testuser1, , db_datadict);
153
--source suite/funcs_1/datadict/datadict_bug_12777.inc
156
--error ER_TABLEACCESS_DENIED_ERROR
160
--echo # Establish connection testuser2 (user=testuser2)
161
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
162
connect (testuser2, localhost, testuser2, , db_datadict);
163
--source suite/funcs_1/datadict/datadict_bug_12777.inc
165
--error ER_TABLEACCESS_DENIED_ERROR
168
--error ER_TABLEACCESS_DENIED_ERROR
171
--echo # Switch to connection default and close connections testuser1, testuser2
173
disconnect testuser1;
174
disconnect testuser2;
177
DROP USER 'testuser1'@'localhost';
178
DROP USER 'testuser2'@'localhost';
179
DROP DATABASE IF EXISTS db_datadict;
182
--echo ###############################################################################
183
--echo # Testcase 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.COLUMNS modifications
184
--echo ###############################################################################
185
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
186
# column) automatically inserts all relevant information on that
187
# object into every appropriate INFORMATION_SCHEMA table.
188
# 3.2.1.14: Ensure that the alteration of any existing database object
189
# automatically updates all relevant information on that object in
190
# every appropriate INFORMATION_SCHEMA table.
191
# 3.2.1.15: Ensure that the dropping of any existing database object
192
# automatically deletes all relevant information on that object from
193
# every appropriate INFORMATION_SCHEMA table.
196
DROP TABLE IF EXISTS test.t1_my_table;
197
DROP DATABASE IF EXISTS db_datadict;
199
CREATE DATABASE db_datadict;
201
SELECT table_name FROM information_schema.columns
202
WHERE table_name LIKE 't1_my_table%';
203
--replace_result $engine_type <engine_type>
205
CREATE TABLE test.t1_my_table (f1 CHAR(12))
206
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
207
ENGINE = $engine_type;
208
# Settings used in CREATE TABLE must be visible in information_schema.columns.
210
SELECT * FROM information_schema.columns
211
WHERE table_name = 't1_my_table';
214
# Check modification of TABLE_NAME
215
SELECT table_name FROM information_schema.columns
216
WHERE table_name LIKE 't1_my_table%';
217
RENAME TABLE test.t1_my_table TO test.t1_my_tablex;
218
SELECT table_name FROM information_schema.columns
219
WHERE table_name LIKE 't1_my_table%';
221
# Check modification of TABLE_SCHEMA
222
SELECT table_schema,table_name FROM information_schema.columns
223
WHERE table_name = 't1_my_tablex';
224
RENAME TABLE test.t1_my_tablex TO db_datadict.t1_my_tablex;
225
SELECT table_schema,table_name FROM information_schema.columns
226
WHERE table_name = 't1_my_tablex';
228
# Check modification of COLUMN_NAME
229
SELECT table_name, column_name FROM information_schema.columns
230
WHERE table_name = 't1_my_tablex';
231
ALTER TABLE db_datadict.t1_my_tablex CHANGE COLUMN f1 first_col CHAR(12);
232
SELECT table_name, column_name FROM information_schema.columns
233
WHERE table_name = 't1_my_tablex';
235
# Check modification of COLUMN size
236
SELECT table_name, column_name, character_maximum_length,
237
character_octet_length, column_type
238
FROM information_schema.columns
239
WHERE table_name = 't1_my_tablex';
240
ALTER TABLE db_datadict.t1_my_tablex
241
MODIFY COLUMN first_col CHAR(20);
242
SELECT table_name, column_name, character_maximum_length,
243
character_octet_length, column_type
244
FROM information_schema.columns
245
WHERE table_name = 't1_my_tablex';
247
# Check modification of COLUMN type
248
SELECT table_name, column_name, character_maximum_length,
249
character_octet_length, column_type
250
FROM information_schema.columns
251
WHERE table_name = 't1_my_tablex';
252
ALTER TABLE db_datadict.t1_my_tablex
253
MODIFY COLUMN first_col VARCHAR(20);
254
SELECT table_name, column_name, character_maximum_length,
255
character_octet_length, column_type
256
FROM information_schema.columns
257
WHERE table_name = 't1_my_tablex';
259
# Check modify COLUMN DEFAULT
260
SELECT table_name, column_name, column_default
261
FROM information_schema.columns
262
WHERE table_name = 't1_my_tablex';
263
ALTER TABLE db_datadict.t1_my_tablex
264
MODIFY COLUMN first_col CHAR(10) DEFAULT 'hello';
265
SELECT table_name, column_name, column_default
266
FROM information_schema.columns
267
WHERE table_name = 't1_my_tablex';
269
# Check modify IS_NULLABLE
270
SELECT table_name, column_name, is_nullable
271
FROM information_schema.columns
272
WHERE table_name = 't1_my_tablex';
273
ALTER TABLE db_datadict.t1_my_tablex
274
MODIFY COLUMN first_col CHAR(10) NOT NULL;
275
SELECT table_name, column_name, is_nullable
276
FROM information_schema.columns
277
WHERE table_name = 't1_my_tablex';
279
# Check modify COLLATION
280
SELECT table_name, column_name, collation_name
281
FROM information_schema.columns
282
WHERE table_name = 't1_my_tablex';
283
ALTER TABLE db_datadict.t1_my_tablex
284
MODIFY COLUMN first_col CHAR(10) COLLATE 'latin1_general_cs';
285
SELECT table_name, column_name, collation_name
286
FROM information_schema.columns
287
WHERE table_name = 't1_my_tablex';
289
# Check modify CHARACTER SET
290
SELECT table_name, column_name, character_maximum_length,
291
character_octet_length, character_set_name
292
FROM information_schema.columns
293
WHERE table_name = 't1_my_tablex';
294
ALTER TABLE db_datadict.t1_my_tablex
295
MODIFY COLUMN first_col CHAR(10) CHARACTER SET utf8;
296
SELECT table_name, column_name, character_maximum_length,
297
character_octet_length, character_set_name
298
FROM information_schema.columns
299
WHERE table_name = 't1_my_tablex';
301
# Check modify COLUMN_COMMENT
302
SELECT table_name, column_name, column_comment
303
FROM information_schema.columns
304
WHERE table_name = 't1_my_tablex';
305
ALTER TABLE db_datadict.t1_my_tablex
306
MODIFY COLUMN first_col CHAR(10) COMMENT 'Hello';
307
SELECT table_name, column_name, column_comment
308
FROM information_schema.columns
309
WHERE table_name = 't1_my_tablex';
312
SELECT table_name, column_name
313
FROM information_schema.columns
314
WHERE table_name = 't1_my_tablex';
315
ALTER TABLE db_datadict.t1_my_tablex
316
ADD COLUMN second_col CHAR(10);
317
SELECT table_name, column_name
318
FROM information_schema.columns
319
WHERE table_name = 't1_my_tablex';
321
# Check switch ordinal position of column
322
SELECT table_name, column_name, ordinal_position
323
FROM information_schema.columns
324
WHERE table_name = 't1_my_tablex'
325
ORDER BY table_name, column_name;
326
ALTER TABLE db_datadict.t1_my_tablex
327
MODIFY COLUMN second_col CHAR(10) FIRST;
328
SELECT table_name, column_name, ordinal_position
329
FROM information_schema.columns
330
WHERE table_name = 't1_my_tablex'
331
ORDER BY table_name, column_name;
334
SELECT table_name, column_name
335
FROM information_schema.columns
336
WHERE table_name = 't1_my_tablex';
337
ALTER TABLE db_datadict.t1_my_tablex
338
DROP COLUMN first_col;
339
SELECT table_name, column_name
340
FROM information_schema.columns
341
WHERE table_name = 't1_my_tablex';
343
# Check set COLUMN UNIQUE
344
SELECT table_name, column_name, column_key
345
FROM information_schema.columns
346
WHERE table_name = 't1_my_tablex';
347
ALTER TABLE db_datadict.t1_my_tablex
348
ADD UNIQUE INDEX IDX(second_col);
349
SELECT table_name, column_name, column_key
350
FROM information_schema.columns
351
WHERE table_name = 't1_my_tablex';
353
# Check impact of DROP TABLE
354
SELECT table_name, column_name
355
FROM information_schema.columns
356
WHERE table_name = 't1_my_tablex';
357
DROP TABLE db_datadict.t1_my_tablex;
358
SELECT table_name, column_name
359
FROM information_schema.columns
360
WHERE table_name = 't1_my_tablex';
363
CREATE VIEW test.t1_my_tablex
364
AS SELECT 1 AS "col1", 'A' collate latin1_german1_ci AS "col2";
366
SELECT * FROM information_schema.columns
367
WHERE table_name = 't1_my_tablex'
368
ORDER BY table_name, column_name;
370
DROP VIEW test.t1_my_tablex;
371
SELECT table_name FROM information_schema.columns
372
WHERE table_name = 't1_my_tablex';
374
# Check impact of DROP SCHEMA
375
--replace_result $engine_type <engine_type>
377
CREATE TABLE db_datadict.t1_my_tablex
378
ENGINE = $engine_type AS
380
SELECT table_name FROM information_schema.columns
381
WHERE table_name = 't1_my_tablex';
382
DROP DATABASE db_datadict;
383
SELECT table_name FROM information_schema.columns
384
WHERE table_name = 't1_my_tablex';
387
--echo ########################################################################
388
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
389
--echo # DDL on INFORMATION_SCHEMA table are not supported
390
--echo ########################################################################
391
# 3.2.1.3: Ensure that no user may execute an INSERT statement on any
392
# INFORMATION_SCHEMA table.
393
# 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
394
# INFORMATION_SCHEMA table.
395
# 3.2.1.5: Ensure that no user may execute a DELETE statement on any
396
# INFORMATION_SCHEMA table.
397
# 3.2.1.8: Ensure that no user may create an index on an
398
# INFORMATION_SCHEMA table.
399
# 3.2.1.9: Ensure that no user may alter the definition of an
400
# INFORMATION_SCHEMA table.
401
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
402
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
404
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
405
# in an INFORMATION_SCHEMA table.
408
DROP DATABASE IF EXISTS db_datadict;
409
DROP TABLE IF EXISTS test.t1;
411
CREATE DATABASE db_datadict;
412
CREATE TABLE test.t1 (f1 BIGINT);
414
--error ER_DBACCESS_DENIED_ERROR
415
INSERT INTO information_schema.columns (table_schema,table_name,column_name)
416
VALUES('test','t1', 'f2');
417
--error ER_DBACCESS_DENIED_ERROR
418
INSERT INTO information_schema.columns (table_schema,table_name,column_name)
419
VALUES('test','t2', 'f1');
421
--error ER_DBACCESS_DENIED_ERROR
422
UPDATE information_schema.columns SET table_name = 't4' WHERE table_name = 't1';
424
--error ER_DBACCESS_DENIED_ERROR
425
DELETE FROM information_schema.columns WHERE table_name = 't1';
426
--error ER_DBACCESS_DENIED_ERROR
427
TRUNCATE information_schema.columns;
429
--error ER_DBACCESS_DENIED_ERROR
430
CREATE INDEX i3 ON information_schema.columns(table_name);
432
--error ER_DBACCESS_DENIED_ERROR
433
ALTER TABLE information_schema.columns ADD f1 INT;
435
--error ER_DBACCESS_DENIED_ERROR
436
DROP TABLE information_schema.columns;
438
--error ER_DBACCESS_DENIED_ERROR
439
ALTER TABLE information_schema.columns RENAME db_datadict.columns;
440
--error ER_DBACCESS_DENIED_ERROR
441
ALTER TABLE information_schema.columns RENAME information_schema.xcolumns;
445
DROP DATABASE db_datadict;