From ecfd9958a19d76250f5cb611eaace7b4caa1ad7c Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Mon, 5 Jul 2010 13:59:34 +0200 Subject: [PATCH] Bug #54401 assert in Diagnostics_area::set_eof_status , HANDLER This assert checks that the server does not try to send EOF to the client if there has been some error during processing. This to make sure that the error is in fact sent to the client. The problem was that any errors during processing of WHERE conditions in HANDLER ... READ statements where not detected by the handler code. The handler code therefore still tried to send EOF to the client, triggering the assert. The bug was only noticeable in debug builds. This patch fixes the problem by making sure that the handler code checks for errors during condition processing and acts accordingly. --- mysql-test/include/handler.inc | 32 ++++++++++++++++++++++++++++++ mysql-test/r/handler_innodb.result | 20 +++++++++++++++++++ mysql-test/r/handler_myisam.result | 20 +++++++++++++++++++ sql/sql_handler.cc | 4 ++++ 4 files changed, 76 insertions(+) diff --git a/mysql-test/include/handler.inc b/mysql-test/include/handler.inc index 0031cb68647..98988ab55ba 100644 --- a/mysql-test/include/handler.inc +++ b/mysql-test/include/handler.inc @@ -1757,3 +1757,35 @@ disconnect con51355; --echo # Connection default connection default; + +--echo # +--echo # Bug#54401 assert in Diagnostics_area::set_eof_status , HANDLER +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +delimiter |; +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN + SELECT 1 FROM t2 INTO @a; + RETURN 1; +END| +delimiter ;| + +# Get f1() parsed and cached +--error ER_NO_SUCH_TABLE +SELECT f1(); + +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (1); +HANDLER t1 OPEN; +# This used to cause the assert +--error ER_NO_SUCH_TABLE +HANDLER t1 READ FIRST WHERE f1() = 1; +HANDLER t1 CLOSE; + +DROP FUNCTION f1; +DROP TABLE t1; diff --git a/mysql-test/r/handler_innodb.result b/mysql-test/r/handler_innodb.result index 08d2fc58e8a..121cfa89f1c 100644 --- a/mysql-test/r/handler_innodb.result +++ b/mysql-test/r/handler_innodb.result @@ -1710,3 +1710,23 @@ ERROR 42S02: Table 'test.t1' doesn't exist HANDLER t1 CLOSE; # Connection con51355 # Connection default +# +# Bug#54401 assert in Diagnostics_area::set_eof_status , HANDLER +# +DROP TABLE IF EXISTS t1, t2; +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN +SELECT 1 FROM t2 INTO @a; +RETURN 1; +END| +SELECT f1(); +ERROR 42S02: Table 'test.t2' doesn't exist +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (1); +HANDLER t1 OPEN; +HANDLER t1 READ FIRST WHERE f1() = 1; +ERROR 42S02: Table 'test.t2' doesn't exist +HANDLER t1 CLOSE; +DROP FUNCTION f1; +DROP TABLE t1; diff --git a/mysql-test/r/handler_myisam.result b/mysql-test/r/handler_myisam.result index 31bc828b0b9..fd08fd12f15 100644 --- a/mysql-test/r/handler_myisam.result +++ b/mysql-test/r/handler_myisam.result @@ -1707,6 +1707,26 @@ HANDLER t1 CLOSE; # Connection con51355 # Connection default # +# Bug#54401 assert in Diagnostics_area::set_eof_status , HANDLER +# +DROP TABLE IF EXISTS t1, t2; +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1() RETURNS INTEGER +BEGIN +SELECT 1 FROM t2 INTO @a; +RETURN 1; +END| +SELECT f1(); +ERROR 42S02: Table 'test.t2' doesn't exist +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (1); +HANDLER t1 OPEN; +HANDLER t1 READ FIRST WHERE f1() = 1; +ERROR 42S02: Table 'test.t2' doesn't exist +HANDLER t1 CLOSE; +DROP FUNCTION f1; +DROP TABLE t1; +# # BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash # CREATE TABLE t1 AS SELECT 1 AS f1; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index d6f2a472e05..e49da2b0423 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -747,7 +747,11 @@ retry: goto ok; } if (cond && !cond->val_int()) + { + if (thd->is_error()) + goto err; continue; + } if (num_rows >= offset_limit_cnt) { protocol->prepare_for_resend();