summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkonstantin@mysql.com <>2006-03-28 15:06:29 +0400
committerkonstantin@mysql.com <>2006-03-28 15:06:29 +0400
commit71defb7a8020e0797cdc3b7b68c1c96adcb7a4e6 (patch)
treeb8b09a147e82ee710a994bfe0d89df334c4fb965
parentcc1ee7e48b864387ad8184968f8792f248379d84 (diff)
downloadmariadb-git-71defb7a8020e0797cdc3b7b68c1c96adcb7a4e6.tar.gz
A fix and a test case for Bug#15683 "crash, Function on nested
VIEWs, Prepared statement": we didn't mark the nested views as 'prelockng placeholders' when building the prelocking list. This resulted in these views being processed (merged, materialized) before they are actually used.
-rw-r--r--mysql-test/r/sp-prelocking.result23
-rw-r--r--mysql-test/t/sp-prelocking.test31
-rw-r--r--sql/sql_view.cc1
3 files changed, 55 insertions, 0 deletions
diff --git a/mysql-test/r/sp-prelocking.result b/mysql-test/r/sp-prelocking.result
index c2614892016..2335513b28a 100644
--- a/mysql-test/r/sp-prelocking.result
+++ b/mysql-test/r/sp-prelocking.result
@@ -214,3 +214,26 @@ drop function f1;
drop function f2;
drop function f3;
drop procedure sp1;
+drop table if exists t1;
+drop view if exists v1, v2, v3;
+drop function if exists bug15683;
+create table t1 (f1 bigint, f2 varchar(20), f3 bigint);
+insert into t1 set f1 = 1, f2 = 'schoenenbourg', f3 = 1;
+create view v1 as select 1 from t1 union all select 1;
+create view v2 as select 1 from v1;
+create view v3 as select 1 as f1 from v2;
+create function bug15683() returns bigint
+begin
+return (select count(*) from v3);
+end|
+prepare stmt from "select bug15683()";
+execute stmt;
+bug15683()
+2
+execute stmt;
+bug15683()
+2
+deallocate prepare stmt;
+drop table t1;
+drop view v1, v2, v3;
+drop function bug15683;
diff --git a/mysql-test/t/sp-prelocking.test b/mysql-test/t/sp-prelocking.test
index 049dcc576dd..a7215462afb 100644
--- a/mysql-test/t/sp-prelocking.test
+++ b/mysql-test/t/sp-prelocking.test
@@ -241,3 +241,34 @@ drop function f2;
drop function f3;
drop procedure sp1;
+#
+# Bug#15683 "crash, Function on nested VIEWs, Prepared statement"
+# Check that when creating the prelocking list a nested view
+# is not merged until it's used.
+#
+--disable_warnings
+drop table if exists t1;
+drop view if exists v1, v2, v3;
+drop function if exists bug15683;
+--enable_warnings
+create table t1 (f1 bigint, f2 varchar(20), f3 bigint);
+insert into t1 set f1 = 1, f2 = 'schoenenbourg', f3 = 1;
+create view v1 as select 1 from t1 union all select 1;
+create view v2 as select 1 from v1;
+create view v3 as select 1 as f1 from v2;
+
+delimiter |;
+create function bug15683() returns bigint
+begin
+return (select count(*) from v3);
+end|
+delimiter ;|
+
+prepare stmt from "select bug15683()";
+execute stmt;
+execute stmt;
+deallocate prepare stmt;
+drop table t1;
+drop view v1, v2, v3;
+drop function bug15683;
+
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 2832adc1f8f..39d1ae5c9fb 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -938,6 +938,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table)
tbl->skip_temporary= 1;
tbl->belong_to_view= top_view;
tbl->referencing_view= table;
+ tbl->prelocking_placeholder= table->prelocking_placeholder;
/*
First we fill want_privilege with SELECT_ACL (this is needed for the
tables which belongs to view subqueries and temporary table views,