summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-01-03 17:45:54 +0100
committerSergei Golubchik <serg@mariadb.org>2022-01-26 18:43:06 +0100
commitd7e7f48eb4c4913311e4d4de4d28e01dd422c3fd (patch)
tree5b8492c58099f9f90136f8ce49b074b292739dc2
parent58195449eebd98a0e1697d90469c4b0a1538d0b2 (diff)
downloadmariadb-git-d7e7f48eb4c4913311e4d4de4d28e01dd422c3fd.tar.gz
MDEV-27407 Different ASC/DESC index attributes on MERGE and underlying table can cause wrong results
detect if merge children are "differently defined" regarding ASC/DESC
-rw-r--r--mysql-test/main/merge.result11
-rw-r--r--mysql-test/main/merge.test13
-rw-r--r--storage/myisam/ha_myisam.cc3
3 files changed, 26 insertions, 1 deletions
diff --git a/mysql-test/main/merge.result b/mysql-test/main/merge.result
index ea1f48c54c8..348717b3950 100644
--- a/mysql-test/main/merge.result
+++ b/mysql-test/main/merge.result
@@ -3904,3 +3904,14 @@ set global default_storage_engine=@save_default_storage_engine;
#
# End of 10.0 tests
#
+#
+# MDEV-27407 Different ASC/DESC index attributes on MERGE and underlying table can cause wrong results
+#
+create table t (a int, key(a desc)) engine=myisam;
+create table tm (a int, key(a)) engine=merge union(t);
+select * from tm;
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
+drop table tm, t;
+#
+# End of 10.8 tests
+#
diff --git a/mysql-test/main/merge.test b/mysql-test/main/merge.test
index e19e223bab5..f9c68cf71f3 100644
--- a/mysql-test/main/merge.test
+++ b/mysql-test/main/merge.test
@@ -2862,3 +2862,16 @@ set global default_storage_engine=@save_default_storage_engine;
--echo #
--echo # End of 10.0 tests
--echo #
+
+--echo #
+--echo # MDEV-27407 Different ASC/DESC index attributes on MERGE and underlying table can cause wrong results
+--echo #
+create table t (a int, key(a desc)) engine=myisam;
+create table tm (a int, key(a)) engine=merge union(t);
+--error ER_WRONG_MRG_TABLE
+select * from tm;
+drop table tm, t;
+
+--echo #
+--echo # End of 10.8 tests
+--echo #
diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc
index 2a49971f6db..7fc42ac8aa4 100644
--- a/storage/myisam/ha_myisam.cc
+++ b/storage/myisam/ha_myisam.cc
@@ -554,7 +554,8 @@ int check_definition(MI_KEYDEF *t1_keyinfo, MI_COLUMNDEF *t1_recinfo,
t1_keysegs_j__type != t2_keysegs[j].type ||
t1_keysegs[j].null_bit != t2_keysegs[j].null_bit ||
t1_keysegs[j].length != t2_keysegs[j].length ||
- t1_keysegs[j].start != t2_keysegs[j].start)
+ t1_keysegs[j].start != t2_keysegs[j].start ||
+ (t1_keysegs[j].flag ^ t2_keysegs[j].flag) & HA_REVERSE_SORT)
{
DBUG_PRINT("error", ("Key segment %d (key %d) has different "
"definition", j, i));