summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnurag Shekhar <anurag.shekhar@sun.com>2009-04-17 11:21:51 +0530
committerAnurag Shekhar <anurag.shekhar@sun.com>2009-04-17 11:21:51 +0530
commit0501328a7deaa77b3b889ea75459ea6d818181b5 (patch)
treefb4254969f7857b83c4bbe473b44f1c80cd8c8eb
parentc90a869c6b5a2ec80e6e917a862872b0d3a40a54 (diff)
downloadmariadb-git-0501328a7deaa77b3b889ea75459ea6d818181b5.tar.gz
Bug#44040 MySQL allows creating a MERGE table upon VIEWs but crashes when
using it. The crash was due to a null pointer present for select_lex while processing the view. Adding a check while opening the view to see if its a child of a merge table fixed this problem. mysql-test/r/merge.result: Updated result for the new test case. mysql-test/t/merge.test: Added test case based on the bug description. sql/sql_base.cc: Added a check to check if the view being opened is a child table of a merge table and return error if it is.
-rw-r--r--mysql-test/r/merge.result12
-rw-r--r--mysql-test/t/merge.test21
-rw-r--r--sql/sql_base.cc10
3 files changed, 43 insertions, 0 deletions
diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result
index d844abc1847..f53b328d14e 100644
--- a/mysql-test/r/merge.result
+++ b/mysql-test/r/merge.result
@@ -2115,4 +2115,16 @@ insert into m1 (col1) values (1);
insert into m1 (col1) values (1);
ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
drop table m1, t1;
+CREATE TABLE t1 (
+col1 INT(10)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+CREATE VIEW v1 as SELECT * FROM t1;
+CREATE TABLE m1 (
+col1 INT(10)
+)ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(v1);
+#Select should detect that the child table is a view and fail.
+SELECT * FROM m1;
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
+DROP VIEW v1;
+DROP TABLE m1, t1;
End of 5.1 tests
diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test
index f12187ea143..5315c91daa6 100644
--- a/mysql-test/t/merge.test
+++ b/mysql-test/t/merge.test
@@ -1514,4 +1514,25 @@ insert into m1 (col1) values (1);
insert into m1 (col1) values (1);
drop table m1, t1;
+
+#
+#Bug #44040 MySQL allows creating a MERGE table upon VIEWs but crashes
+#when using it
+#
+
+CREATE TABLE t1 (
+ col1 INT(10)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+CREATE VIEW v1 as SELECT * FROM t1;
+CREATE TABLE m1 (
+ col1 INT(10)
+)ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(v1);
+
+--echo #Select should detect that the child table is a view and fail.
+--error ER_WRONG_MRG_TABLE
+SELECT * FROM m1;
+
+DROP VIEW v1;
+DROP TABLE m1, t1;
--echo End of 5.1 tests
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0f0ee7c529e..0dc29f7e3c2 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -3844,6 +3844,16 @@ retry:
if (share->is_view)
{
/*
+ If parent_l of the table_list is non null then a merge table
+ has this view as child table, which is not supported.
+ */
+ if (table_list->parent_l)
+ {
+ my_error(ER_WRONG_MRG_TABLE, MYF(0));
+ goto err;
+ }
+
+ /*
This table is a view. Validate its metadata version: in particular,
that it was a view when the statement was prepared.
*/