File: innodb_pk_extension_on.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 (474 lines) | stat: -rw-r--r-- 21,658 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#
#  WL#6266 Make use of hidden key parts
#
#
# Optimizer switch use_index_extensions=on
#
set optimizer_switch= "use_index_extensions=on";
CREATE TABLE t1
(
pk_1 INT,
pk_2 INT,
f1 DATETIME,
f2 INT,
PRIMARY KEY(pk_1, pk_2),
KEY k1(f1),
KEY k2(f2)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES
(1, 1, '2000-01-01', 1), (1, 2, '2000-01-02', 2), (1, 3, '2000-01-03', 3), (1, 4, '2000-01-04', 4), (1, 5, '2000-01-05', 5),
(2, 1, '2000-01-01', 6), (2, 2, '2000-01-02', 7), (2, 3, '2000-01-03', 8), (2, 4, '2000-01-04', 9), (2, 5, '2000-01-05', 10),
(3, 1, '2000-01-01', 11), (3, 2, '2000-01-02', 12), (3, 3, '2000-01-03', 13), (3, 4, '2000-01-04', 14), (3, 5, '2000-01-05', 15),
(4, 1, '2000-01-01', 16), (4, 2, '2000-01-02', 17), (4, 3, '2000-01-03', 18), (4, 4, '2000-01-04', 19), (4, 5, '2000-01-05', 20),
(5, 1, '2000-01-01', 21), (5, 2, '2000-01-02', 22), (5, 3, '2000-01-03', 23), (5, 4, '2000-01-04', 24), (5, 5, '2000-01-05', 25),
(6, 1, '2000-01-06', 26), (6, 2, '2000-01-06', 27), (6, 3, '2000-01-03', 28), (6, 4, '2000-01-06', 29), (6, 5, '2000-01-06', 30),
(7, 1, '2000-01-06', 31), (7, 2, '2000-01-06', 32), (7, 3, '2000-01-03', 33), (7, 4, '2000-01-06', 34), (7, 5, '2000-01-06', 35),
(8, 1, '2000-01-06', 36), (8, 2, '2000-01-06', 37), (8, 3, '2000-01-03', 38), (8, 4, '2000-01-06', 39), (8, 5, '2000-01-06', 40),
(9, 1, '2000-01-06', 41), (9, 2, '2000-01-06', 42), (9, 3, '2000-01-03', 43), (9, 4, '2000-01-06', 44), (9, 5, '2000-01-06', 45);
INSERT INTO t1 VALUES
(11, 1, '2000-01-01', 1), (11, 2, '2000-01-02', 2), (11, 3, '2000-01-03', 3), (11, 4, '2000-01-04', 4), (11, 5, '2000-01-05', 5),
(12, 1, '2000-01-01', 6), (12, 2, '2000-01-02', 7), (12, 3, '2000-01-03', 8), (12, 4, '2000-01-04', 9), (12, 5, '2000-01-05', 10),
(13, 1, '2000-01-01', 11), (13, 2, '2000-01-02', 12), (13, 3, '2000-01-03', 13), (13, 4, '2000-01-04', 14), (13, 5, '2000-01-05', 15),
(14, 1, '2000-01-01', 16), (14, 2, '2000-01-02', 17), (14, 3, '2000-01-03', 18), (14, 4, '2000-01-04', 19), (14, 5, '2000-01-05', 20),
(15, 1, '2000-01-01', 1), (15, 2, '2000-01-02', 2), (15, 3, '2000-01-03', 3), (15, 4, '2000-01-04', 4), (15, 5, '2000-01-05', 5),
(16, 1, '2000-01-06', 6), (16, 2, '2000-01-06', 7), (16, 3, '2000-01-03', 8), (16, 4, '2000-01-06', 9), (16, 5, '2000-01-06', 10),
(17, 1, '2000-01-06', 31), (17, 2, '2000-01-06', 32), (17, 3, '2000-01-03', 33), (17, 4, '2000-01-06', 34), (17, 5, '2000-01-06', 35),
(18, 1, '2000-01-06', 36), (18, 2, '2000-01-06', 37), (18, 3, '2000-01-03', 38), (18, 4, '2000-01-06', 39), (18, 5, '2000-01-06', 40),
(19, 1, '2000-01-06', 1), (19, 2, '2000-01-06', 2), (19, 3, '2000-01-03', 3), (19, 4, '2000-01-06', 4), (19, 5, '2000-01-06', 5);
INSERT INTO t1 VALUES
(21, 1, '2000-01-01', 1), (21, 2, '2000-01-02', 2), (31, 3, '2000-01-03', 3), (41, 4, '2000-01-04', 4), (51, 5, '2000-01-05', 5),
(22, 1, '2000-01-01', 6), (22, 2, '2000-01-02', 7), (32, 3, '2000-01-03', 8), (42, 4, '2000-01-04', 9), (52, 5, '2000-01-05', 10),
(23, 1, '2000-01-01', 11), (23, 2, '2000-01-02', 12), (33, 3, '2000-01-03', 13), (43, 4, '2000-01-04', 14), (53, 5, '2000-01-05', 15),
(24, 1, '2000-01-01', 16), (24, 2, '2000-01-02', 17), (34, 3, '2000-01-03', 18), (44, 4, '2000-01-04', 19), (54, 5, '2000-01-05', 20),
(25, 1, '2000-01-01', 1), (25, 2, '2000-01-02', 2), (35, 3, '2000-01-03', 3), (45, 4, '2000-01-04', 4), (55, 5, '2000-01-05', 5),
(26, 1, '2000-01-06', 6), (26, 2, '2000-01-06', 7), (36, 3, '2000-01-03', 8), (46, 4, '2000-01-06', 9), (56, 5, '2000-01-06', 10),
(27, 1, '2000-01-06', 31), (27, 2, '2000-01-06', 32), (37, 3, '2000-01-03', 33), (47, 4, '2000-01-06', 34), (57, 5, '2000-01-06', 35),
(28, 1, '2000-01-06', 36), (28, 2, '2000-01-06', 37), (38, 3, '2000-01-03', 38), (48, 4, '2000-01-06', 39), (58, 5, '2000-01-06', 40),
(29, 1, '2000-01-06', 1), (29, 2, '2000-01-06', 2), (39, 3, '2000-01-03', 3), (49, 4, '2000-01-06', 4), (59, 5, '2000-01-06', 5);
INSERT INTO t1 SELECT pk_1 + 60, pk_2, f1, f2 FROM t1;
INSERT INTO t1 SELECT pk_1 + 120, pk_2, f1, f2 FROM t1;
INSERT INTO t1 SELECT pk_1 + 240, pk_2, f1, f2 FROM t1;
INSERT INTO t1 SELECT pk_1, pk_2 + 10, f1, f2 FROM t1;
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
#
# REF access optimization
#
EXPLAIN SELECT count(*) FROM t1 WHERE pk_1 = 3 and f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	PRIMARY,k1	k1	10	const,const	#	100.00	Using index
Warnings:
Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`t1` where ((`test`.`t1`.`f1` = TIMESTAMP'2000-01-03 00:00:00') and (`test`.`t1`.`pk_1` = 3))
FLUSH STATUS;
SELECT count(*) FROM t1 WHERE pk_1 = 3 and f1 = '2000-01-03';
count(*)
2
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	2
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
EXPLAIN SELECT pk_2 FROM t1 WHERE pk_1 = 3 and f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	PRIMARY,k1	k1	10	const,const	#	100.00	Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`pk_2` AS `pk_2` from `test`.`t1` where ((`test`.`t1`.`f1` = TIMESTAMP'2000-01-03 00:00:00') and (`test`.`t1`.`pk_1` = 3))
FLUSH STATUS;
SELECT pk_2 FROM t1 WHERE pk_1 = 3 and f1 = '2000-01-03';
pk_2
3
13
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	2
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
#
# RANGE access optimization
#
EXPLAIN SELECT count(*) FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	range	PRIMARY,k1	k1	10	NULL	#	100.00	Using where; Using index
Warnings:
Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`t1` where ((`test`.`t1`.`f1` = TIMESTAMP'2000-01-03 00:00:00') and (`test`.`t1`.`pk_1` between 3 and 5))
FLUSH STATUS;
SELECT count(*) FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
count(*)
6
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	6
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
EXPLAIN SELECT pk_1, pk_2 FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	range	PRIMARY,k1	k1	10	NULL	#	100.00	Using where; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`pk_1` AS `pk_1`,`test`.`t1`.`pk_2` AS `pk_2` from `test`.`t1` where ((`test`.`t1`.`f1` = TIMESTAMP'2000-01-03 00:00:00') and (`test`.`t1`.`pk_1` between 3 and 5))
FLUSH STATUS;
SELECT pk_1, pk_2 FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
pk_1	pk_2
3	3
3	13
4	3
4	13
5	3
5	13
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	6
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
#
# MAX/MIN optimization
#
EXPLAIN SELECT MIN(pk_1) FROM t1 WHERE f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select min(`test`.`t1`.`pk_1`) AS `MIN(pk_1)` from `test`.`t1` where multiple equal(TIMESTAMP'2000-01-03 00:00:00', `test`.`t1`.`f1`)
FLUSH STATUS;
SELECT MIN(pk_1) FROM t1 WHERE f1 = '2000-01-03';
MIN(pk_1)
1
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
EXPLAIN SELECT MIN(pk_1) FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select min(`test`.`t1`.`pk_1`) AS `MIN(pk_1)` from `test`.`t1` where ((`test`.`t1`.`pk_1` between 3 and 5) and multiple equal(TIMESTAMP'2000-01-03 00:00:00', `test`.`t1`.`f1`))
FLUSH STATUS;
SELECT MIN(pk_1) FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
MIN(pk_1)
3
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
EXPLAIN SELECT MAX(pk_1) FROM t1 WHERE f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select max(`test`.`t1`.`pk_1`) AS `MAX(pk_1)` from `test`.`t1` where multiple equal(TIMESTAMP'2000-01-03 00:00:00', `test`.`t1`.`f1`)
FLUSH STATUS;
SELECT MAX(pk_1) FROM t1 WHERE f1 = '2000-01-03';
MAX(pk_1)
459
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
EXPLAIN SELECT MAX(pk_1) FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	Select tables optimized away
Warnings:
Note	1003	/* select#1 */ select max(`test`.`t1`.`pk_1`) AS `MAX(pk_1)` from `test`.`t1` where ((`test`.`t1`.`pk_1` between 3 and 5) and multiple equal(TIMESTAMP'2000-01-03 00:00:00', `test`.`t1`.`f1`))
FLUSH STATUS;
SELECT MAX(pk_1) FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03';
MAX(pk_1)
5
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
#
# Loose index scan
#
EXPLAIN SELECT MIN(pk_1) FROM t1 WHERE f2 BETWEEN 13 AND 14 GROUP BY f2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	range	k2	k2	5	NULL	#	100.00	Using where; Using index for group-by
Warnings:
Note	1003	/* select#1 */ select min(`test`.`t1`.`pk_1`) AS `MIN(pk_1)` from `test`.`t1` where (`test`.`t1`.`f2` between 13 and 14) group by `test`.`t1`.`f2`
FLUSH STATUS;
SELECT MIN(pk_1) FROM t1 WHERE f2 BETWEEN 13 AND 14 GROUP BY f2;
MIN(pk_1)
3
3
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	4
Handler_read_last	1
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
EXPLAIN SELECT MIN(pk_1) FROM t1 WHERE f2 IN (1, 2) GROUP BY f2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	range	k2	k2	5	NULL	#	100.00	Using where; Using index for group-by
Warnings:
Note	1003	/* select#1 */ select min(`test`.`t1`.`pk_1`) AS `MIN(pk_1)` from `test`.`t1` where (`test`.`t1`.`f2` in (1,2)) group by `test`.`t1`.`f2`
FLUSH STATUS;
SELECT MIN(pk_1) FROM t1 WHERE f2 IN (1, 2) GROUP BY f2;
MIN(pk_1)
1
1
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	5
Handler_read_last	1
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
#
# JOIN optimization
#
EXPLAIN SELECT count(*) FROM t1 AS t1 JOIN t1 AS t2
ON t2.pk_1 = t1.pk_1 WHERE t1.f1 = '2000-01-03' AND t2.f1 = '2000-01-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	PRIMARY,k1	k1	6	const	#	100.00	Using index
1	SIMPLE	t2	NULL	ref	PRIMARY,k1	k1	10	const,test.t1.pk_1	#	100.00	Using index
Warnings:
Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`t1` join `test`.`t1` `t2` where ((`test`.`t2`.`pk_1` = `test`.`t1`.`pk_1`) and (`test`.`t2`.`f1` = TIMESTAMP'2000-01-03 00:00:00') and (`test`.`t1`.`f1` = TIMESTAMP'2000-01-03 00:00:00'))
FLUSH STATUS;
SELECT count(*) FROM t1 AS t1 JOIN t1 AS t2
ON t2.pk_1 = t1.pk_1 WHERE t1.f1 = '2000-01-03' AND t2.f1 = '2000-01-03';
count(*)
864
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	433
Handler_read_last	0
Handler_read_next	1296
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
#
# Optimization of sorting
# Also verifies FORMAT=tree for reverse ref access.
#
EXPLAIN SELECT f1, pk_1, pk_2 FROM t1 WHERE pk_1 = 3 AND f1 = '2000-01-03'
ORDER BY pk_2 DESC LIMIT 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	PRIMARY,k1	k1	10	const,const	#	100.00	Backward index scan; Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`pk_1` AS `pk_1`,`test`.`t1`.`pk_2` AS `pk_2` from `test`.`t1` where ((`test`.`t1`.`f1` = TIMESTAMP'2000-01-03 00:00:00') and (`test`.`t1`.`pk_1` = 3)) order by `test`.`t1`.`pk_2` desc limit 5
EXPLAIN FORMAT=tree SELECT f1, pk_1, pk_2 FROM t1 WHERE pk_1 = 3 AND f1 = '2000-01-03'
ORDER BY pk_2 DESC LIMIT 5;
EXPLAIN
-> Limit: 5 row(s)  (cost=0.45 rows=2)
    -> Covering index lookup on t1 using k1 (f1=TIMESTAMP'2000-01-03 00:00:00', pk_1=3) (reverse)  (cost=0.45 rows=2)

FLUSH STATUS;
SELECT f1, pk_1, pk_2 FROM t1 WHERE pk_1 = 3 AND f1 = '2000-01-03'
ORDER BY pk_2 DESC LIMIT 5;
f1	pk_1	pk_2
2000-01-03 00:00:00	3	13
2000-01-03 00:00:00	3	3
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	2
Handler_read_rnd	0
Handler_read_rnd_next	0
EXPLAIN SELECT f1, pk_1, pk_2 FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03'
ORDER BY pk_2 DESC LIMIT 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	range	PRIMARY,k1	k1	10	NULL	#	100.00	Using where; Using index; Using filesort
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`pk_1` AS `pk_1`,`test`.`t1`.`pk_2` AS `pk_2` from `test`.`t1` where ((`test`.`t1`.`f1` = TIMESTAMP'2000-01-03 00:00:00') and (`test`.`t1`.`pk_1` between 3 and 5)) order by `test`.`t1`.`pk_2` desc limit 5
FLUSH STATUS;
SELECT f1, pk_1, pk_2 FROM t1 WHERE pk_1 BETWEEN 3 AND 5 AND f1 = '2000-01-03'
ORDER BY pk_2 DESC LIMIT 5;
f1	pk_1	pk_2
2000-01-03 00:00:00	3	13
2000-01-03 00:00:00	4	13
2000-01-03 00:00:00	5	13
2000-01-03 00:00:00	3	3
2000-01-03 00:00:00	4	3
SHOW STATUS LIKE 'handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	1
Handler_read_last	0
Handler_read_next	6
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	0
DROP TABLE t1;
#
# Max key part limitation
#
CREATE TABLE t1
(
f1 INT, f2 INT, f3 INT, f4 INT, f5 INT, f6 INT, f7 INT, f8 INT, f9 INT, f10 INT,
f11 INT, f12 INT, f13 INT, f14 INT, f15 INT, f16 INT, f17 INT, f18 INT,
PRIMARY KEY (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10),
KEY k1 (f11, f12, f13, f14, f15, f16, f17)
) ENGINE = InnoDB;
EXPLAIN SELECT f17 FROM t1 FORCE INDEX (k1) WHERE
f1 = 0 AND f2 = 0 AND f3 = 0 AND f4 = 0 AND f5 = 0 AND
f6 = 0 AND f7 = 0 AND f8 = 0 AND f9 = 0 AND f10 = 0 AND
f11 = 0 AND f12 = 0 AND f13 = 0 AND f14 = 0 AND
f15 = 0 AND f16 = 0 AND f17 = 0;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	k1	k1	71	const,const,const,const,const,const,const,const,const,const,const,const,const,const,const,const	#	100.00	Using where
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`f17` AS `f17` from `test`.`t1` FORCE INDEX (`k1`) where ((`test`.`t1`.`f17` = 0) and (`test`.`t1`.`f16` = 0) and (`test`.`t1`.`f15` = 0) and (`test`.`t1`.`f14` = 0) and (`test`.`t1`.`f13` = 0) and (`test`.`t1`.`f12` = 0) and (`test`.`t1`.`f11` = 0) and (`test`.`t1`.`f10` = 0) and (`test`.`t1`.`f9` = 0) and (`test`.`t1`.`f8` = 0) and (`test`.`t1`.`f7` = 0) and (`test`.`t1`.`f6` = 0) and (`test`.`t1`.`f5` = 0) and (`test`.`t1`.`f4` = 0) and (`test`.`t1`.`f3` = 0) and (`test`.`t1`.`f2` = 0) and (`test`.`t1`.`f1` = 0))
EXPLAIN SELECT f17 FROM t1 FORCE INDEX (k1) WHERE
f1 = 0 AND f2 = 0 AND f3 = 0 AND f4 = 0 AND f5 = 0 AND
f6 = 0 AND f7 = 0 AND f8 = 0 AND f9 = 0 AND
f11 = 0 AND f12 = 0 AND f13 = 0 AND f14 = 0 AND
f15 = 0 AND f16 = 0 AND f17 = 0;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	k1	k1	71	const,const,const,const,const,const,const,const,const,const,const,const,const,const,const,const	#	100.00	Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`f17` AS `f17` from `test`.`t1` FORCE INDEX (`k1`) where ((`test`.`t1`.`f17` = 0) and (`test`.`t1`.`f16` = 0) and (`test`.`t1`.`f15` = 0) and (`test`.`t1`.`f14` = 0) and (`test`.`t1`.`f13` = 0) and (`test`.`t1`.`f12` = 0) and (`test`.`t1`.`f11` = 0) and (`test`.`t1`.`f9` = 0) and (`test`.`t1`.`f8` = 0) and (`test`.`t1`.`f7` = 0) and (`test`.`t1`.`f6` = 0) and (`test`.`t1`.`f5` = 0) and (`test`.`t1`.`f4` = 0) and (`test`.`t1`.`f3` = 0) and (`test`.`t1`.`f2` = 0) and (`test`.`t1`.`f1` = 0))
DROP TABLE t1;
#
# Max key length limitation
#
CREATE TABLE t1
(
f1 VARCHAR(500), f2 VARCHAR(500), f3 VARCHAR(500),
f4 VARCHAR(500), f5 VARCHAR(500), f6 VARCHAR(500),
f7 VARCHAR(500),
PRIMARY KEY (f1, f2, f3, f4),
KEY k1 (f5, f6, f7)
) charset latin1 ENGINE = InnoDB;
EXPLAIN SELECT f5 FROM t1 FORCE INDEX (k1) WHERE
f1 = 'a' AND f2 = 'a' AND f3 = 'a' AND f4 = 'a' AND
f5 = 'a' AND f6 = 'a' AND f7 = 'a';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	k1	k1	3015	const,const,const,const,const,const	#	100.00	Using where
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`f5` AS `f5` from `test`.`t1` FORCE INDEX (`k1`) where ((`test`.`t1`.`f7` = 'a') and (`test`.`t1`.`f6` = 'a') and (`test`.`t1`.`f5` = 'a') and (`test`.`t1`.`f4` = 'a') and (`test`.`t1`.`f3` = 'a') and (`test`.`t1`.`f2` = 'a') and (`test`.`t1`.`f1` = 'a'))
EXPLAIN SELECT f5 FROM t1 FORCE INDEX (k1) WHERE
f1 = 'a' AND f2 = 'a' AND f3 = 'a' AND
f5 = 'a' AND f6 = 'a' AND f7 = 'a';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	k1	k1	3015	const,const,const,const,const,const	#	100.00	Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`f5` AS `f5` from `test`.`t1` FORCE INDEX (`k1`) where ((`test`.`t1`.`f7` = 'a') and (`test`.`t1`.`f6` = 'a') and (`test`.`t1`.`f5` = 'a') and (`test`.`t1`.`f3` = 'a') and (`test`.`t1`.`f2` = 'a') and (`test`.`t1`.`f1` = 'a'))
EXPLAIN SELECT f5 FROM t1 FORCE INDEX (k1) WHERE
f1 = 'a' AND f2 = 'a' AND f4 = 'a' AND
f5 = 'a' AND f6 = 'a' AND f7 = 'a';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	NULL	ref	k1	k1	2513	const,const,const,const,const	#	100.00	Using where
Warnings:
Note	1003	/* select#1 */ select `test`.`t1`.`f5` AS `f5` from `test`.`t1` FORCE INDEX (`k1`) where ((`test`.`t1`.`f7` = 'a') and (`test`.`t1`.`f6` = 'a') and (`test`.`t1`.`f5` = 'a') and (`test`.`t1`.`f4` = 'a') and (`test`.`t1`.`f2` = 'a') and (`test`.`t1`.`f1` = 'a'))
DROP TABLE t1;
#
# Unique extended key
#
CREATE TABLE t1
(
pk INT NOT NULL auto_increment,
f1 INT NOT NULL,
KEY (f1),
PRIMARY KEY (pk)
) ENGINE = INNODB;
CREATE TABLE t2
(
f1 INT,
f2 INT
) ENGINE = INNODB;
INSERT INTO t1(f1) VALUES (1),(2);
INSERT INTO t1(f1) SELECT f1 + 2 FROM t1;
INSERT INTO t1(f1) SELECT f1 + 4 FROM t1;
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
INSERT INTO t2 VALUES (1,1), (2,2);
EXPLAIN SELECT t2.f1 FROM t2 JOIN t1 IGNORE INDEX(primary) ON t2.f1 = t1.pk and t2.f2 = t1.f1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
1	SIMPLE	t1	NULL	eq_ref	f1	f1	8	test.t2.f2,test.t2.f1	1	100.00	Using index
Warnings:
Note	1003	/* select#1 */ select `test`.`t2`.`f1` AS `f1` from `test`.`t2` join `test`.`t1` IGNORE INDEX (PRIMARY) where ((`test`.`t1`.`f1` = `test`.`t2`.`f2`) and (`test`.`t1`.`pk` = `test`.`t2`.`f1`))
FLUSH STATUS;
SELECT t2.f1 FROM t2 JOIN t1 IGNORE INDEX(primary) ON t2.f1 = t1.pk and t2.f2 = t1.f1;
f1
1
2
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	1
Handler_read_key	3
Handler_read_last	0
Handler_read_next	0
Handler_read_prev	0
Handler_read_rnd	0
Handler_read_rnd_next	3
DROP TABLE t1, t2;
#
# Bug#20430526 ADDRESSSANITIZER: HEAP-BUFFER-OVERFLOW IN
#              FIELD_BLOB::GET_KEY_IMAGE FLOAT8STORE
#
CREATE TABLE t1
(a GEOMETRY NOT NULL SRID 0, SPATIAL KEY(a)) ENGINE=INNODB;
INSERT INTO t1 VALUES (point(7, 7));
SELECT st_astext(a) FROM t1 WHERE st_equals(a, point(7, 7));
st_astext(a)
POINT(7 7)
DROP TABLE t1;
#
# Bug #31617858 INCORRECT RESULTS WHEN USING INDEX ON LONG CHARACTER COLS.
#
CREATE TABLE t(
a VARCHAR(256) NOT NULL,
i VARCHAR(512) NOT NULL,
PRIMARY KEY (a),
KEY (i)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO t VALUES
('aaa12345678','aaa'), ('aaa2','aaa'), ('aaa4','aaa'),
('aaa3','aaa'),('aaa1','aaa');
ANALYZE TABLE t;
Table	Op	Msg_type	Msg_text
test.t	analyze	status	OK
EXPLAIN SELECT DISTINCT(i) FROM t FORCE INDEX(i) WHERE a LIKE '%aaa12345678%';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t	NULL	index	i	i	2050	NULL	5	20.00	Using where
Warnings:
Note	1003	/* select#1 */ select distinct `test`.`t`.`i` AS `i` from `test`.`t` FORCE INDEX (`i`) where (`test`.`t`.`a` like '%aaa12345678%')
SELECT DISTINCT(i) FROM t FORCE INDEX(i) WHERE a LIKE '%aaa12345678%';
i
aaa
DROP TABLE t;
set optimizer_switch=default;