diff options
author | Sergei Golubchik <serg@mariadb.org> | 2022-01-01 17:20:52 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2022-01-26 18:43:06 +0100 |
commit | b18697fd3eb9bc2d88c03869109bcebcdf55a9a1 (patch) | |
tree | a12e81450bd5f00c1e817db28d1d76e637ad5a72 | |
parent | f00236ac230ebc48cd30fb72166fc1106141c365 (diff) | |
download | mariadb-git-b18697fd3eb9bc2d88c03869109bcebcdf55a9a1.tar.gz |
MDEV-27398 DESC index causes wrong (empty) result on Federated tables
take descending indexes into account when generating a query
-rw-r--r-- | mysql-test/suite/federated/indexes.result | 33 | ||||
-rw-r--r-- | mysql-test/suite/federated/indexes.test | 22 | ||||
-rw-r--r-- | storage/federatedx/ha_federatedx.cc | 11 |
3 files changed, 61 insertions, 5 deletions
diff --git a/mysql-test/suite/federated/indexes.result b/mysql-test/suite/federated/indexes.result new file mode 100644 index 00000000000..d5ebbeeb6dc --- /dev/null +++ b/mysql-test/suite/federated/indexes.result @@ -0,0 +1,33 @@ +# +# MDEV-27398 DESC index causes wrong (empty) result on Federated tables +# +create table t (a int); +insert into t values (1),(5),(2),(3),(4); +create table tf (a int, key(a desc)) connection 'mysql://root@127.0.0.1:$MASTER_MYPORT/test/t' engine=Federated; +select * from tf; +a +1 +2 +3 +4 +5 +select * from tf where a > 2; +a +3 +4 +5 +select * from tf where a < 3; +a +1 +2 +select * from tf where a >= 3; +a +3 +4 +5 +select * from tf where a <= 3; +a +1 +2 +3 +drop table tf, t; diff --git a/mysql-test/suite/federated/indexes.test b/mysql-test/suite/federated/indexes.test new file mode 100644 index 00000000000..2ad2f823acf --- /dev/null +++ b/mysql-test/suite/federated/indexes.test @@ -0,0 +1,22 @@ +--source include/not_embedded.inc +--source suite/federated/have_federatedx.inc + +--echo # +--echo # MDEV-27398 DESC index causes wrong (empty) result on Federated tables +--echo # + +create table t (a int); +insert into t values (1),(5),(2),(3),(4); + +--evalp create table tf (a int, key(a desc)) connection 'mysql://root@127.0.0.1:$MASTER_MYPORT/test/t' engine=Federated +--sorted_result +select * from tf; +--sorted_result +select * from tf where a > 2; +--sorted_result +select * from tf where a < 3; +--sorted_result +select * from tf where a >= 3; +--sorted_result +select * from tf where a <= 3; +drop table tf, t; diff --git a/storage/federatedx/ha_federatedx.cc b/storage/federatedx/ha_federatedx.cc index e18a3cfd854..b99b16df5c3 100644 --- a/storage/federatedx/ha_federatedx.cc +++ b/storage/federatedx/ha_federatedx.cc @@ -1261,6 +1261,7 @@ bool ha_federatedx::create_where_from_key(String *to, uint store_length= key_part->store_length; uint part_length= MY_MIN(store_length, length); bool needs_quotes= field->str_needs_quotes(); + bool reverse= key_part->key_part_flag & HA_REVERSE_SORT; static const LEX_CSTRING lt={STRING_WITH_LEN(" < ") }; static const LEX_CSTRING gt={STRING_WITH_LEN(" > ") }; static const LEX_CSTRING le={STRING_WITH_LEN(" <= ") }; @@ -1338,12 +1339,12 @@ bool ha_federatedx::create_where_from_key(String *to, if (i > 0) /* end key */ { - if (tmp.append(le)) + if (tmp.append(reverse ? ge : le)) goto err; } else /* start key */ { - if (tmp.append(gt)) + if (tmp.append(reverse ? lt : gt)) goto err; } @@ -1358,7 +1359,7 @@ bool ha_federatedx::create_where_from_key(String *to, case HA_READ_KEY_OR_NEXT: DBUG_PRINT("info", ("federatedx HA_READ_KEY_OR_NEXT %d", i)); if (emit_key_part_name(&tmp, key_part) || - tmp.append(ge) || + tmp.append(reverse ? le : ge) || emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr, part_length)) goto err; @@ -1368,7 +1369,7 @@ bool ha_federatedx::create_where_from_key(String *to, if (store_length >= length) { if (emit_key_part_name(&tmp, key_part) || - tmp.append(lt) || + tmp.append(reverse ? gt : lt) || emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr, part_length)) goto err; @@ -1378,7 +1379,7 @@ bool ha_federatedx::create_where_from_key(String *to, case HA_READ_KEY_OR_PREV: DBUG_PRINT("info", ("federatedx HA_READ_KEY_OR_PREV %d", i)); if (emit_key_part_name(&tmp, key_part) || - tmp.append(le) || + tmp.append(reverse ? ge : le) || emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr, part_length)) goto err; |