1
# suite/funcs_1/t/is_statistics.test
3
# Check the layout of information_schema.statistics and the impact of
4
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... 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 = STATISTICS;
26
# The table INFORMATION_SCHEMA.STATISTICS 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.14.1: INFORMATION_SCHEMA.STATISTICS layout
40
--echo #########################################################################
41
# Ensure that the INFORMATION_SCHEMA.STATISTICS table has the following columns,
42
# in the following order:
44
# TABLE_CATALOG (always shows NULL),
45
# TABLE_SCHEMA (shows the database, or schema, in which a table indexed by
46
# an accessible index resides),
47
# TABLE_NAME (shows the name of the indexed table),
48
# NON_UNIQUE (shows whether the index may contain duplicate values;
49
# 0 if it cannot, 1 if it can),
50
# INDEX_SCHEMA (shows the database, or schema, in which an accessible
52
# INDEX_NAME (shows the name of an index which the current user may access),
53
# SEQ_IN_INDEX (shows the ordinal position of an indexed column within
55
# COLUMN_NAME (shows the name of a column that comprises some, or all, of an
57
# COLLATION (shows how the column is sorted in the index; either A for ascending
58
# or NULL for unsorted columns),
59
# CARDINALITY (shows the number of unique values in the index),
60
# SUB_PART (shows the number of indexed characters if the index is
62
# PACKED (shows how the index key is packed),
63
# NULLABLE (shows whether the index column may contain NULL values),
64
# INDEX_TYPE (shows the index type; either BTREE, FULLTEXT, HASH or RTREE),
65
# COMMENT (shows a comment on the index, if any).
68
--source suite/funcs_1/datadict/datadict_bug_12777.inc
69
eval DESCRIBE information_schema.$is_table;
70
--source suite/funcs_1/datadict/datadict_bug_12777.inc
71
eval SHOW CREATE TABLE information_schema.$is_table;
72
--source suite/funcs_1/datadict/datadict_bug_12777.inc
73
eval SHOW COLUMNS FROM information_schema.$is_table;
75
# Note: Retrieval of information within information_schema.columns about
76
# information_schema.statistics is in is_columns_is.test.
78
# Show that TABLE_CATALOG is always NULL.
79
SELECT table_catalog, table_schema, table_name, index_schema, index_name
80
FROM information_schema.statistics WHERE table_catalog IS NOT NULL;
83
--echo ####################################################################################
84
--echo # Testcase 3.2.14.2 + 3.2.14.3: INFORMATION_SCHEMA.STATISTICS accessible information
85
--echo ####################################################################################
86
# 3.2.14.2 Ensure that the table shows the relevant information on every index
87
# which the current user or PUBLIC may access (usually because
88
# privileges on the indexed table have been granted).
89
# 3.2.14.3 Ensure that the table does not show any information on any indexes
90
# which the current user and PUBLIC may not access.
92
# Note: Check of content within information_schema.statistics about
94
# mysql is_statistics_mysql.test
95
# information_schema is_statistics_is.test
98
DROP DATABASE IF EXISTS db_datadict;
99
DROP DATABASE IF EXISTS db_datadict_2;
101
CREATE DATABASE db_datadict;
102
CREATE DATABASE db_datadict_2;
104
--error 0,ER_CANNOT_USER
105
DROP USER 'testuser1'@'localhost';
106
CREATE USER 'testuser1'@'localhost';
107
--error 0,ER_CANNOT_USER
108
DROP USER 'testuser2'@'localhost';
109
CREATE USER 'testuser2'@'localhost';
111
--replace_result $engine_type <engine_type>
113
CREATE TABLE db_datadict.t1
114
(f1 INT NOT NULL, PRIMARY KEY(f1), f2 INT, INDEX f2_ind(f2))
115
ENGINE = $engine_type;
116
--replace_result $engine_type <engine_type>
118
CREATE TABLE db_datadict.t2
119
(f1 INT NOT NULL, PRIMARY KEY(f1), f2 INT, INDEX f2_ind(f2))
120
ENGINE = $engine_type;
123
CREATE TABLE db_datadict_2.t3
124
(f1 INT NOT NULL, f2 INT, f5 DATE,
125
PRIMARY KEY(f1), INDEX f2f1_ind(f2,f1), UNIQUE(f5))
126
ENGINE = $engine_type;
128
CREATE TABLE db_datadict_2.t4
129
(f1 INT NOT NULL, PRIMARY KEY(f1), f2 INT, INDEX f2_ind(f2))
130
ENGINE = $engine_type;
132
let $my_select = SELECT * FROM information_schema.statistics
133
WHERE table_schema LIKE 'db_datadict%'
134
ORDER BY table_schema,table_name,index_name,seq_in_index,column_name;
135
let $my_show1 = SHOW GRANTS FOR 'testuser1'@'localhost';
136
let $my_show2 = SHOW GRANTS FOR 'testuser2'@'localhost';
141
--echo # Establish connection testuser1 (user=testuser1)
142
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
143
connect (testuser1, localhost, testuser1, , test);
144
# nothing visible for testuser1
147
--error ER_DBACCESS_DENIED_ERROR
150
--echo # Establish connection testuser2 (user=testuser2)
151
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
152
connect (testuser2, localhost, testuser2, , test);
153
# nothing visible for testuser2
155
--error ER_DBACCESS_DENIED_ERROR
159
--echo # Switch to connection default
161
GRANT SELECT ON db_datadict.t1 TO 'testuser1'@'localhost' WITH GRANT OPTION;
162
GRANT SELECT(f1,f5) ON db_datadict_2.t3 TO 'testuser1'@'localhost';
167
--echo # Switch to connection testuser1
168
connection testuser1;
171
--error ER_DBACCESS_DENIED_ERROR
174
--echo # Switch to connection testuser2
175
connection testuser2;
177
--error ER_DBACCESS_DENIED_ERROR
181
--echo # Switch to connection default
183
REVOKE SELECT,GRANT OPTION ON db_datadict.t1 FROM 'testuser1'@'localhost';
186
--echo # Switch to connection testuser1
187
# nothing visible for testuser1
188
connection testuser1;
193
--echo # Switch to connection default and close connections testuser1, testuser2
195
disconnect testuser1;
196
disconnect testuser2;
197
DROP USER 'testuser1'@'localhost';
198
DROP USER 'testuser2'@'localhost';
199
DROP DATABASE db_datadict;
200
DROP DATABASE db_datadict_2;
203
--echo #########################################################################
204
--echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.STATISTICS modifications
205
--echo #########################################################################
206
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
207
# column) automatically inserts all relevant information on that
208
# object into every appropriate INFORMATION_SCHEMA table.
209
# 3.2.1.14: Ensure that the alteration of any existing database object
210
# automatically updates all relevant information on that object in
211
# every appropriate INFORMATION_SCHEMA table.
212
# 3.2.1.15: Ensure that the dropping of any existing database object
213
# automatically deletes all relevant information on that object from
214
# every appropriate INFORMATION_SCHEMA table.
217
DROP TABLE IF EXISTS test.t1_my_table;
218
DROP DATABASE IF EXISTS db_datadict;
220
CREATE DATABASE db_datadict;
221
--replace_result $other_engine_type <other_engine_type>
223
CREATE TABLE test.t1_1 (f1 BIGINT,
224
f2 TEXT, f2x TEXT, f3 CHAR(10), f3x CHAR(10), f4 BIGINT, f4x BIGINT,
225
f5 POINT, f5x POINT NOT NULL)
226
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
227
ENGINE = $other_engine_type;
228
--replace_result $engine_type <engine_type>
230
CREATE TABLE test.t1_2 (f1 BIGINT, f2 BIGINT)
231
ENGINE = $engine_type;
233
# Tables without primary key or index do not show up
234
# in information_schema.statistics.
235
SELECT table_name FROM information_schema.statistics
236
WHERE table_name LIKE 't1_%';
237
# Check ADD PRIMARY KEY (two columns)
238
ALTER TABLE test.t1_1 ADD PRIMARY KEY (f1,f3);
239
SELECT * FROM information_schema.statistics
240
WHERE table_name LIKE 't1_%'
241
ORDER BY table_schema,table_name,index_name,seq_in_index,column_name;
242
# Check DROP PRIMARY KEY
243
ALTER TABLE test.t1_1 DROP PRIMARY KEY;
244
SELECT table_name FROM information_schema.statistics
245
WHERE table_name LIKE 't1_%';
246
# Check ADD PRIMARY KEY (one column)
247
ALTER TABLE test.t1_1 ADD PRIMARY KEY (f1);
248
SELECT * FROM information_schema.statistics
249
WHERE table_name LIKE 't1_%';
250
# Some variations on index definitions
251
# 1. No name assigned, one column
252
ALTER TABLE test.t1_1 ADD INDEX (f4);
253
# 2. Name assigned, two columns
254
CREATE INDEX f3_f1 ON test.t1_1 (f3,f1);
256
CREATE UNIQUE INDEX f4x_uni ON test.t1_1 (f4x);
257
# 4. Index using HASH
258
CREATE INDEX f2_hash USING HASH ON test.t1_2 (f2);
259
# 5. Index with comment (feature introduced in 5.2)
260
--error ER_PARSE_ERROR
261
CREATE INDEX f1_idx ON test.t1_2 (f1) COMMENT = 'COMMENT';
263
CREATE INDEX not_null ON test.t1_1 (f3x);
265
CREATE INDEX f2_prefix ON test.t1_1 (f2(20));
267
SELECT * FROM information_schema.statistics
268
WHERE table_name LIKE 't1_%' AND index_name <> 'PRIMARY'
269
ORDER BY table_schema,table_name,index_name,seq_in_index,column_name;
271
DROP TABLE test.t1_2;
273
# Check modification of TABLE_NAME
274
SELECT DISTINCT table_name FROM information_schema.statistics
275
WHERE table_name = 't1_1';
276
RENAME TABLE test.t1_1 TO test.t1_1x;
277
SELECT DISTINCT table_name FROM information_schema.statistics
278
WHERE table_name = 't1_1x';
280
# Check modification of TABLE_SCHEMA
281
SELECT DISTINCT table_schema,table_name FROM information_schema.statistics
282
WHERE table_name LIKE 't1_1%';
283
RENAME TABLE test.t1_1x TO db_datadict.t1_1x;
284
SELECT DISTINCT table_schema,table_name FROM information_schema.statistics
285
WHERE table_name LIKE 't1_1%';
287
# Check impact of DROP TABLE
288
SELECT DISTINCT table_name FROM information_schema.statistics
289
WHERE table_name = 't1_1x';
290
DROP TABLE db_datadict.t1_1x;
291
SELECT DISTINCT table_name FROM information_schema.statistics
292
WHERE table_name = 't1_1x';
294
# Check a temporary table (not visible)
295
--replace_result $engine_type <engine_type>
297
CREATE TEMPORARY TABLE test.t1_1x (PRIMARY KEY(f1,f2))
298
ENGINE = $engine_type
299
AS SELECT 1 AS f1, 2 AS f2;
301
SELECT * FROM information_schema.statistics
302
WHERE table_name = 't1_1x';
304
DROP TEMPORARY TABLE test.t1_1x;
306
# Check impact of DROP SCHEMA
307
--replace_result $engine_type <engine_type>
309
CREATE TABLE db_datadict.t1_1x (PRIMARY KEY(f1))
310
ENGINE = $engine_type
311
AS SELECT 1 AS f1, 2 AS f2;
312
SELECT table_name FROM information_schema.statistics
313
WHERE table_name = 't1_1x';
314
DROP DATABASE db_datadict;
315
SELECT table_name FROM information_schema.statistics
316
WHERE table_name = 't1_1x';
319
--echo ########################################################################
320
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
321
--echo # DDL on INFORMATION_SCHEMA tables are not supported
322
--echo ########################################################################
323
# 3.2.1.3: Ensure that no user may execute an INSERT statement on any
324
# INFORMATION_SCHEMA table.
325
# 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
326
# INFORMATION_SCHEMA table.
327
# 3.2.1.5: Ensure that no user may execute a DELETE statement on any
328
# INFORMATION_SCHEMA table.
329
# 3.2.1.8: Ensure that no user may create an index on an
330
# INFORMATION_SCHEMA table.
331
# 3.2.1.9: Ensure that no user may alter the definition of an
332
# INFORMATION_SCHEMA table.
333
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
334
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
336
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
337
# in an INFORMATION_SCHEMA table.
340
DROP DATABASE IF EXISTS db_datadict;
342
CREATE DATABASE db_datadict;
343
--replace_result $engine_type <engine_type>
345
CREATE TABLE db_datadict.t1 (f1 BIGINT)
346
ENGINE = $engine_type;
348
--error ER_DBACCESS_DENIED_ERROR
349
INSERT INTO information_schema.statistics
350
SELECT * FROM information_schema.statistics;
352
--error ER_DBACCESS_DENIED_ERROR
353
UPDATE information_schema.statistics SET table_schema = 'test'
354
WHERE table_name = 't1';
356
--error ER_DBACCESS_DENIED_ERROR
357
DELETE FROM information_schema.statistics WHERE table_name = 't1';
358
--error ER_DBACCESS_DENIED_ERROR
359
TRUNCATE information_schema.statistics;
361
--error ER_DBACCESS_DENIED_ERROR
362
CREATE INDEX my_idx_on_statistics
363
ON information_schema.statistics(table_schema);
365
--error ER_DBACCESS_DENIED_ERROR
366
ALTER TABLE information_schema.statistics DROP PRIMARY KEY;
367
--error ER_DBACCESS_DENIED_ERROR
368
ALTER TABLE information_schema.statistics ADD f1 INT;
370
--error ER_DBACCESS_DENIED_ERROR
371
DROP TABLE information_schema.statistics;
373
--error ER_DBACCESS_DENIED_ERROR
374
ALTER TABLE information_schema.statistics RENAME db_datadict.statistics;
375
--error ER_DBACCESS_DENIED_ERROR
376
ALTER TABLE information_schema.statistics RENAME information_schema.xstatistics;
379
DROP DATABASE db_datadict;