Skip to content

Commit 0c58c93

Browse files
Bug #21103101 SORTING SKIPPED WHEN DROPPING THE
SINGLE COLUMN PRIMARY KEY Description: - Don't skip sorting during rebuilding of the table when single column primary key is dropped. Reviewed-by: Marko Mäkelä <[email protected]> Approved via IM.
1 parent e17a193 commit 0c58c93

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

mysql-test/suite/innodb/r/innodb-index.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,3 +1582,18 @@ a b
15821582
0 khdHps6UxW8Lwaoxa604oK6zkb
15831583
1 khdHps6UtW8L
15841584
drop table t1;
1585+
#
1586+
# Bug #21103101 SORTING SKIPPED WHEN DROPPING THE SINGLE
1587+
# COLUMN PRIMARY KEY
1588+
#
1589+
create table t1(f1 int not null, f2 int not null,
1590+
primary key (f1), unique key(f1, f2))engine=innodb;
1591+
insert into t1 values(1,3), (2,2);
1592+
alter table t1 drop column f1;
1593+
drop table t1;
1594+
create table t1(f1 int not null, f2 int not null,
1595+
primary key (f1), unique key(f1, f2))engine=innodb;
1596+
insert into t1 values(1,3), (2,2);
1597+
alter table t1 drop primary key, lock=none;
1598+
ERROR 0A000: LOCK=NONE is not supported. Reason: Dropping a primary key is not allowed without also adding a new primary key. Try LOCK=SHARED.
1599+
drop table t1;

mysql-test/suite/innodb/t/innodb-index.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,23 @@ alter table t1 drop primary key, add primary key (b(8),a);
852852
select * from t1;
853853
drop table t1;
854854

855+
856+
--echo #
857+
--echo # Bug #21103101 SORTING SKIPPED WHEN DROPPING THE SINGLE
858+
--echo # COLUMN PRIMARY KEY
859+
--echo #
860+
861+
# Drop primary key column.
862+
create table t1(f1 int not null, f2 int not null,
863+
primary key (f1), unique key(f1, f2))engine=innodb;
864+
insert into t1 values(1,3), (2,2);
865+
alter table t1 drop column f1;
866+
drop table t1;
867+
868+
# Drop Primary key when lock is none.
869+
create table t1(f1 int not null, f2 int not null,
870+
primary key (f1), unique key(f1, f2))engine=innodb;
871+
insert into t1 values(1,3), (2,2);
872+
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
873+
alter table t1 drop primary key, lock=none;
874+
drop table t1;

storage/innobase/handler/handler0alter.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,13 @@ innobase_pk_order_preserved(
27492749
old_field++;
27502750
new_field++;
27512751
} else if (old_col_no == ULINT_UNDEFINED) {
2752+
2753+
if (old_n_fields == 1) {
2754+
/* Dropping single column primary key
2755+
requires sorting. */
2756+
return(false);
2757+
}
2758+
27522759
pk_col_dropped = true;
27532760
old_field++;
27542761
} else {

0 commit comments

Comments
 (0)