Skip to content

Commit e925ddd

Browse files
committed
MDEV-27578 DESC attribute upon spatial index creation prevents ER_DUP_INDEX warning
strip DESC from SPATIAL indexes earlier. Before check_duplicate_key() not when creating the frm
1 parent dd63c6c commit e925ddd

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

mysql-test/main/alter_table_errors.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#
2+
# MDEV-16110 ALTER with ALGORITHM=INPLACE breaks temporary table with virtual columns
3+
#
14
create table t (a int, v int as (a)) engine=innodb;
25
alter table t change column a b tinyint, algorithm=inplace;
36
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Cannot change column type. Try ALGORITHM=COPY
@@ -28,8 +31,23 @@ t2 CREATE TEMPORARY TABLE `t2` (
2831
`v` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL
2932
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
3033
drop temporary table t1, t2;
34+
unlock tables;
35+
#
36+
# MDEV-18083 ASAN heap-use-after-free in Field::set_warning_truncated_wrong_value upon inserting into temporary table
37+
#
3138
create temporary table t1 (a int);
3239
alter table t1 add column f text;
3340
insert into t1 values ('x','foo');
3441
ERROR 22007: Incorrect integer value: 'x' for column `test`.`t1`.`a` at row 1
3542
drop temporary table t1;
43+
# End of 10.2 tests
44+
#
45+
# MDEV-27578 DESC attribute upon spatial index creation prevents ER_DUP_INDEX warning
46+
#
47+
create table t1 (c point not null);
48+
alter table t1 add spatial index b1(c desc);
49+
alter table t1 add spatial index b2(c desc);
50+
Warnings:
51+
Note 1831 Duplicate index `b2`. This is deprecated and will be disallowed in a future release
52+
drop table t1;
53+
# End of 10.11 tests

mysql-test/main/alter_table_errors.test

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
--source include/have_innodb.inc
22

3-
#
4-
# MDEV-16110 ALTER with ALGORITHM=INPLACE breaks temporary table with virtual columns
5-
#
3+
--echo #
4+
--echo # MDEV-16110 ALTER with ALGORITHM=INPLACE breaks temporary table with virtual columns
5+
--echo #
66
create table t (a int, v int as (a)) engine=innodb;
77
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
88
alter table t change column a b tinyint, algorithm=inplace;
@@ -20,12 +20,25 @@ lock table t2 write;
2020
alter table t2 change column a b int, algorithm=inplace;
2121
show create table t2;
2222
drop temporary table t1, t2;
23+
unlock tables;
2324

24-
#
25-
# MDEV-18083 ASAN heap-use-after-free in Field::set_warning_truncated_wrong_value upon inserting into temporary table
26-
#
25+
--echo #
26+
--echo # MDEV-18083 ASAN heap-use-after-free in Field::set_warning_truncated_wrong_value upon inserting into temporary table
27+
--echo #
2728
create temporary table t1 (a int);
2829
alter table t1 add column f text;
2930
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
3031
insert into t1 values ('x','foo');
3132
drop temporary table t1;
33+
34+
--echo # End of 10.2 tests
35+
36+
--echo #
37+
--echo # MDEV-27578 DESC attribute upon spatial index creation prevents ER_DUP_INDEX warning
38+
--echo #
39+
create table t1 (c point not null);
40+
alter table t1 add spatial index b1(c desc);
41+
alter table t1 add spatial index b2(c desc);
42+
drop table t1;
43+
44+
--echo # End of 10.11 tests

sql/sql_table.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,6 +3724,12 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info,
37243724
auto_increment_key= sql_field;
37253725
}
37263726

3727+
/* For SPATIAL, FULLTEXT and HASH indexes (anything other than B-tree),
3728+
ignore the ASC/DESC attribute of columns. */
3729+
if ((key_info->algorithm > HA_KEY_ALG_BTREE) ||
3730+
(key_info->flags & (HA_SPATIAL|HA_FULLTEXT)))
3731+
column->asc= true; // ignore DESC
3732+
37273733
key_part_info->fieldnr= field;
37283734
key_part_info->offset= (uint16) sql_field->offset;
37293735
key_part_info->key_type=sql_field->pack_flag;

sql/unireg.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,6 @@ static uint pack_keys(uchar *keybuff, uint key_count, KEY *keyinfo,
685685
key->flags, key->user_defined_key_parts,
686686
key->key_part));
687687

688-
/* For SPATIAL, FULLTEXT and HASH indexes (anything other than B-tree),
689-
ignore the ASC/DESC attribute of columns. */
690-
const uchar ha_reverse_sort=
691-
key->algorithm > HA_KEY_ALG_BTREE || key->flags & (HA_FULLTEXT|HA_SPATIAL)
692-
? 0 : HA_REVERSE_SORT;
693-
694688
for (key_part=key->key_part,key_part_end=key_part+key->user_defined_key_parts ;
695689
key_part != key_part_end ;
696690
key_part++)
@@ -703,14 +697,17 @@ static uint pack_keys(uchar *keybuff, uint key_count, KEY *keyinfo,
703697
int2store(pos,key_part->fieldnr+1+FIELD_NAME_USED);
704698
offset= (uint) (key_part->offset+data_offset+1);
705699
int2store(pos+2, offset);
706-
key_part->key_part_flag &= ha_reverse_sort;
700+
key_part->key_part_flag &= HA_REVERSE_SORT;
701+
/* DESC can be set only for BTREE indexes */
702+
DBUG_ASSERT(key_part->key_part_flag == 0 ||
703+
(key->algorithm <= HA_KEY_ALG_BTREE && !(key->flags & (HA_FULLTEXT|HA_SPATIAL))));
707704
pos[4]= (uchar)(key_part->key_part_flag);
708705
int2store(pos+5,key_part->key_type);
709706
int2store(pos+7,key_part->length);
710707
pos+=9;
711708
}
712709
}
713-
/* Save keynames */
710+
/* Save keynames */
714711
keyname_pos=pos;
715712
*pos++=(uchar) NAMES_SEP_CHAR;
716713
for (key=keyinfo ; key != end ; key++)

0 commit comments

Comments
 (0)