Commit bbce18c3 authored by unknown's avatar unknown

Fix for bug #31742: delete from ... order by function call that causes

an error, asserts server

In case of a fatal error during filesort in find_all_keys() the error
was returned without the necessary handler uninitialization.
Fixed by changing the code so that handler uninitialization is performed
before returning the error.


mysql-test/r/delete.result:
  Added a test case for bug #31742.
mysql-test/t/delete.test:
  Added a test case for bug #31742.
sql/filesort.cc:
  In case of a fatal error in find_all_keys() do not return before doing
  the necessary handler uninitialization steps.
parent 04311fab
...@@ -271,3 +271,11 @@ a ...@@ -271,3 +271,11 @@ a
DROP TABLE t1, t2; DROP TABLE t1, t2;
DROP DATABASE db1; DROP DATABASE db1;
DROP DATABASE db2; DROP DATABASE db2;
CREATE FUNCTION f1() RETURNS INT RETURN 1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0);
DELETE FROM t1 ORDER BY (f1(10)) LIMIT 1;
ERROR 42000: Incorrect number of arguments for FUNCTION test.f1; expected 0, got 1
DROP TABLE t1;
DROP FUNCTION f1;
End of 5.0 tests
...@@ -277,3 +277,18 @@ SELECT * FROM t1; ...@@ -277,3 +277,18 @@ SELECT * FROM t1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
DROP DATABASE db1; DROP DATABASE db1;
DROP DATABASE db2; DROP DATABASE db2;
#
# Bug 31742: delete from ... order by function call that causes an error,
# asserts server
#
CREATE FUNCTION f1() RETURNS INT RETURN 1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0);
--error 1318
DELETE FROM t1 ORDER BY (f1(10)) LIMIT 1;
DROP TABLE t1;
DROP FUNCTION f1;
--echo End of 5.0 tests
...@@ -534,7 +534,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ...@@ -534,7 +534,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
file->unlock_row(); file->unlock_row();
/* It does not make sense to read more keys in case of a fatal error */ /* It does not make sense to read more keys in case of a fatal error */
if (thd->net.report_error) if (thd->net.report_error)
DBUG_RETURN(HA_POS_ERROR); break;
} }
if (quick_select) if (quick_select)
{ {
...@@ -551,6 +551,9 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ...@@ -551,6 +551,9 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
file->ha_rnd_end(); file->ha_rnd_end();
} }
if (thd->net.report_error)
DBUG_RETURN(HA_POS_ERROR);
DBUG_PRINT("test",("error: %d indexpos: %d",error,indexpos)); DBUG_PRINT("test",("error: %d indexpos: %d",error,indexpos));
if (error != HA_ERR_END_OF_FILE) if (error != HA_ERR_END_OF_FILE)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment