Skip to content

Commit

Permalink
[bugfix] Issue: #56 invisible index is not respected by slave under …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
AliSQL authored and AliSQL committed Jan 23, 2018
1 parent e337866 commit 229996d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
@@ -0,0 +1,25 @@
include/master-slave.inc
Warnings:
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
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.
[connection master]
create table t1(id int auto_increment, name varchar(30), key idx_id(id)) engine=innodb;
insert into t1(name) values('MySQL');
insert into t1(name) values('InnoDB');
insert into t1(name) select a.name from t1 a, t1 b;
insert into t1(name) select a.name from t1 a, t1 b;
insert into t1(name) select a.name from t1 a, t1 b;
delete from t1 where id > 1000 limit 100;
select variable_value = 100 from information_schema.global_status where variable_name='Innodb_rows_read';
variable_value = 100
1
alter table t1 alter index idx_id invisible;
delete from t1 where id > 1000 limit 100;
select table_name, index_name, is_visible from information_schema.statistics where index_name = 'idx_id';
table_name index_name is_visible
t1 idx_id NO
select variable_value/100 > 100 from information_schema.global_status where variable_name='Innodb_rows_read';
variable_value/100 > 100
1
drop table t1;
include/rpl_end.inc
@@ -0,0 +1 @@
--log-bin --binlog-format=row
@@ -0,0 +1 @@
--log-bin --binlog-format=row
@@ -0,0 +1,33 @@
--source include/master-slave.inc
--source include/have_binlog_format_row.inc

create table t1(id int auto_increment, name varchar(30), key idx_id(id)) engine=innodb;
insert into t1(name) values('MySQL');
insert into t1(name) values('InnoDB');
insert into t1(name) select a.name from t1 a, t1 b;
insert into t1(name) select a.name from t1 a, t1 b;
insert into t1(name) select a.name from t1 a, t1 b;

delete from t1 where id > 1000 limit 100;
sync_slave_with_master;

## on slave, Innodb_rows_read is equal with Innodb_rows_deleted(100) because idx_id is used
select variable_value = 100 from information_schema.global_status where variable_name='Innodb_rows_read';

## change idx_id index on slave invisible
alter table t1 alter index idx_id invisible;

connection master;
delete from t1 where id > 1000 limit 100;
sync_slave_with_master;

## make sure invisible attribute is respected
## Innodb_rows_read is much bigger than Innodb_rows_deleted(100) because idx_id can not be used
select table_name, index_name, is_visible from information_schema.statistics where index_name = 'idx_id';
select variable_value/100 > 100 from information_schema.global_status where variable_name='Innodb_rows_read';

## clean up
connection master;
drop table t1;
sync_slave_with_master;
--source include/rpl_end.inc
4 changes: 2 additions & 2 deletions sql/log_event.cc
Expand Up @@ -9927,12 +9927,12 @@ search_key_in_table(TABLE *table, MY_BITMAP *bi_cols, uint key_type)
key++,keyinfo++)
{
/*
- Skip innactive keys
- Skip innactive keys or invisible indexes
- Skip unique keys without nullable parts
- Skip indices that do not support ha_index_next() e.g. full-text
- Skip primary keys
*/
if (!(table->s->keys_in_use.is_set(key)) ||
if (!(table->s->usable_indexes().is_set(key)) ||
((keyinfo->flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME) ||
!(table->file->index_flags(key, 0, true) & HA_READ_NEXT) ||
(key == table->s->primary_key))
Expand Down

0 comments on commit 229996d

Please sign in to comment.