Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions mysql-test/main/order_by.result
Original file line number Diff line number Diff line change
Expand Up @@ -4849,4 +4849,36 @@ ERROR 42S22: Unknown column '-5' in 'ORDER BY'
SELECT 1 FROM (select 1) dt order BY 50;
ERROR 42S22: Unknown column '50' in 'ORDER BY'
# End of 10.11 tests
#
# MDEV-38649: Wrong result (missing rows) upon condition pushdown on table with DESC key
#
CREATE TABLE t1 (a INT, b INT not null, KEY(b));
INSERT INTO t1 VALUES (2,8),(9,1),(4,6);
SELECT a, b FROM t1 WHERE b != 10 and b < 30 ORDER BY b DESC;
a b
2 8
4 6
9 1
SELECT a, b FROM t1 use index() WHERE b != 10 and b < 30 ORDER BY b DESC;
a b
2 8
4 6
9 1
DROP TABLE t1;
#
# End of 12.3 tests
#
#
# MDEV-38921: Incorrect ORDER BY Result
#
CREATE TABLE t2 (a INT, b INT not null, KEY(b));
INSERT INTO t2 VALUES (2,8),(9,1),(4,6),(11,13),(15,17);
SELECT a, b FROM t2 WHERE b != 10 and b < 30 ORDER BY b DESC;
a b
15 17
11 13
2 8
4 6
9 1
DROP TABLE t2;
ALTER DATABASE test CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;
21 changes: 21 additions & 0 deletions mysql-test/main/order_by.test
Original file line number Diff line number Diff line change
Expand Up @@ -2831,4 +2831,25 @@ SELECT 1 FROM (select 1) dt order BY 50;

--echo # End of 10.11 tests

--echo #
--echo # MDEV-38649: Wrong result (missing rows) upon condition pushdown on table with DESC key
--echo #
CREATE TABLE t1 (a INT, b INT not null, KEY(b));
INSERT INTO t1 VALUES (2,8),(9,1),(4,6);
SELECT a, b FROM t1 WHERE b != 10 and b < 30 ORDER BY b DESC;
SELECT a, b FROM t1 use index() WHERE b != 10 and b < 30 ORDER BY b DESC;
DROP TABLE t1;

--echo #
--echo # End of 12.3 tests
--echo #

--echo #
--echo # MDEV-38921: Incorrect ORDER BY Result
--echo #
CREATE TABLE t2 (a INT, b INT not null, KEY(b));
INSERT INTO t2 VALUES (2,8),(9,1),(4,6),(11,13),(15,17);
SELECT a, b FROM t2 WHERE b != 10 and b < 30 ORDER BY b DESC;
DROP TABLE t2;

--source include/test_db_charset_restore.inc
10 changes: 6 additions & 4 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13904,7 +13904,7 @@ int QUICK_SELECT_DESC::get_next()
* step back once, and move backwards
*/

for (;;)
for (;; last_range= nullptr, file->set_end_range(nullptr))
{
int result;
if (last_range)
Expand Down Expand Up @@ -13953,7 +13953,7 @@ int QUICK_SELECT_DESC::get_next()
DBUG_RETURN(local_error); // Empty table
if (cmp_prev(last_range) == 0)
DBUG_RETURN(0);
last_range= 0; // No match; go to next range
// No match; go to next range
continue;
}

Expand All @@ -13974,6 +13974,8 @@ int QUICK_SELECT_DESC::get_next()
last_range->make_min_endpoint(&min_range);
if (min_range.length > 0)
file->set_end_range(&min_range, handler::RANGE_SCAN_DESC);
else
file->set_end_range(nullptr);

DBUG_ASSERT(last_range->flag & NEAR_MAX ||
(last_range->flag & EQ_RANGE &&
Expand All @@ -13989,7 +13991,7 @@ int QUICK_SELECT_DESC::get_next()
{
if (result != HA_ERR_KEY_NOT_FOUND && result != HA_ERR_END_OF_FILE)
DBUG_RETURN(result);
last_range= 0; // Not found, to next range
// Not found, to next range
continue;
}
if (cmp_prev(last_range) == 0)
Expand All @@ -13998,7 +14000,7 @@ int QUICK_SELECT_DESC::get_next()
last_range= 0; // Stop searching
DBUG_RETURN(0); // Found key is in range
}
last_range= 0; // To next range
// To next range
}
}

Expand Down