Loading innobase/row/row0sel.c +72 −62 Original line number Diff line number Diff line Loading @@ -642,16 +642,17 @@ row_sel_get_clust_rec( we lock only the record, i.e. next-key locking is not used. */ if ( srv_locks_unsafe_for_binlog ) { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index,node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index, node->row_lock_mode, LOCK_ORDINARY, thr); if (srv_locks_unsafe_for_binlog) { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index, node->row_lock_mode, LOCK_ORDINARY, thr); } if (err != DB_SUCCESS) { Loading Loading @@ -1210,16 +1211,18 @@ row_sel( not used. */ if ( srv_locks_unsafe_for_binlog ) { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_ORDINARY, thr); if (srv_locks_unsafe_for_binlog) { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_ORDINARY, thr); } if (err != DB_SUCCESS) { /* Note that in this case we will store in pcur the PREDECESSOR of the record we are waiting Loading Loading @@ -1250,13 +1253,10 @@ row_sel( not used. */ if ( srv_locks_unsafe_for_binlog ) { if (srv_locks_unsafe_for_binlog) { err = sel_set_rec_lock(rec, index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { } else { err = sel_set_rec_lock(rec, index, node->row_lock_mode, LOCK_ORDINARY, thr); } Loading Loading @@ -3209,8 +3209,7 @@ row_search_for_mysql( we do not lock gaps. Supremum record is really a gap and therefore we do not set locks there. */ if ( srv_locks_unsafe_for_binlog == FALSE ) { if (srv_locks_unsafe_for_binlog == FALSE) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_ORDINARY, thr); Loading Loading @@ -3312,11 +3311,18 @@ row_search_for_mysql( if (prebuilt->select_lock_type != LOCK_NONE && set_also_gap_locks) { /* Try to place a lock on the index record */ /* Try to place a gap lock on the index record only if innodb_locks_unsafe_for_binlog option is not set */ if (srv_locks_unsafe_for_binlog == FALSE) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_GAP, thr); } if (err != DB_SUCCESS) { goto lock_wait_or_error; Loading @@ -3338,11 +3344,18 @@ row_search_for_mysql( if (prebuilt->select_lock_type != LOCK_NONE && set_also_gap_locks) { /* Try to place a lock on the index record */ /* Try to place a gap lock on the index record only if innodb_locks_unsafe_for_binlog option is not set */ if (srv_locks_unsafe_for_binlog == FALSE) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_GAP, thr); } if (err != DB_SUCCESS) { goto lock_wait_or_error; Loading Loading @@ -3378,16 +3391,13 @@ row_search_for_mysql( } else { /* If innodb_locks_unsafe_for_binlog option is used, we lock only the record, i.e. next-key locking is not used. */ if ( srv_locks_unsafe_for_binlog ) { not used. */ if (srv_locks_unsafe_for_binlog) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_REC_NOT_GAP, thr); } else { } else { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_ORDINARY, thr); Loading mysql-test/r/myisam.result +1 −0 Original line number Diff line number Diff line Loading @@ -529,6 +529,7 @@ show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 1 a 1 a A NULL NULL NULL YES BTREE disabled create table t2 (a int); set @@rand_seed1=31415926,@@rand_seed2=2718281828; insert t1 select * from t2; show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Loading mysql-test/r/ndb_index_unique.result +52 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,51 @@ a b c 7 8 3 8 2 3 drop table t1; CREATE TABLE t1 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned, c int unsigned, UNIQUE bc(b,c) ) engine = ndb; insert into t1 values(1,1,1),(2,NULL,2),(3,NULL,NULL),(4,4,NULL); select * from t1 use index (bc) where b IS NULL order by a; a b c 2 NULL 2 3 NULL NULL select * from t1 use index (bc)order by a; a b c 1 1 1 2 NULL 2 3 NULL NULL 4 4 NULL select * from t1 use index (bc) order by a; a b c 1 1 1 2 NULL 2 3 NULL NULL 4 4 NULL select * from t1 use index (PRIMARY) where b IS NULL order by a; a b c 2 NULL 2 3 NULL NULL select * from t1 use index (bc) where b IS NULL order by a; a b c 2 NULL 2 3 NULL NULL select * from t1 use index (bc) where b IS NULL and c IS NULL order by a; a b c select * from t1 use index (bc) where b IS NULL and c = 2 order by a; a b c select * from t1 use index (bc) where b < 4 order by a; a b c 1 1 1 select * from t1 use index (bc) where b IS NOT NULL order by a; a b c 1 1 1 4 4 NULL insert into t1 values(5,1,1); ERROR 23000: Duplicate entry '5' for key 1 drop table t1; CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, Loading Loading @@ -87,6 +132,13 @@ a b c 7 8 3 8 2 3 drop table t2; CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, c int unsigned, UNIQUE USING HASH (b, c) ) engine=ndbcluster; ERROR 42000: Column 'c' is used with UNIQUE or INDEX but is not defined as NOT NULL CREATE TABLE t3 ( a int unsigned NOT NULL, b int unsigned not null, Loading mysql-test/r/subselect.result +15 −0 Original line number Diff line number Diff line Loading @@ -1990,3 +1990,18 @@ ac 700 NULL drop tables t1,t2; create table t1 (a int not null, b int not null, c int, primary key (a,b)); insert into t1 values (1,1,1), (2,2,2), (3,3,3); set @b:= 0; explain select sum(a) from t1 where b > @b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 8 NULL 3 Using where; Using index set @a:= (select sum(a) from t1 where b > @b); explain select a from t1 where c=2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where do @a:= (select sum(a) from t1 where b > @b); explain select a from t1 where c=2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where drop table t1; mysql-test/t/myisam.test +2 −1 Original line number Diff line number Diff line Loading @@ -498,11 +498,12 @@ alter table t1 disable keys; show keys from t1; create table t2 (a int); let $i=1000; set @@rand_seed1=31415926,@@rand_seed2=2718281828; --disable_query_log while ($i) { dec $i; eval insert t2 values (rand()*100000); insert t2 values (rand()*100000); } --enable_query_log insert t1 select * from t2; Loading Loading
innobase/row/row0sel.c +72 −62 Original line number Diff line number Diff line Loading @@ -642,16 +642,17 @@ row_sel_get_clust_rec( we lock only the record, i.e. next-key locking is not used. */ if ( srv_locks_unsafe_for_binlog ) { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index,node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index, node->row_lock_mode, LOCK_ORDINARY, thr); if (srv_locks_unsafe_for_binlog) { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = lock_clust_rec_read_check_and_lock(0, clust_rec, index, node->row_lock_mode, LOCK_ORDINARY, thr); } if (err != DB_SUCCESS) { Loading Loading @@ -1210,16 +1211,18 @@ row_sel( not used. */ if ( srv_locks_unsafe_for_binlog ) { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_ORDINARY, thr); if (srv_locks_unsafe_for_binlog) { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { err = sel_set_rec_lock(page_rec_get_next(rec), index, node->row_lock_mode, LOCK_ORDINARY, thr); } if (err != DB_SUCCESS) { /* Note that in this case we will store in pcur the PREDECESSOR of the record we are waiting Loading Loading @@ -1250,13 +1253,10 @@ row_sel( not used. */ if ( srv_locks_unsafe_for_binlog ) { if (srv_locks_unsafe_for_binlog) { err = sel_set_rec_lock(rec, index, node->row_lock_mode, LOCK_REC_NOT_GAP, thr); } else { } else { err = sel_set_rec_lock(rec, index, node->row_lock_mode, LOCK_ORDINARY, thr); } Loading Loading @@ -3209,8 +3209,7 @@ row_search_for_mysql( we do not lock gaps. Supremum record is really a gap and therefore we do not set locks there. */ if ( srv_locks_unsafe_for_binlog == FALSE ) { if (srv_locks_unsafe_for_binlog == FALSE) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_ORDINARY, thr); Loading Loading @@ -3312,11 +3311,18 @@ row_search_for_mysql( if (prebuilt->select_lock_type != LOCK_NONE && set_also_gap_locks) { /* Try to place a lock on the index record */ /* Try to place a gap lock on the index record only if innodb_locks_unsafe_for_binlog option is not set */ if (srv_locks_unsafe_for_binlog == FALSE) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_GAP, thr); } if (err != DB_SUCCESS) { goto lock_wait_or_error; Loading @@ -3338,11 +3344,18 @@ row_search_for_mysql( if (prebuilt->select_lock_type != LOCK_NONE && set_also_gap_locks) { /* Try to place a lock on the index record */ /* Try to place a gap lock on the index record only if innodb_locks_unsafe_for_binlog option is not set */ if (srv_locks_unsafe_for_binlog == FALSE) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_GAP, thr); } if (err != DB_SUCCESS) { goto lock_wait_or_error; Loading Loading @@ -3378,16 +3391,13 @@ row_search_for_mysql( } else { /* If innodb_locks_unsafe_for_binlog option is used, we lock only the record, i.e. next-key locking is not used. */ if ( srv_locks_unsafe_for_binlog ) { not used. */ if (srv_locks_unsafe_for_binlog) { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_REC_NOT_GAP, thr); } else { } else { err = sel_set_rec_lock(rec, index, prebuilt->select_lock_type, LOCK_ORDINARY, thr); Loading
mysql-test/r/myisam.result +1 −0 Original line number Diff line number Diff line Loading @@ -529,6 +529,7 @@ show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment t1 1 a 1 a A NULL NULL NULL YES BTREE disabled create table t2 (a int); set @@rand_seed1=31415926,@@rand_seed2=2718281828; insert t1 select * from t2; show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Loading
mysql-test/r/ndb_index_unique.result +52 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,51 @@ a b c 7 8 3 8 2 3 drop table t1; CREATE TABLE t1 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned, c int unsigned, UNIQUE bc(b,c) ) engine = ndb; insert into t1 values(1,1,1),(2,NULL,2),(3,NULL,NULL),(4,4,NULL); select * from t1 use index (bc) where b IS NULL order by a; a b c 2 NULL 2 3 NULL NULL select * from t1 use index (bc)order by a; a b c 1 1 1 2 NULL 2 3 NULL NULL 4 4 NULL select * from t1 use index (bc) order by a; a b c 1 1 1 2 NULL 2 3 NULL NULL 4 4 NULL select * from t1 use index (PRIMARY) where b IS NULL order by a; a b c 2 NULL 2 3 NULL NULL select * from t1 use index (bc) where b IS NULL order by a; a b c 2 NULL 2 3 NULL NULL select * from t1 use index (bc) where b IS NULL and c IS NULL order by a; a b c select * from t1 use index (bc) where b IS NULL and c = 2 order by a; a b c select * from t1 use index (bc) where b < 4 order by a; a b c 1 1 1 select * from t1 use index (bc) where b IS NOT NULL order by a; a b c 1 1 1 4 4 NULL insert into t1 values(5,1,1); ERROR 23000: Duplicate entry '5' for key 1 drop table t1; CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, Loading Loading @@ -87,6 +132,13 @@ a b c 7 8 3 8 2 3 drop table t2; CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, b int unsigned not null, c int unsigned, UNIQUE USING HASH (b, c) ) engine=ndbcluster; ERROR 42000: Column 'c' is used with UNIQUE or INDEX but is not defined as NOT NULL CREATE TABLE t3 ( a int unsigned NOT NULL, b int unsigned not null, Loading
mysql-test/r/subselect.result +15 −0 Original line number Diff line number Diff line Loading @@ -1990,3 +1990,18 @@ ac 700 NULL drop tables t1,t2; create table t1 (a int not null, b int not null, c int, primary key (a,b)); insert into t1 values (1,1,1), (2,2,2), (3,3,3); set @b:= 0; explain select sum(a) from t1 where b > @b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 8 NULL 3 Using where; Using index set @a:= (select sum(a) from t1 where b > @b); explain select a from t1 where c=2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where do @a:= (select sum(a) from t1 where b > @b); explain select a from t1 where c=2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where drop table t1;
mysql-test/t/myisam.test +2 −1 Original line number Diff line number Diff line Loading @@ -498,11 +498,12 @@ alter table t1 disable keys; show keys from t1; create table t2 (a int); let $i=1000; set @@rand_seed1=31415926,@@rand_seed2=2718281828; --disable_query_log while ($i) { dec $i; eval insert t2 values (rand()*100000); insert t2 values (rand()*100000); } --enable_query_log insert t1 select * from t2; Loading