Commit 1da21cd4 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

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.
parent 3dcca1b7
...@@ -6236,5 +6236,30 @@ i j ...@@ -6236,5 +6236,30 @@ i j
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1, t2, t3; 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 # End of 10.2 tests
# #
...@@ -5984,6 +5984,26 @@ SELECT * FROM v1; ...@@ -5984,6 +5984,26 @@ SELECT * FROM v1;
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1, t2, t3; 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 #
--echo # End of 10.2 tests --echo # End of 10.2 tests
--echo # --echo #
...@@ -2171,6 +2171,7 @@ void st_select_lex::init_select() ...@@ -2171,6 +2171,7 @@ void st_select_lex::init_select()
name_visibility_map= 0; name_visibility_map= 0;
with_dep= 0; with_dep= 0;
join= 0; join= 0;
lock_type= TL_READ_DEFAULT;
} }
/* /*
......
...@@ -925,6 +925,9 @@ class st_select_lex: public st_select_lex_node ...@@ -925,6 +925,9 @@ class st_select_lex: public st_select_lex_node
table_map with_dep; table_map with_dep;
/* it is for correct printing SELECT options */
thr_lock_type lock_type;
void init_query(); void init_query();
void init_select(); void init_select();
st_select_lex_unit* master_unit() { return (st_select_lex_unit*) master; } st_select_lex_unit* master_unit() { return (st_select_lex_unit*) master; }
......
...@@ -25162,6 +25162,12 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) ...@@ -25162,6 +25162,12 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
// limit // limit
print_limit(thd, str, query_type); 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 // PROCEDURE unsupported here
} }
......
...@@ -436,6 +436,15 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, ...@@ -436,6 +436,15 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
goto err; 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) || if (thd->open_temporary_tables(lex->query_tables) ||
open_and_lock_tables(thd, lex->query_tables, TRUE, 0)) open_and_lock_tables(thd, lex->query_tables, TRUE, 0))
{ {
......
...@@ -8645,12 +8645,14 @@ opt_select_lock_type: ...@@ -8645,12 +8645,14 @@ opt_select_lock_type:
| FOR_SYM UPDATE_SYM | FOR_SYM UPDATE_SYM
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->current_select->lock_type= TL_WRITE;
lex->current_select->set_lock_for_tables(TL_WRITE); lex->current_select->set_lock_for_tables(TL_WRITE);
lex->safe_to_cache_query=0; lex->safe_to_cache_query=0;
} }
| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->current_select->lock_type= TL_READ_WITH_SHARED_LOCKS;
lex->current_select-> lex->current_select->
set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS); set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
lex->safe_to_cache_query=0; lex->safe_to_cache_query=0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment