Skip to content

Commit 9d1a800

Browse files
AliSQLAliSQL
authored andcommitted
[perf] #57 Preferred to chose index with auto_increment column when slave apply binlog
Description ----------- In row binlog format, slave chose index when apply binlog use such order: 1) primary key 2) unique key without null columns 3) normal index or unique key with null columns Actually, in situation 3 we should chose index with auto_increment column first, after this patch, the new order is 1) primary key 2) unique key without null columns 3) normal index with auto_increment columns 4) normal index without auto_increment columns or unique key with null columns
1 parent 229996d commit 9d1a800

5 files changed

Lines changed: 67 additions & 0 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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(c1 int auto_increment, c2 int, c3 int, key(c1,c2), key(c2)) engine=innodb;
7+
insert into t1 values(1,1,1);
8+
insert into t1 values(2,2,2);
9+
update t1 set c3=10;
10+
create table t2(c1 int, c2 int auto_increment, c3 int, key(c1), key(c2)) engine=innodb;
11+
insert into t2 values(1,1,1);
12+
insert into t2 values(2,2,2);
13+
update t2 set c3=10;
14+
select * from t1;
15+
c1 c2 c3
16+
1 1 10
17+
2 2 10
18+
select * from t2;
19+
c1 c2 c3
20+
1 1 10
21+
2 2 10
22+
drop table t1;
23+
drop table t2;
24+
include/rpl_end.inc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--binlog-format=row
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--binlog-format=row
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--source include/have_log_bin.inc
2+
--source include/master-slave.inc
3+
4+
connection master;
5+
create table t1(c1 int auto_increment, c2 int, c3 int, key(c1,c2), key(c2)) engine=innodb;
6+
insert into t1 values(1,1,1);
7+
insert into t1 values(2,2,2);
8+
9+
update t1 set c3=10;
10+
11+
create table t2(c1 int, c2 int auto_increment, c3 int, key(c1), key(c2)) engine=innodb;
12+
insert into t2 values(1,1,1);
13+
insert into t2 values(2,2,2);
14+
15+
update t2 set c3=10;
16+
17+
sync_slave_with_master;
18+
select * from t1;
19+
select * from t2;
20+
21+
connection master;
22+
drop table t1;
23+
drop table t2;
24+
25+
sync_slave_with_master;
26+
27+
--source include/rpl_end.inc

sql/log_event.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9922,6 +9922,20 @@ search_key_in_table(TABLE *table, MY_BITMAP *bi_cols, uint key_type)
99229922
if (key_type & MULTIPLE_KEY_FLAG && table->s->keys)
99239923
{
99249924
DBUG_PRINT("debug", ("Searching for K."));
9925+
9926+
/* auot_increment index has higher priority over other secondary indexes */
9927+
if (table->found_next_number_field)
9928+
{
9929+
keyinfo= table->key_info + table->s->next_number_index;
9930+
9931+
res= are_all_columns_signaled_for_key(keyinfo, bi_cols) ?
9932+
table->s->next_number_index : MAX_KEY;
9933+
9934+
if (res < MAX_KEY &&
9935+
table->s->usable_indexes().is_set(res))
9936+
DBUG_RETURN(res);
9937+
}
9938+
99259939
for (key=0,keyinfo= table->key_info ;
99269940
(key < table->s->keys) && (res == MAX_KEY);
99279941
key++,keyinfo++)

0 commit comments

Comments
 (0)