Commit bc4cac35 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 80d5d145
......@@ -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.
# -----------------------------------------------------------------
......
......@@ -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 # -----------------------------------------------------------------
......
......@@ -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;
}
/*
......
......@@ -846,6 +846,9 @@ class st_select_lex: public st_select_lex_node
/* 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();
......
......@@ -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
}
......
......@@ -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))
{
......
......@@ -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;
......
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