[Commits] 4ffe229: MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE

Oleksandr Byelkin sanja at mariadb.com
Sun May 15 16:25:33 EEST 2016


revision-id: 4ffe2295e78538dde93df078421726f0c5a7d2a2 (mariadb-10.2.0-29-g4ffe229)
parent(s): b79944950e5e5db40cf7ad49061edf5f105512c4
committer: Oleksandr Byelkin
timestamp: 2016-05-15 15:25:33 +0200
message:

MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE

Lock type specifications prohibited in a view definition.

---
 mysql-test/r/view.result  | 11 +++++++++++
 mysql-test/t/view.test    | 11 +++++++++++
 sql/share/errmsg-utf8.txt |  2 ++
 sql/sql_lex.cc            |  1 +
 sql/sql_lex.h             |  1 +
 sql/sql_yacc.yy           | 15 +++++++++++++++
 6 files changed, 41 insertions(+)

diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 3fccd6e..cab7b5a 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -5953,5 +5953,16 @@ t3	CREATE TABLE `t3` (
 DROP VIEW v1;
 DROP TABLE t1,t2,t3;
 #
+# MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1
+# FOR UPDATE
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (10);
+CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE;
+ERROR 42000: Lock type specification is not allowed here
+CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE;
+ERROR 42000: Lock type specification is not allowed here
+DROP TABLE t1;
+#
 # End of 10.2 tests
 #
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index d11b7f0..e27e2ce 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -5784,6 +5784,17 @@ SHOW CREATE TABLE t3;
 DROP VIEW v1;
 DROP TABLE t1,t2,t3;
 
+--echo #
+--echo # MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1
+--echo # FOR UPDATE
+--echo #
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (10);
+--error ER_NO_LOCK_TYPE_SPEC
+CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE;
+--error ER_NO_LOCK_TYPE_SPEC
+CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE;
+DROP TABLE t1;
 
 --echo #
 --echo # End of 10.2 tests
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 376c1eb..e0d3aba 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7201,3 +7201,5 @@ ER_WINDOW_FUNCTION_DONT_HAVE_FRAME
         eng "This window function may not have a window frame"
 ER_INVALID_NTILE_ARGUMENT
         eng "Argument of NTILE must be greater than 0"
+ER_NO_LOCK_TYPE_SPEC 42000
+        eng "Lock type specification is not allowed here"
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index de345b4..7633cc3 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -235,6 +235,7 @@ st_parsing_options::reset()
   allows_select_into= TRUE;
   allows_select_procedure= TRUE;
   allows_derived= TRUE;
+  allows_lock_type= TRUE;
 }
 
 
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 10247bd..a4d948e 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1820,6 +1820,7 @@ struct st_parsing_options
   bool allows_select_into;
   bool allows_select_procedure;
   bool allows_derived;
+  bool allows_lock_type;
 
   st_parsing_options() { reset(); }
   void reset();
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 9468254..341c2b5 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -8723,12 +8723,25 @@ opt_select_lock_type:
         | FOR_SYM UPDATE_SYM
           {
             LEX *lex=Lex;
+            if (!lex->parsing_options.allows_lock_type)
+            {
+              my_message(ER_NO_LOCK_TYPE_SPEC,
+                         ER_THD(thd, ER_NO_LOCK_TYPE_SPEC), MYF(0));
+              MYSQL_YYABORT;
+            }
+
             lex->current_select->set_lock_for_tables(TL_WRITE);
             lex->safe_to_cache_query=0;
           }
         | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
           {
             LEX *lex=Lex;
+            if (!lex->parsing_options.allows_lock_type)
+            {
+              my_message(ER_NO_LOCK_TYPE_SPEC,
+                         ER_THD(thd, ER_NO_LOCK_TYPE_SPEC), MYF(0));
+              MYSQL_YYABORT;
+            }
             lex->current_select->
               set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
             lex->safe_to_cache_query=0;
@@ -16614,6 +16627,7 @@ view_select:
             lex->parsing_options.allows_select_into= FALSE;
             lex->parsing_options.allows_select_procedure= FALSE;
             lex->parsing_options.allows_derived= FALSE;
+            lex->parsing_options.allows_lock_type= FALSE;
             lex->create_view_select.str= (char *) YYLIP->get_cpp_ptr();
           }
           opt_with_clause view_select_aux view_check_option
@@ -16628,6 +16642,7 @@ view_select:
             lex->parsing_options.allows_select_into= TRUE;
             lex->parsing_options.allows_select_procedure= TRUE;
             lex->parsing_options.allows_derived= TRUE;
+            lex->parsing_options.allows_lock_type= TRUE;
             lex->current_select->set_with_clause($2);
           }
         ;


More information about the commits mailing list