@@ -526,5 +526,92 @@ select * from information_schema.tables;
526
526
--echo #cleanup
527
527
drop table t1;
528
528
529
+ # Bug#29611297 NDB: INDEX STAT HAS ISSUES WITH ONLINE ALTER TABLE TO/FROM
530
+ # READBACKUP. Online ALTER TABLE statements that resulted in the index
531
+ # version being bumped up left behind orphaned index stats corresponding
532
+ # to the previous index version.
533
+ CREATE TABLE t1 (
534
+ a INT PRIMARY KEY,
535
+ b INT,
536
+ c INT,
537
+ UNIQUE(c)
538
+ ) ENGINE NDB PARTITION BY KEY(a);
539
+
540
+ --echo Insert 100 rows
541
+ --disable_query_log
542
+ let $i = 100;
543
+ while ($i)
544
+ {
545
+ dec $i;
546
+ eval INSERT INTO t1 VALUES($i, $i % 100, $i);
547
+ }
548
+ --enable_query_log
549
+
550
+ # Trigger index stats creation which creates 1 metadata entry
551
+ # in the head table (exposed to users via the ndbinfo.index_stats
552
+ # table) and n sample table entries per index
553
+ ANALYZE TABLE t1;
554
+ # Uncomment below to check details
555
+ #SELECT * FROM mysql.ndb_index_stat_head;
556
+ SELECT CASE COUNT(*) > 0
557
+ WHEN 1 THEN 'YES' ELSE 'NO' END
558
+ AS stats_metadata_present FROM mysql.ndb_index_stat_head;
559
+ # Record the number of samples created. This seems to vary across platforms
560
+ SELECT COUNT(*) INTO @samples_pre_alter FROM mysql.ndb_index_stat_sample;
561
+
562
+ # Record the value of 'rows' in the EXPLAIN output for a later check
563
+ --let $query=SELECT * FROM t1 WHERE c > 50
564
+ --let $explain_rows_pre_alter=query_get_value(EXPLAIN $query, rows, 1)
565
+
566
+ # Online ALTER that creates indexes with new versions
567
+ ALTER TABLE t1 COMMENT="NDB_TABLE=READ_BACKUP=1";
568
+
569
+ # Trigger index stats creation. The ANALYZE below will clean up
570
+ # samples corresponding to the old index version in the
571
+ # ndb_index_stat_sample table and create new samples for the
572
+ # new index version.
573
+ ANALYZE TABLE t1;
574
+ # Uncomment below to check details
575
+ #SELECT * FROM mysql.ndb_index_stat_head;
576
+ # Check for duplicates
577
+ SELECT COUNT(index_id)
578
+ FROM mysql.ndb_index_stat_head
579
+ GROUP BY index_id
580
+ HAVING COUNT(index_id) > 1;
581
+ # Should still be 21/26 samples. Was 42/52 (21/26 created with
582
+ # <index_id, old index_version> as the key and 21/26 more
583
+ # with <index_id, new index version>) before the bug fix
584
+ if (`SELECT COUNT(*) <> @samples_pre_alter FROM mysql.ndb_index_stat_sample`)
585
+ {
586
+ --die "Extra samples found"
587
+ }
588
+ --echo Sample count is the same as before the ALTER
589
+
590
+ # Execute the same EXPLAIN as earlier. The expectation is that the 'rows'
591
+ # output is the same from before the ALTER
592
+ --let $explain_rows_post_alter=query_get_value(EXPLAIN $query, rows, 1)
593
+ #--expr $explain_rows_change = $explain_rows_post_alter - $explain_rows_pre_alter
594
+ if ($explain_rows_post_alter == $explain_rows_pre_alter)
595
+ {
596
+ --echo EXPLAIN is the same both pre- and post-ALTER
597
+ }
598
+ if ($explain_rows_post_alter != $explain_rows_pre_alter)
599
+ {
600
+ --die EXPLAIN has changed. Pre-ALTER: $explain_rows_pre_alter and post-ALTER: $explain_rows_post_alter
601
+ }
602
+
603
+ DROP TABLE t1;
604
+
605
+ # We expect 0 entries in the sample table but "stale" metadata
606
+ # info is still present in the head table
607
+ # Uncomment below to check details
608
+ #SELECT * FROM mysql.ndb_index_stat_head;
609
+ SELECT CASE COUNT(*) > 0
610
+ WHEN 1 THEN 'YES' ELSE 'NO' END
611
+ AS stats_metadata_present FROM mysql.ndb_index_stat_head;
612
+ SELECT CASE COUNT(*) = 0
613
+ WHEN 1 THEN 'YES' ELSE 'NO' END
614
+ AS stats_samples_cleaned_up FROM mysql.ndb_index_stat_sample;
615
+
529
616
set @is_enable = @is_enable_default;
530
617
source ndb_index_stat_enable.inc;
0 commit comments