diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2017-01-04 13:26:09 +0100 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2017-01-04 13:27:45 +0100 |
commit | bc4cac358ed0d08daaa3cb869b3ecc444afa09fa (patch) | |
tree | af059e932b6ab8dd758e8dae6920b9b23b74d3e1 | |
parent | 80d5d1452a4a6b7bd1627116f2a5a950003fc3cb (diff) | |
download | mariadb-git-bc4cac358ed0d08daaa3cb869b3ecc444afa09fa.tar.gz |
MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE
Ability to print lock type added.
Restoring correct lock type for CREATE VIEW added.
-rw-r--r-- | mysql-test/r/view.result | 25 | ||||
-rw-r--r-- | mysql-test/t/view.test | 22 | ||||
-rw-r--r-- | sql/sql_lex.cc | 1 | ||||
-rw-r--r-- | sql/sql_lex.h | 3 | ||||
-rw-r--r-- | sql/sql_select.cc | 6 | ||||
-rw-r--r-- | sql/sql_view.cc | 9 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 2 |
7 files changed, 68 insertions, 0 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 924b3a11fef..6530fd10a6a 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -5799,6 +5799,31 @@ f1 f2 drop table t1, t2; SELECT 1 FROM (SELECT 1 as a) AS b HAVING (SELECT `SOME_GARBAGE`.b.a)=1; ERROR 42S22: Unknown column 'SOME_GARBAGE.b.a' in 'field list' +# +# 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.0 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 241b3b414f6..5ea97f6465e 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -5694,6 +5694,28 @@ drop table t1, t2; --error ER_BAD_FIELD_ERROR SELECT 1 FROM (SELECT 1 as a) AS b HAVING (SELECT `SOME_GARBAGE`.b.a)=1; + +--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.0 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 9d5f4cfcb5b..d20c5ae78af 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1943,6 +1943,7 @@ void st_select_lex::init_select() m_agg_func_used= false; name_visibility_map= 0; join= 0; + lock_type= TL_READ_DEFAULT; } /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 019231e2004..c4fd109009f 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -846,6 +846,9 @@ public: /* namp of nesting SELECT visibility (for aggregate functions check) */ nesting_map name_visibility_map; + /* it is for correct printing SELECT options */ + thr_lock_type lock_type; + void init_query(); void init_select(); st_select_lex_unit* master_unit(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f345d3c9687..09ceb16fcba 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -24592,6 +24592,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 f3717e3ded2..9fe4dd4849d 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -430,6 +430,15 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, lex->link_first_table_back(view, link_to_local); view->open_type= OT_BASE_ONLY; + /* + 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 (open_temporary_tables(thd, 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 c9fd000141a..bf354496433 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -8491,12 +8491,14 @@ 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; |