summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-01-03 17:20:58 +0100
committerSergei Golubchik <serg@mariadb.org>2022-01-26 18:43:06 +0100
commit58195449eebd98a0e1697d90469c4b0a1538d0b2 (patch)
tree1b376ee160c84fb2206b2e1f96cc37088fb9c145
parentaea076dc214ebf7d8c7928b36ce11198ebf861fd (diff)
downloadmariadb-git-58195449eebd98a0e1697d90469c4b0a1538d0b2.tar.gz
MDEV-27406 Index on a HEAP table retains DESC attribute despite being hash
just like in SHOW KEYS, suppress DESC in SHOW CREATE if not HA_READ_ORDER
-rw-r--r--mysql-test/suite/heap/heap_hash.result22
-rw-r--r--mysql-test/suite/heap/heap_hash.test20
-rw-r--r--sql/sql_show.cc3
3 files changed, 37 insertions, 8 deletions
diff --git a/mysql-test/suite/heap/heap_hash.result b/mysql-test/suite/heap/heap_hash.result
index 6bc9ff0d527..eb73b53dd2f 100644
--- a/mysql-test/suite/heap/heap_hash.result
+++ b/mysql-test/suite/heap/heap_hash.result
@@ -1,4 +1,3 @@
-drop table if exists t1,t2;
create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps" avg_row_length=100 min_rows=1 max_rows=100;
insert into t1 values(1,1),(2,2),(3,3),(4,4);
delete from t1 where a=1 or a=0;
@@ -467,4 +466,23 @@ SELECT * FROM t1 WHERE c1='bar2';
c1
bar2
DROP TABLE t1;
-End of 5.5 tests
+#
+# End of 5.5 tests
+#
+#
+# MDEV-27406 Index on a HEAP table retains DESC attribute despite being hash
+#
+create table t1 (a int, key(a desc)) engine=memory;
+show index from t1;
+Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
+t1 1 a 1 a NULL 0 NULL NULL YES HASH NO
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ KEY `a` (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+drop table t1;
+#
+# End of 10.8 tests
+#
diff --git a/mysql-test/suite/heap/heap_hash.test b/mysql-test/suite/heap/heap_hash.test
index 3a8979a2393..3d3855d8062 100644
--- a/mysql-test/suite/heap/heap_hash.test
+++ b/mysql-test/suite/heap/heap_hash.test
@@ -2,10 +2,6 @@
# Test of heap tables.
#
---disable_warnings
-drop table if exists t1,t2;
---enable_warnings
-
create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps" avg_row_length=100 min_rows=1 max_rows=100;
insert into t1 values(1,1),(2,2),(3,3),(4,4);
delete from t1 where a=1 or a=0;
@@ -346,4 +342,18 @@ explain SELECT * FROM t1 WHERE c1='bar2';
SELECT * FROM t1 WHERE c1='bar2';
DROP TABLE t1;
---echo End of 5.5 tests
+--echo #
+--echo # End of 5.5 tests
+--echo #
+
+--echo #
+--echo # MDEV-27406 Index on a HEAP table retains DESC attribute despite being hash
+--echo #
+create table t1 (a int, key(a desc)) engine=memory;
+show index from t1;
+show create table t1;
+drop table t1;
+
+--echo #
+--echo # End of 10.8 tests
+--echo #
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 877bfada417..47d94375290 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2369,7 +2369,8 @@ int show_create_table_ex(THD *thd, TABLE_LIST *table_list,
packet->append_parenthesized((long) key_part->length /
key_part->field->charset()->mbmaxlen);
}
- if (key_part->key_part_flag & HA_REVERSE_SORT)
+ if (table->file->index_flags(i, j, 0) & HA_READ_ORDER &&
+ key_part->key_part_flag & HA_REVERSE_SORT) /* same in SHOW KEYS */
packet->append(STRING_WITH_LEN(" DESC"));
}