File: information_schema_statistics.result

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (238 lines) | stat: -rw-r--r-- 8,047 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
CREATE TEMPORARY TABLE t1 (f1 int, f2 int primary key, UNIQUE KEY (f1));
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
f1	int	YES	UNI	NULL	NULL
f2	int	NO	PRI	NULL	NULL
SHOW INDEXES FROM t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment	Visible	Expression
t1	0	PRIMARY	1	f2	A	0	NULL	NULL		BTREE			YES	NULL
t1	0	f1	1	f1	A	0	NULL	NULL	YES	BTREE			YES	NULL
SELECT * FROM information_schema.tmp_tables_columns;
ERROR 42S02: Unknown table 'TMP_TABLES_COLUMNS' in information_schema
SELECT * FROM information_schema.tmp_tables_keys;
ERROR 42S02: Unknown table 'TMP_TABLES_KEYS' in information_schema
DROP TEMPORARY TABLE t1;
CREATE TABLE t1 (f1 int);
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
FROM information_schema.tables WHERE table_name='t1';
TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE
test	t1	BASE TABLE
LOCK TABLE t1 READ;
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
FROM information_schema.tables WHERE table_name='t1';
TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE
test	t1	BASE TABLE
PREPARE st2 FROM
"SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE FROM
   information_schema.tables WHERE table_name='t1'";
