File: histogram-debug.test

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 (335 lines) | stat: -rw-r--r-- 11,584 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
--source include/have_debug.inc

SET GLOBAL DEBUG="+d, parallel_read_buffering_print";

--echo #
--echo # Sampling on an empty table
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME='sampled_pages_read';

CREATE TABLE t1 (a INT);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';
DROP TABLE t1;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # Case where only root node is present
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;
SET DEBUG='+d,histogram_force_sampling';

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10), (20), (30), (40), (50), (60), (70), (80), (90), (100);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';
DROP TABLE t1;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = "module_sampling";
SET GLOBAL innodb_monitor_reset_all = "module_sampling";
SET DEBUG='-d,histogram_force_sampling';


--echo #
--echo # Case where only two levels is present with sampling_percentage = 50
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;
SET DEBUG='+d,histogram_force_sampling';

# Restrict the number of records in a page to 2
set global innodb_limit_optimistic_insert_debug = 2;

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10), (20), (30);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';
DROP TABLE t1;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";
set global innodb_limit_optimistic_insert_debug = 0;
SET DEBUG='-d,histogram_force_sampling';


--echo #
--echo # Case where only two levels is present with sampling_percentage = 100
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

# Restrict the number of records in a page to 2
set global innodb_limit_optimistic_insert_debug = 2;

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10), (20), (30);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';
DROP TABLE t1;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";
set global innodb_limit_optimistic_insert_debug = 0;


--echo #
--echo # Normal case with small dataset
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

# Restrict the number of records in a page to 2
set global innodb_limit_optimistic_insert_debug = 2;

CREATE TABLE t1 (a INT);

INSERT INTO t1 VALUES (10), (20), (30), (40), (50);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';
set global innodb_limit_optimistic_insert_debug = 0;
DROP TABLE t1;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # Check that histogram with sampling works as expected with large dataset
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

# Restrict the number of records in a page to 2
set global innodb_limit_optimistic_insert_debug = 2;
CREATE TABLE t1 (col1 DOUBLE);
INSERT INTO t1 SELECT RAND(1);
INSERT INTO t1 SELECT RAND(2) FROM t1;
INSERT INTO t1 SELECT RAND(3) FROM t1;
INSERT INTO t1 SELECT RAND(4) FROM t1;
INSERT INTO t1 SELECT RAND(5) FROM t1;
INSERT INTO t1 SELECT RAND(6) FROM t1;
INSERT INTO t1 SELECT RAND(7) FROM t1;
INSERT INTO t1 SELECT RAND(8) FROM t1;
INSERT INTO t1 SELECT RAND(9) FROM t1;
INSERT INTO t1 SELECT RAND(10) FROM t1;
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 5 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'col1';

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # Check that histogram with sampling works as expected with large dataset and different sampling percentage
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;
SET DEBUG='+d,histogram_force_sampling';

ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 50 BUCKETS;

SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'col1';
DROP TABLE t1;

set global innodb_limit_optimistic_insert_debug = 0;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";
SET DEBUG='-d,histogram_force_sampling';


--echo #
--echo # Normal case with small dataset with different sampling_percentage
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

SET DEBUG='+d,histogram_force_sampling';

# Restrict the number of records in a page to 2
set global innodb_limit_optimistic_insert_debug = 2;

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10), (20), (30), (40), (50), (60), (70), (80), (90), (100);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # Case to check if same rows are returned  for the same seed
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;

SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';

DROP TABLE t1;

set global innodb_limit_optimistic_insert_debug = 0;
SET DEBUG='-d,histogram_force_sampling';

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # Case were there is an error while buffering
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

SET DEBUG='+d,histogram_force_sampling';
SET GLOBAL DEBUG='+d,parallel_reader_histogram_induce_error';

# Restrict the number of records in a page to 2
set global innodb_limit_optimistic_insert_debug = 2;

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10), (20), (30), (40), (50), (60), (70), (80), (90), (100);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON a WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'a';
DROP TABLE t1;
set global innodb_limit_optimistic_insert_debug = 0;
SET GLOBAL DEBUG='-d,parallel_reader_histogram_induce_error';
SET DEBUG='-d,histogram_force_sampling';

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # Case were partitions are involved
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

CREATE TABLE p (col1 INT PRIMARY KEY, col2 INT, col3 INT)
               PARTITION BY KEY (col1) PARTITIONS 4;
INSERT INTO p VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);
ANALYZE TABLE p UPDATE HISTOGRAM ON col2 WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'col2';
DROP TABLE p;

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # Case were there is an error while buffering when partitions are involved
--echo #

SET GLOBAL innodb_monitor_enable = module_sampling;

SET DEBUG='+d,histogram_force_sampling';
SET GLOBAL DEBUG='+d,parallel_reader_histogram_induce_error';

# Restrict the number of records in a page to 2
set global innodb_limit_optimistic_insert_debug = 2;

CREATE TABLE p (col1 INT PRIMARY KEY, col2 INT, col3 INT)
               PARTITION BY KEY (col1) PARTITIONS 4;
INSERT INTO p VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);
ANALYZE TABLE p UPDATE HISTOGRAM ON col2 WITH 50 BUCKETS;
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'col2';

SELECT NAME,COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE SUBSYSTEM='sampling';

DROP TABLE p;
set global innodb_limit_optimistic_insert_debug = 0;
SET GLOBAL DEBUG='-d,parallel_reader_histogram_induce_error';
SET DEBUG='-d,histogram_force_sampling';

SET GLOBAL innodb_monitor_disable = module_sampling;
SET GLOBAL innodb_monitor_reset_all = "module_sampling";


--echo #
--echo # RAPID use case : Break from sampling after sampling half the records
--echo #

CREATE TABLE t1 (id int);
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);

SET DEBUG = "+d,sample_read_sample_half";
ANALYZE TABLE t1 UPDATE HISTOGRAM ON id WITH 50 BUCKETS;

SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'id';

SET DEBUG = "-d, sample_read_sample_half";

DROP TABLE t1;


--echo #
--echo # Error case where the table is discared
--echo #

CREATE TABLE t1 (id int);

# Discard tablespace to force histogram failure.
ALTER TABLE t1 DISCARD TABLESPACE;
ANALYZE TABLE t1 UPDATE HISTOGRAM ON id WITH 50 BUCKETS;

DROP TABLE t1;


--echo #
--echo # Simulated error case where parallel read thread returns error
--echo #

CREATE TABLE t1 (id int);
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);

SET GLOBAL DEBUG = "+d,simulate_sample_read_error";
ANALYZE TABLE t1 UPDATE HISTOGRAM ON id WITH 50 BUCKETS;

SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, JSON_REMOVE(histogram, '$."last-updated"') FROM information_schema.column_statistics WHERE COLUMN_NAME = 'id';

SET GLOBAL DEBUG = "-d,simulate_sample_read_error";

DROP TABLE t1;


--echo #
--echo # Cleanup
--echo #

SET GLOBAL innodb_monitor_enable = default;
SET GLOBAL innodb_monitor_disable = default;
SET GLOBAL innodb_monitor_reset_all = default;

SET GLOBAL DEBUG="-d, parallel_read_buffering_print";