summaryrefslogtreecommitdiff
path: root/mysql-test/t/view.test
diff options
context:
space:
mode:
authorunknown <kroki/tomash@moonlight.intranet>2006-10-10 13:44:04 +0400
committerunknown <kroki/tomash@moonlight.intranet>2006-10-10 13:44:04 +0400
commit469ff92d81d496862ed1fcb7cf700390b7c2de72 (patch)
tree570b1da7c2c4f38e5729d20b5028727367d6045a /mysql-test/t/view.test
parent44a40f1dd4ea8ea2dbf12fd7fd851948a659aef0 (diff)
downloadmariadb-git-469ff92d81d496862ed1fcb7cf700390b7c2de72.tar.gz
Bug#19111: TRIGGERs selecting from a VIEW on the firing base table fail.
In a trigger or a function used in a statement it is possible to do SELECT from a table being modified by the statement. However, encapsulation of such SELECT into a view and selecting from a view instead of direct SELECT was not possible. This happened because tables used by views (which in their turn were used from functions/triggers) were not excluded from checks in unique_table() routine as it happens for the rest of tables added to the statement table list for prelocking. With this fix we ignore all such tables in unique_table(), thus providing consistency: inside a trigger or a functions SELECT from a view may be used where plain SELECT is allowed. Modification of the same table from function or trigger is still disallowed. Also, this patch doesn't affect the case where SELECT from the table being modified is done outside of function of trigger, such SELECTs are still disallowed (this limitation and visibility problem when function select from a table being modified are subjects of bug 21326). See also bug 22427. mysql-test/r/view.result: Add result for bug#19111: TRIGGERs selecting from a VIEW on the firing base table fail. mysql-test/t/view.test: Add test case for bug#19111: TRIGGERs selecting from a VIEW on the firing base table fail. sql/sql_base.cc: In unique_table() do not check tables that are used in a stored function or a trigger ('prelocking_placeholder' is set). If such function or a trigger will attempt to modify a table, the error will be given, however select is allowed there.
Diffstat (limited to 'mysql-test/t/view.test')
-rw-r--r--mysql-test/t/view.test39
1 files changed, 38 insertions, 1 deletions
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index a1c1e9b2ad1..56c0529a67b 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -2595,4 +2595,41 @@ CREATE TABLE t2 SELECT * FROM v1;
SELECT * FROM t2;
DROP VIEW v1;
-DROP TABLE IF EXISTS t1,t2;
+DROP TABLE t1,t2;
+
+
+#
+# Bug#19111: TRIGGERs selecting from a VIEW on the firing base table
+# fail
+#
+# Allow to select from a view on a table being modified in a trigger
+# and stored function, since plain select is allowed there.
+#
+--disable_warnings
+DROP FUNCTION IF EXISTS f1;
+DROP VIEW IF EXISTS v1;
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1);
+
+CREATE VIEW v1 AS SELECT MAX(i) FROM t1;
+
+# Plain 'SET NEW.i = (SELECT MAX(i) FROM t1) + 1' works, so select
+# from a view should work too.
+CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
+ SET NEW.i = (SELECT * FROM v1) + 1;
+INSERT INTO t1 VALUES (1);
+
+# Plain 'RETURN (SELECT MAX(i) FROM t1)' works in INSERT, so select
+# from a view should work too.
+CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1);
+UPDATE t1 SET i= f1();
+
+DROP FUNCTION f1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+
+--echo End of 5.0 tests.