Skip to content

Commit 229996d

Browse files
AliSQLAliSQL
authored andcommitted
[bugfix] Issue: #56 invisible index is not respected by slave under row format
Description ============ bug#88847, this issue is related to invisible indexes feature which we ported from 8.0 upstream. Invisible index is not considered by slave SQL row applier when searching index to use, and choosed anyway as long as the index is fit for update. Solution: ============ Make slave SQL applier thread respecting invisible indexes and don't choose them when searching index to use.
1 parent e337866 commit 229996d

5 files changed

Lines changed: 62 additions & 2 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
create table t1(id int auto_increment, name varchar(30), key idx_id(id)) engine=innodb;
7+
insert into t1(name) values('MySQL');
8+
insert into t1(name) values('InnoDB');
9+
insert into t1(name) select a.name from t1 a, t1 b;
10+
insert into t1(name) select a.name from t1 a, t1 b;
11+
insert into t1(name) select a.name from t1 a, t1 b;
12+
delete from t1 where id > 1000 limit 100;
13+
select variable_value = 100 from information_schema.global_status where variable_name='Innodb_rows_read';
14+
variable_value = 100
15+
1
16+
alter table t1 alter index idx_id invisible;
17+
delete from t1 where id > 1000 limit 100;
18+
select table_name, index_name, is_visible from information_schema.statistics where index_name = 'idx_id';
19+
table_name index_name is_visible
20+
t1 idx_id NO
21+
select variable_value/100 > 100 from information_schema.global_status where variable_name='Innodb_rows_read';
22+
variable_value/100 > 100
23+
1
24+
drop table t1;
25+
include/rpl_end.inc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--log-bin --binlog-format=row
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--log-bin --binlog-format=row
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--source include/master-slave.inc
2+
--source include/have_binlog_format_row.inc
3+
4+
create table t1(id int auto_increment, name varchar(30), key idx_id(id)) engine=innodb;
5+
insert into t1(name) values('MySQL');
6+
insert into t1(name) values('InnoDB');
7+
insert into t1(name) select a.name from t1 a, t1 b;
8+
insert into t1(name) select a.name from t1 a, t1 b;
9+
insert into t1(name) select a.name from t1 a, t1 b;
10+
11+
delete from t1 where id > 1000 limit 100;
12+
sync_slave_with_master;
13+
14+
## on slave, Innodb_rows_read is equal with Innodb_rows_deleted(100) because idx_id is used
15+
select variable_value = 100 from information_schema.global_status where variable_name='Innodb_rows_read';
16+
17+
## change idx_id index on slave invisible
18+
alter table t1 alter index idx_id invisible;
19+
20+
connection master;
21+
delete from t1 where id > 1000 limit 100;
22+
sync_slave_with_master;
23+
24+
## make sure invisible attribute is respected
25+
## Innodb_rows_read is much bigger than Innodb_rows_deleted(100) because idx_id can not be used
26+
select table_name, index_name, is_visible from information_schema.statistics where index_name = 'idx_id';
27+
select variable_value/100 > 100 from information_schema.global_status where variable_name='Innodb_rows_read';
28+
29+
## clean up
30+
connection master;
31+
drop table t1;
32+
sync_slave_with_master;
33+
--source include/rpl_end.inc

sql/log_event.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9927,12 +9927,12 @@ search_key_in_table(TABLE *table, MY_BITMAP *bi_cols, uint key_type)
99279927
key++,keyinfo++)
99289928
{
99299929
/*
9930-
- Skip innactive keys
9930+
- Skip innactive keys or invisible indexes
99319931
- Skip unique keys without nullable parts
99329932
- Skip indices that do not support ha_index_next() e.g. full-text
99339933
- Skip primary keys
99349934
*/
9935-
if (!(table->s->keys_in_use.is_set(key)) ||
9935+
if (!(table->s->usable_indexes().is_set(key)) ||
99369936
((keyinfo->flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME) ||
99379937
!(table->file->index_flags(key, 0, true) & HA_READ_NEXT) ||
99389938
(key == table->s->primary_key))

0 commit comments

Comments
 (0)