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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
|
-- source include/have_innodb.inc
SET @save_opt= @@GLOBAL.innodb_prefix_index_cluster_optimization;
set global innodb_prefix_index_cluster_optimization = ON;
show variables like 'innodb_prefix_index_cluster_optimization';
SET @save_innodb_stats_persistent=@@GLOBAL.innodb_stats_persistent;
SET GLOBAL innodb_stats_persistent = OFF;
--echo # Create a table with a large varchar field that we index the prefix
--echo # of and ensure we only trigger cluster lookups when we expect it.
create table prefixinno (
id int not null,
fake_id int not null,
bigfield varchar(4096),
primary key(id),
index bigfield_idx (bigfield(32)),
index fake_id_bigfield_prefix (fake_id, bigfield(32))
) engine=innodb;
insert into prefixinno values (1, 1001, repeat('a', 1)),
(8, 1008, repeat('b', 8)),
(24, 1024, repeat('c', 24)),
(31, 1031, repeat('d', 31)),
(32, 1032, repeat('x', 32)),
(33, 1033, repeat('y', 33)),
(128, 1128, repeat('z', 128));
select * from prefixinno;
let $show_count_statement = show status like 'innodb_secondary_index_triggered_cluster_reads';
let $show_opt_statement = show status like 'innodb_secondary_index_triggered_cluster_reads_avoided';
--echo # Baseline sanity check: 0, 0.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select "no-op query";
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible for optimization.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where bigfield = repeat('d', 31);
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible for optimization, access via fake_id only.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where fake_id = 1031;
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible for optimization, access via fake_id of big row.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where fake_id = 1033;
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible for optimization.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where bigfield = repeat('x', 32);
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible for optimization.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where bigfield = repeat('y', 33);
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible, should not increment lookup counter.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where bigfield = repeat('b', 8);
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible, should not increment lookup counter.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where bigfield = repeat('c', 24);
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Should increment lookup counter.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
select id, bigfield from prefixinno where bigfield = repeat('z', 128);
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Disable optimization, confirm we still increment counter.
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
set global innodb_prefix_index_cluster_optimization = OFF;
select id, bigfield from prefixinno where fake_id = 1033;
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval select $count - $base_count into @cluster_lookups;
eval select $opt - $base_opt into @cluster_lookups_avoided;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
drop table prefixinno;
--echo # Multi-byte handling case
set global innodb_prefix_index_cluster_optimization = ON;
SET NAMES utf8mb4;
CREATE TABLE t1(
f1 varchar(10) CHARACTER SET UTF8MB4 COLLATE UTF8MB4_BIN,
INDEX (f1(3)))ENGINE=INNODB;
INSERT INTO t1 VALUES('a'), ('cccc'), ('až'), ('cčc'), ('ggᵷg'), ('¢¢');
INSERT INTO t1 VALUES('தமிழ்'), ('🐱🌑'), ('🌒'), ('🌑');
INSERT INTO t1 VALUES('😊me'), ('eu€'), ('ls¢');
--echo # Eligible - record length is shorter than prefix
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'a';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like 'c%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'až';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'தமிழ்';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like 'ggᵷ%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '😊%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'ls¢';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '¢¢%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '🐱🌑%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '🌑%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '🌒%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
DROP TABLE t1;
--echo # Multi-byte with minimum character length > 1 bytes
CREATE TABLE t1(
f1 varchar(10) CHARACTER SET UTF16 COLLATE UTF16_BIN,
INDEX (f1(3)))ENGINE=INNODB;
INSERT INTO t1 VALUES('a'), ('cccc'), ('až'), ('cčc'), ('ggᵷg'), ('¢¢');
INSERT INTO t1 VALUES('தமிழ்'), ('🐱🌑'), ('🌒'), ('🌑');
INSERT INTO t1 VALUES('😊me'), ('eu€'), ('ls¢');
--echo # Eligible - record length is shorter than prefix
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'a';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like 'c%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'až';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'தமிழ்';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like 'ggᵷ%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '😊%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 = 'ls¢';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX(`f1`) WHERE f1 like '¢¢%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '🐱🌑%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length is shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '🌑%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Eligible - record length is shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '🌒%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
DROP TABLE t1;
CREATE TABLE t1(
col1 INT,
col2 BLOB DEFAULT NULL,
INDEX `idx1`(col2(4), col1))ENGINE=INNODB;
INSERT INTO t1 VALUES (2, 'test'), (3, repeat('test1', 2000));
INSERT INTO t1(col1) VALUES(1);
--echo # Eligible - record length is shorter than prefix length
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT col1 FROM t1 FORCE INDEX (`idx1`) WHERE col2 is NULL;
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
--echo # Not eligible - record length longer than prefix index
let $base_count = query_get_value($show_count_statement, Value, 1);
let $base_opt = query_get_value($show_opt_statement, Value, 1);
SELECT col1 FROM t1 FORCE INDEX (`idx1`) WHERE col2 like 'test1%';
let $count = query_get_value($show_count_statement, Value, 1);
let $opt = query_get_value($show_opt_statement, Value, 1);
--disable_query_log
eval set @cluster_lookups = $count - $base_count;
eval set @cluster_lookups_avoided = $opt - $base_opt;
--enable_query_log
select @cluster_lookups;
select @cluster_lookups_avoided;
DROP TABLE t1;
--echo #
--echo # MDEV-20464 Division by 0 in row_search_with_covering_prefix()
--echo #
CREATE TABLE t1 (f1 INT, f2 INT AS (f1), f3 INT AS (f1), f4 INT AS (f1),
KEY (f1,f2,f3)) ENGINE=InnoDB;
INSERT INTO t1 (f1) VALUES (NULL),(0);
SELECT f1, MAX(f3), COUNT(f4) FROM t1 GROUP BY f1;
DROP TABLE t1;
--echo #
--echo # MDEV-23600 Division by 0 in row_search_with_covering_prefix()
--echo #
CREATE TABLE t(c POINT UNIQUE) ENGINE=InnoDB;
INSERT t SET c=POINT(1,1);
SELECT * FROM t WHERE c > (SELECT MAX(c) FROM t);
DROP TABLE t;
--echo #
--echo # MDEV-12486 Wrong results with innodb_prefix_index_cluster_optimization
--echo #
CREATE TABLE wp_blogs (
blog_id bigint(20) NOT NULL auto_increment,
site_id bigint(20) NOT NULL default '0',
domain varchar(200) NOT NULL default '',
path varchar(100) NOT NULL default '',
registered datetime NOT NULL default '0000-00-00 00:00:00',
last_updated datetime NOT NULL default '0000-00-00 00:00:00',
public tinyint(2) NOT NULL default '1',
archived tinyint(2) NOT NULL default '0',
mature tinyint(2) NOT NULL default '0',
spam tinyint(2) NOT NULL default '0',
deleted tinyint(2) NOT NULL default '0',
lang_id int(11) NOT NULL default '0',
PRIMARY KEY (blog_id),
KEY domain (domain(50),path(5)),
KEY lang_id (lang_id)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
INSERT INTO wp_blogs (domain, path) VALUES
('domain.no', '/fondsinvesteringer/'), ('domain.no', '/'),
('foo', 'bar'), ('bar', 'foo'), ('foo', 'foo'), ('bar', 'bar'),
('foo', 'foobar'), ('bar', 'foobar'), ('foobar', 'foobar');
SET GLOBAL innodb_prefix_index_cluster_optimization=off;
SELECT blog_id FROM wp_blogs WHERE domain IN ('domain.no')
AND path IN ( '/fondsinvesteringer/', '/' );
SET GLOBAL innodb_prefix_index_cluster_optimization=on;
SELECT blog_id FROM wp_blogs WHERE domain IN ('domain.no')
AND path IN ( '/fondsinvesteringer/', '/' );
DROP TABLE wp_blogs;
SET GLOBAL innodb_prefix_index_cluster_optimization = @save_opt;
SET GLOBAL innodb_stats_persistent = @save_innodb_stats_persistent;
|