EXECUTE st2;
TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE
test	t1	BASE TABLE
DEALLOCATE PREPARE st2;
UNLOCK TABLES;
DROP TABLE t1;
CREATE DATABASE abc;
CREATE TABLE abc.memorytable (id INT NOT NULL) ENGINE=MEMORY;
# restart
SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'abc';
DROP DATABASE abc;
#
# Bug#30769965
# duplicate entry for key 'primary' when querying
# information_schema.tables
#
# When we run I_S query, we attempt to update the table
# 'mysql.table_stats'.  There exists no entry in mysql.table_stats
# for table db1.t1, when I_S query started execution. Once the I_S
# query starts execution it sees only the snapshot image of
# mysql.table_stats. Meanwhile I_S query is still executing, there
# can be a thread that creates a table db1.t1. The I_S query being
# executed first would attempt to update the dynamic statistics for
# db1.t1.  This can lead to DUPLICATE KEY error.
#
# Case 1: Test using InnoDB table.
#
CREATE TABLE t0 (c0 INT);
INSERT INTO t0 VALUES (1),(2),(3),(4),(5);
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
# Wait just before inserting dynamic statistics for t0.
SET DEBUG_SYNC='before_insert_into_dd SIGNAL parked WAIT_FOR cont1';
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
# In another connection, query I_S.TABLES to cause
# dynamic statistics to be inserted before con1.
SET DEBUG_SYNC= 'now WAIT_FOR parked';
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
SET DEBUG_SYNC= 'now SIGNAL cont1';
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
# Cleanup
DROP TABLE t0;
SET GLOBAL DEBUG=DEFAULT;
SET DEBUG_SYNC = 'RESET';
#
# Case 2: Testing MYISAM table path.
#
CREATE TABLE t0 (c0 INT) ENGINE=MyISAM;
INSERT INTO t0 VALUES (1),(2),(3),(4),(5);
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
# Wait just before inserting dynamic statistics for t0.
SET DEBUG_SYNC='before_insert_into_dd SIGNAL parked WAIT_FOR cont1';
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
# In another connection, query I_S.TABLES to cause
# dynamic statistics to be inserted before con1.
SET DEBUG_SYNC= 'now WAIT_FOR parked';
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
SET DEBUG_SYNC= 'now SIGNAL cont1';
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
# Cleanup
DROP TABLE t0;
SET GLOBAL DEBUG=DEFAULT;
SET DEBUG_SYNC = 'RESET';
#
# Case 3: Test Case1 with ANALYZE TABLE and a I_S query running in
#         parallel. This is for Bug#31582758.
#
CREATE TABLE t0 (c0 INT);
INSERT INTO t0 VALUES (1),(2),(3),(4),(5);
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
INSERT INTO t0 SELECT * FROM t0;
# Wait just before inserting dynamic statistics for t0.
SET DEBUG_SYNC='before_insert_into_dd SIGNAL parked WAIT_FOR cont1';
ANALYZE TABLE t0;
# In another connection, query I_S.TABLES to cause
# dynamic statistics to be inserted before con1.
SET DEBUG_SYNC= 'now WAIT_FOR parked';
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
SET DEBUG_SYNC= 'now SIGNAL cont1';
Table	Op	Msg_type	Msg_text
test.t0	analyze	status	OK
SELECT TABLE_NAME, ENGINE, TABLE_ROWS
INTO @v1, @v2, @v3
FROM INFORMATION_SCHEMA.TABLES WHERE table_name='t0';
# Cleanup
DROP TABLE t0;
SET GLOBAL DEBUG=DEFAULT;
SET DEBUG_SYNC = 'RESET';
#
# Bug#33538106: There is a problem when calling the system table
# in stored function
#
# Verify that dynamic information from I_S reflects all changes also when
# queried from a stored function or prepared statement.
CREATE TABLE t1 (
org_id INT NOT NULL AUTO_INCREMENT,
org_code VARCHAR(16) NOT NULL,
PRIMARY KEY (org_id));
INSERT INTO t1 VALUES (NULL, '1');
INSERT INTO t1 VALUES (NULL, '2');
SET SESSION information_schema_stats_expiry = 0;
CREATE FUNCTION f1(table_name VARCHAR(64)) RETURNS INT
BEGIN
DECLARE dbname VARCHAR(32) DEFAULT 'test';
DECLARE nextid INT;
SELECT DATABASE() INTO dbname;
SELECT MAX(AUTO_INCREMENT) INTO nextid FROM information_schema.tables t WHERE
table_schema = dbname AND t.table_name = table_name;
RETURN nextid;
END;
/
PREPARE ps1 FROM 'SELECT MAX(AUTO_INCREMENT) = ? FROM information_schema.tables WHERE
table_schema = ? AND table_name = ?';
# Expect the value to be 3
SELECT MAX(AUTO_INCREMENT) FROM information_schema.tables t WHERE
table_schema = 'test' AND t.table_name = 't1';
MAX(AUTO_INCREMENT)
3
SELECT f1('t1') = 3;
f1('t1') = 3
1
SET @expected = 3;
SET @db = 'test';
SET @table = 't1';
EXECUTE ps1 USING @expected, @db, @table;
MAX(AUTO_INCREMENT) = ?
1
INSERT INTO t1 VALUES (NULL, '1');
# After additional insert the expected value is 4
SELECT MAX(AUTO_INCREMENT) FROM information_schema.tables t WHERE
table_schema = 'test' AND t.table_name = 't1';
MAX(AUTO_INCREMENT)
4
# When using a function
SELECT f1('t1') = 4;
f1('t1') = 4
1
# And also with a prepared statement
SET @expected = 4;
EXECUTE ps1 USING @expected, @db, @table;
MAX(AUTO_INCREMENT) = ?
1
# Testing caching of I_S.FILES
CREATE TABLE t2 (b CHAR(250), c CHAR(250));
# Procedure querying dynamic columns from I_S.FILES
CREATE PROCEDURE p2(tablespace VARCHAR(64))
BEGIN
SELECT DATA_FREE, FREE_EXTENTS, TOTAL_EXTENTS FROM information_schema.files WHERE
TABLESPACE_NAME = tablespace;
END;
/
# Convenince procedure to populate table with data to make dyanmic
# columns change
CREATE PROCEDURE populate_t2()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE (i <= 6000) DO
INSERT INTO t2 (b,c) VALUES (repeat('b', 250), repeat('c', 250));
SET i = i + 1;
END WHILE;
END; /
PREPARE ps2 FROM 'SELECT DATA_FREE, FREE_EXTENTS, TOTAL_EXTENTS FROM information_schema.files WHERE
TABLESPACE_NAME = ?';
# Query I_S for empty table
CALL p2('test/t2');
DATA_FREE	FREE_EXTENTS	TOTAL_EXTENTS
0	0	0
SET @tablespace = 'test/t2';
EXECUTE ps2 USING @tablepspace;
DATA_FREE	FREE_EXTENTS	TOTAL_EXTENTS
CALL populate_t2();
# Querying I_S after table has been populated must show updated values
CALL p2('test/t2');
DATA_FREE	FREE_EXTENTS	TOTAL_EXTENTS
4194304	2	11
EXECUTE ps2 USING @tablespace;
DATA_FREE	FREE_EXTENTS	TOTAL_EXTENTS
4194304	2	11
SELECT DATA_FREE, FREE_EXTENTS, TOTAL_EXTENTS FROM information_schema.files WHERE
TABLESPACE_NAME = 'test/t2';
DATA_FREE	FREE_EXTENTS	TOTAL_EXTENTS
4194304	2	11
# Cleanup
DROP PROCEDURE populate_t2;
DROP PROCEDURE p2;
DROP TABLE t2;
DEALLOCATE PREPARE ps1;
DROP FUNCTION f1;
DROP TABLE t1;
SET SESSION information_schema_stats_expiry = default;