summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/view.result25
-rw-r--r--mysql-test/t/view.test20
-rw-r--r--sql/sql_lex.cc1
-rw-r--r--sql/sql_lex.h3
-rw-r--r--sql/sql_select.cc6
-rw-r--r--sql/sql_view.cc11
-rw-r--r--sql/sql_yacc.yy2
7 files changed, 67 insertions, 1 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 8ab215fd99a..7db28cf80df 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -6236,5 +6236,30 @@ i j
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 (1),(2);
+CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE;
+SHOW CREATE VIEW v1;
+View Create View character_set_client collation_connection
+v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` for update latin1 latin1_swedish_ci
+select * from v1;
+a
+1
+2
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE;
+SHOW CREATE VIEW v1;
+View Create View character_set_client collation_connection
+v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` lock in share mode latin1 latin1_swedish_ci
+select * from v1;
+a
+1
+2
+DROP VIEW v1;
+DROP TABLE t1;
+#
# End of 10.2 tests
#
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index e2bc2168385..ae3f57d49f4 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -5984,6 +5984,26 @@ SELECT * FROM v1;
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 (1),(2);
+
+CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE;
+SHOW CREATE VIEW v1;
+select * from v1;
+DROP VIEW v1;
+
+CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE;
+SHOW CREATE VIEW v1;
+select * from v1;
+DROP VIEW v1;
+
+DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 08b619668fb..0217b8d8ef8 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2171,6 +2171,7 @@ void st_select_lex::init_select()
name_visibility_map= 0;
with_dep= 0;
join= 0;
+ lock_type= TL_READ_DEFAULT;
}
/*
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 128b57438f0..dbe76703c56 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -925,6 +925,9 @@ public:
table_map with_dep;
+ /* it is for correct printing SELECT options */
+ thr_lock_type lock_type;
+
void init_query();
void init_select();
st_select_lex_unit* master_unit() { return (st_select_lex_unit*) master; }
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e6bb6e03e43..bf92e3e3d5c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -25162,6 +25162,12 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
// limit
print_limit(thd, str, query_type);
+ // lock type
+ if (lock_type == TL_READ_WITH_SHARED_LOCKS)
+ str->append(" lock in share mode");
+ else if (lock_type == TL_WRITE)
+ str->append(" for update");
+
// PROCEDURE unsupported here
}
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 4744b442842..c0d9ba48121 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -435,7 +435,16 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
res= TRUE;
goto err;
}
-
+
+ /*
+ ignore lock specs for CREATE statement
+ */
+ if (lex->current_select->lock_type != TL_READ_DEFAULT)
+ {
+ lex->current_select->set_lock_for_tables(TL_READ_DEFAULT);
+ view->mdl_request.set_type(MDL_EXCLUSIVE);
+ }
+
if (thd->open_temporary_tables(lex->query_tables) ||
open_and_lock_tables(thd, lex->query_tables, TRUE, 0))
{
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 8a263ae23f7..63ba77caa22 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -8645,12 +8645,14 @@ opt_select_lock_type:
| FOR_SYM UPDATE_SYM
{
LEX *lex=Lex;
+ lex->current_select->lock_type= TL_WRITE;
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;
+ lex->current_select->lock_type= TL_READ_WITH_SHARED_LOCKS;
lex->current_select->
set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
lex->safe_to_cache_query=0;