From 6c621bbd7f6a62641f21994ad6371494491538ca Mon Sep 17 00:00:00 2001
From: unknown <pem@mysql.comhem.se>
Date: Fri, 18 Mar 2005 16:52:41 +0100
Subject: [PATCH] Fixed BUG#6600: Stored procedure crash after repeated calls
 with check table

mysql-test/r/sp.result:
  New test case for BUG#6600.
mysql-test/t/sp.test:
  New test case for BUG#6600.
sql/sp_head.cc:
  Added yet another multiple result set statement to the list.
sql/sql_parse.cc:
  Have to invalidate SP caches in CHECK TABLE, or it will produce very
  strange results when called in SPs.
---
 mysql-test/r/sp.result | 19 +++++++++++++++++++
 mysql-test/t/sp.test   | 22 ++++++++++++++++++++++
 sql/sp_head.cc         |  1 +
 sql/sql_parse.cc       |  2 ++
 4 files changed, 44 insertions(+)

diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 5366ecb2be..b2a1af03c9 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -2777,4 +2777,23 @@ a
 3.2000
 drop procedure bug8937|
 delete from t1|
+drop procedure if exists bug6600|
+drop table if exists t3|
+drop view if exists v1|
+create table t3 (s1 decimal(31,30))|
+create view v1 as select * from t3|
+create procedure bug6600()
+check table v1|
+call bug6600()|
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+call bug6600()|
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+call bug6600()|
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+drop procedure bug6600|
+drop view v1|
+drop table t3|
 drop table t1,t2;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index b8eb371931..5c2e02045c 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -3398,6 +3398,28 @@ drop procedure bug8937|
 delete from t1|
 
 
+#
+# BUG#6600: Stored procedure crash after repeated calls with check table
+#
+--disable_warnings
+drop procedure if exists bug6600|
+drop table if exists t3|
+drop view if exists v1|
+--enable_warnings
+create table t3 (s1 decimal(31,30))|
+create view v1 as select * from t3|
+
+create procedure bug6600()
+  check table v1|
+
+call bug6600()|
+call bug6600()|
+call bug6600()|
+drop procedure bug6600|
+drop view v1|
+drop table t3|
+
+
 #
 # BUG#NNNN: New bug synopsis
 #
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 89c4b2dbaa..037ef0b70c 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -58,6 +58,7 @@ sp_multi_results_command(enum enum_sql_command cmd)
 {
   switch (cmd) {
   case SQLCOM_ANALYZE:
+  case SQLCOM_CHECK:
   case SQLCOM_CHECKSUM:
   case SQLCOM_HA_READ:
   case SQLCOM_SHOW_BINLOGS:
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index cc5bd90e4f..d968f11113 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -27,6 +27,7 @@
 
 #include "sp_head.h"
 #include "sp.h"
+#include "sp_cache.h"
 
 #ifdef HAVE_OPENSSL
 /*
@@ -3045,6 +3046,7 @@ unsent_create_error:
       goto error; /* purecov: inspected */
     thd->slow_command=TRUE;
     res = mysql_check_table(thd, first_table, &lex->check_opt);
+    sp_cache_invalidate();
     break;
   }
   case SQLCOM_ANALYZE:
-- 
2.30.9