Skip to content

Commit 37bf7b1

Browse files
committed
MDEV-17610 Unexpected connection abort after certain operations from
within stored procedure Always set SERVER_MORE_RESULTS_EXIST when executing stored procedure. statements If statements produce a result, EOF packet needs this flag (SP ends with an OK packet). IF statetement does not produce a result, affected rows count are part of the final OK packet.
1 parent 6e71dde commit 37bf7b1

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

mysql-test/r/sp.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7635,6 +7635,22 @@ c1 c2 count(c3)
76357635
2012-03-01 02:00:00 3 1
76367636
DROP PROCEDURE p1;
76377637
# End of 5.5 test
7638+
CREATE PROCEDURE sp() ALTER TABLE non_existing_table OPTIMIZE PARTITION p0;
7639+
CALL sp;
7640+
Table Op Msg_type Msg_text
7641+
test.non_existing_table optimize Error Table 'test.non_existing_table' doesn't exist
7642+
test.non_existing_table optimize status Operation failed
7643+
SELECT 1;
7644+
1
7645+
1
7646+
DROP PROCEDURE sp;
7647+
CREATE PROCEDURE sp() SHOW USER_STATISTICS;
7648+
CALL sp;
7649+
User Total_connections Concurrent_connections Connected_time Busy_time Cpu_time Bytes_received Bytes_sent Binlog_bytes_written Rows_read Rows_sent Rows_deleted Rows_inserted Rows_updated Select_commands Update_commands Other_commands Commit_transactions Rollback_transactions Denied_connections Lost_connections Access_denied Empty_queries Total_ssl_connections Max_statement_time_exceeded
7650+
SELECT 1;
7651+
1
7652+
1
7653+
DROP PROCEDURE sp;
76387654
#
76397655
# Bug#12663165 SP DEAD CODE REMOVAL DOESN'T UNDERSTAND CONTINUE HANDLERS
76407656
#

mysql-test/t/sp.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9073,6 +9073,15 @@ DROP PROCEDURE p1;
90739073

90749074
--echo # End of 5.5 test
90759075

9076+
#MDEV-17610
9077+
CREATE PROCEDURE sp() ALTER TABLE non_existing_table OPTIMIZE PARTITION p0;
9078+
CALL sp;
9079+
SELECT 1;
9080+
DROP PROCEDURE sp;
9081+
CREATE PROCEDURE sp() SHOW USER_STATISTICS;
9082+
CALL sp;
9083+
SELECT 1;
9084+
DROP PROCEDURE sp;
90769085

90779086
--echo #
90789087
--echo # Bug#12663165 SP DEAD CODE REMOVAL DOESN'T UNDERSTAND CONTINUE HANDLERS

sql/sp_head.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ sp_get_flags_for_command(LEX *lex)
243243
case SQLCOM_SHOW_EXPLAIN:
244244
case SQLCOM_SHOW_FIELDS:
245245
case SQLCOM_SHOW_FUNC_CODE:
246+
case SQLCOM_SHOW_GENERIC:
246247
case SQLCOM_SHOW_GRANTS:
247248
case SQLCOM_SHOW_ENGINE_STATUS:
248249
case SQLCOM_SHOW_ENGINE_LOGS:

sql/sql_parse.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,15 +2442,14 @@ static bool do_execute_sp(THD *thd, sp_head *sp)
24422442
my_error(ER_SP_BADSELECT, MYF(0), sp->m_qname.str);
24432443
return 1;
24442444
}
2445-
/*
2446-
If SERVER_MORE_RESULTS_EXISTS is not set,
2447-
then remember that it should be cleared
2448-
*/
2449-
bits_to_be_cleared= (~thd->server_status &
2450-
SERVER_MORE_RESULTS_EXISTS);
2451-
thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
24522445
}
2453-
2446+
/*
2447+
If SERVER_MORE_RESULTS_EXISTS is not set,
2448+
then remember that it should be cleared
2449+
*/
2450+
bits_to_be_cleared= (~thd->server_status &
2451+
SERVER_MORE_RESULTS_EXISTS);
2452+
thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
24542453
ha_rows select_limit= thd->variables.select_limit;
24552454
thd->variables.select_limit= HA_POS_ERROR;
24562455

0 commit comments

Comments
 (0)