summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/check.result9
-rw-r--r--mysql-test/t/check.test12
-rw-r--r--sql/sql_table.cc7
3 files changed, 28 insertions, 0 deletions
diff --git a/mysql-test/r/check.result b/mysql-test/r/check.result
index ecaa13642bd..4c565f4f1b1 100644
--- a/mysql-test/r/check.result
+++ b/mysql-test/r/check.result
@@ -5,3 +5,12 @@ insert into t1 values (200000);
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
+Create table t1(f1 int);
+Create table t2(f1 int);
+Create view v1 as Select * from t1;
+Check Table v1,t2;
+Table Op Msg_type Msg_text
+test.v1 check status OK
+test.t2 check status OK
+drop view v1;
+drop table t1, t2;
diff --git a/mysql-test/t/check.test b/mysql-test/t/check.test
index bc61aea2d66..c502655818d 100644
--- a/mysql-test/t/check.test
+++ b/mysql-test/t/check.test
@@ -22,3 +22,15 @@ connection con1;
reap;
drop table t1;
+#
+# Bug #9897 Views: 'Check Table' crashes MySQL, with a view and a table
+# in the statement
+#
+
+connection default;
+Create table t1(f1 int);
+Create table t2(f1 int);
+Create view v1 as Select * from t1;
+Check Table v1,t2;
+drop view v1;
+drop table t1, t2;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 6fcde27b537..bbe7c53147b 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -2344,6 +2344,13 @@ send_result_message:
}
close_thread_tables(thd);
table->table=0; // For query cache
+ /*
+ thd->lex->derived_tables may be set to non zero value if we open
+ a view. It is necessary to clear thd->lex->derived_tables flag
+ to prevent processing of derived tables during next open_and_lock_tables
+ if next table is a real table.
+ */
+ thd->lex->derived_tables= 0;
if (protocol->write())
goto err;
}