summaryrefslogtreecommitdiff
path: root/mysql-test/t/lock.test
diff options
context:
space:
mode:
authorKristofer Pettersson <kristofer.pettersson@sun.com>2009-03-05 15:22:33 +0100
committerKristofer Pettersson <kristofer.pettersson@sun.com>2009-03-05 15:22:33 +0100
commitddaede8087c66bfd28a5a9e74d26143254deb63a (patch)
tree37053e7724481a2dcfeeb3ddd6925d1003ecadff /mysql-test/t/lock.test
parentd61f114f7f753e8443d48190826f121662066967 (diff)
downloadmariadb-git-ddaede8087c66bfd28a5a9e74d26143254deb63a.tar.gz
Bug#39843 DELETE requires write access to table in subquery in where clause
An unnecessarily restrictive lock were taken on sub-SELECTs during DELETE. During parsing, a global structure is reused for sub-SELECTs and the attribute keeping track of lock options were not reset properly. This patch introduces a new attribute to keep track on the syntactical lock option elements found in a sub-SELECT and then sets the lock options accordingly. Now the sub-SELECTs will try to acquire a READ lock if possible instead of a WRITE lock as inherited from the outer DELETE statement. mysql-test/r/lock.result: Added test case for bug39843 mysql-test/t/lock.test: Added test case for bug39843 sql/sql_lex.cc: * Reset member variable lock_option on each new query. sql/sql_lex.h: * Introduced new member variable 'lock_option' which is keeping track of the syntactical lock option of a (sub-)select query. sql/sql_parse.cc: * Wrote comments to functions. sql/sql_yacc.yy: * Introduced an attribute to keep track of syntactical lock options in sub-selects. * Made sure that the default value TL_READ_DEFAULT is at the begining of each subselect-rule.
Diffstat (limited to 'mysql-test/t/lock.test')
-rw-r--r--mysql-test/t/lock.test30
1 files changed, 30 insertions, 0 deletions
diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test
index 6069bbf7018..30f4d4d6c61 100644
--- a/mysql-test/t/lock.test
+++ b/mysql-test/t/lock.test
@@ -214,4 +214,34 @@ create view v_bug5719 as select * from t2;
--echo
drop table t2, t3;
+--echo #
+--echo # Bug#39843 DELETE requires write access to table in subquery in where clause
+--echo #
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2;
+--enable_warnings
+CREATE TABLE t1 (
+table1_rowid SMALLINT NOT NULL
+);
+CREATE TABLE t2 (
+table2_rowid SMALLINT NOT NULL
+);
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+LOCK TABLES t1 WRITE, t2 READ;
+--echo # Sub-select should not try to aquire a write lock.
+DELETE FROM t1
+WHERE EXISTS
+(
+SELECT 'x'
+FROM t2
+WHERE t1.table1_rowid = t2.table2_rowid
+) ;
+--echo # While implementing the patch we didn't break old behavior;
+--echo # The following sub-select should still requires a write lock:
+--error ER_TABLE_NOT_LOCKED_FOR_WRITE
+SELECT * FROM t1 WHERE 1 IN (SELECT * FROM t2 FOR UPDATE);
+UNLOCK TABLES;
+DROP TABLE t1,t2;
+
--echo End of 5.1 tests.