Debian Codegraph @

mysql-test/suite/ndb/t/ndb_use_dropped_index_rebuild.test

raw
1 --source include/have_ndb.inc
2 -- source suite/ndb/include/backup_restore_setup.inc
3 --result_format 2
4
5 ## The MySQL Server supports opening tables with missing indexes.
6 ## This means that MySQL knows about an index which does
7 ## not exist in NDB but it still allows opening the table with
8 ## the index unavailable.
9 ##
10 ## This test makes sure that a table with missing index which
11 ## has been opened in MySQL detects when the index becomes available
12 ## in NDB again.
13 ##
14
15 # This test results in an error message in the server log:
16 # [ERROR] [MY-010211] [Server] Got error 126 when reading table './test/t1'
17 call mtr.add_suppression(".*Got error 126 when reading table '.*t1'");
18
19 CREATE TABLE t1 (
20 pk INT PRIMARY KEY,
21 a INT,
22 b VARCHAR(255),
23 c DECIMAL(10,2),
24 INDEX idx_a (a)
25 ) ENGINE=NDBCLUSTER;
26
27 INSERT INTO t1 VALUES
28 (1, 10, 'value1', 10.50),
29 (2, 20, 'value2', 20.25),
30 (3, 30, 'value3', 30.75);
31
32 ## Take backup in order to be able to restore the index
33 --source include/ndb_backup.inc
34
35 ## Read from table when index idx_a is available
36 ## thus opening the table and cache it
37 SELECT a FROM t1 WHERE a = 10;
38 EXPLAIN SELECT a FROM t1 WHERE a = 10;
39 ## Other queries work
40 SELECT pk FROM t1 ORDER BY pk LIMIT 1;
41 SELECT pk FROM t1 WHERE pk = 1;
42
43 ## Check index exist in NDB
44 if (`SELECT COUNT(*) != 1 FROM ndbinfo.index_columns WHERE index_name = 'idx_a'`)
45 {
46 SELECT * FROM ndbinfo.index_columns;
47 die Index is not in NDB;
48 }
49
50 ##########################################
51 ## Use ndb_drop_index to drop the index idx_a.
52 --exec $NDB_DROP_INDEX -d test t1 idx_a >> $NDB_TOOLS_OUTPUT
53
54 ## Check index does NOT exist in NDB
55 if (`SELECT COUNT(*) != 0 FROM ndbinfo.index_columns WHERE index_name = 'idx_a'`)
56 {
57 SELECT * FROM ndbinfo.index_columns;
58 die Index exist in NDB;
59 }
60
61 ## Select from the table again, expect error since NDB
62 ## detects that table version has changed
63 --error ER_TABLE_DEF_CHANGED
64 SELECT a FROM t1 WHERE a = 10;
65
66 ## Query using the index fails
67 --error ER_NOT_KEYFILE
68 SELECT a FROM t1 WHERE a = 10;
69
70 ## Other queries work
71 SELECT pk FROM t1 ORDER BY pk LIMIT 1;
72 SELECT pk FROM t1 WHERE pk = 1;
73
74 ###################################
75 ## Restore index from backup
76 let $cmd = $NDB_RESTORE;
77 let $cmd = $cmd -b $the_backup_id;
78 let $cmd = $cmd --nodeid 2;
79 let $cmd = $cmd --parallelism=1;
80 let $cmd = $cmd --rebuild-indexes;
81 let $cmd = $cmd $NDB_BACKUPS-$the_backup_id;
82 #echo cmd: $cmd;
83 --exec $cmd >> $NDB_TOOLS_OUTPUT
84 ####################################
85
86 ## Check that index 'idx_a' exist in NDB again
87 if (`SELECT COUNT(*) != 1 FROM ndbinfo.index_columns WHERE index_name = 'idx_a'`)
88 {
89 SELECT * FROM ndbinfo.index_columns;
90 die Index is not restored in NDB;
91 }
92
93 ## Query using the index works again
94 SELECT a FROM t1 WHERE a = 10;
95
96 ## Other queries work
97 SELECT pk FROM t1 ORDER BY pk LIMIT 1;
98 SELECT pk FROM t1 WHERE pk = 1;
99
100 ## Explain shows that MySQL still want to use idx_a
101 EXPLAIN SELECT a FROM t1 WHERE a = 10;
102
103 # Cleanup
104 DROP TABLE t1;
105
106 --source suite/ndb/include/backup_restore_cleanup.inc
107 --remove_file $NDB_TOOLS_OUTPUT