Skip to content

Commit bc4cac3

Browse files
committed
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.
1 parent 80d5d14 commit bc4cac3

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

mysql-test/r/view.result

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5799,6 +5799,31 @@ f1 f2
57995799
drop table t1, t2;
58005800
SELECT 1 FROM (SELECT 1 as a) AS b HAVING (SELECT `SOME_GARBAGE`.b.a)=1;
58015801
ERROR 42S22: Unknown column 'SOME_GARBAGE.b.a' in 'field list'
5802+
#
5803+
# MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1
5804+
# FOR UPDATE
5805+
#
5806+
CREATE TABLE t1 (a INT);
5807+
insert into t1 values (1),(2);
5808+
CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE;
5809+
SHOW CREATE VIEW v1;
5810+
View Create View character_set_client collation_connection
5811+
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
5812+
select * from v1;
5813+
a
5814+
1
5815+
2
5816+
DROP VIEW v1;
5817+
CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE;
5818+
SHOW CREATE VIEW v1;
5819+
View Create View character_set_client collation_connection
5820+
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
5821+
select * from v1;
5822+
a
5823+
1
5824+
2
5825+
DROP VIEW v1;
5826+
DROP TABLE t1;
58025827
# -----------------------------------------------------------------
58035828
# -- End of 10.0 tests.
58045829
# -----------------------------------------------------------------

mysql-test/t/view.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5694,6 +5694,28 @@ drop table t1, t2;
56945694
--error ER_BAD_FIELD_ERROR
56955695
SELECT 1 FROM (SELECT 1 as a) AS b HAVING (SELECT `SOME_GARBAGE`.b.a)=1;
56965696

5697+
5698+
--echo #
5699+
--echo # MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1
5700+
--echo # FOR UPDATE
5701+
--echo #
5702+
5703+
CREATE TABLE t1 (a INT);
5704+
insert into t1 values (1),(2);
5705+
5706+
CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE;
5707+
SHOW CREATE VIEW v1;
5708+
select * from v1;
5709+
DROP VIEW v1;
5710+
5711+
CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE;
5712+
SHOW CREATE VIEW v1;
5713+
select * from v1;
5714+
DROP VIEW v1;
5715+
5716+
DROP TABLE t1;
5717+
5718+
56975719
--echo # -----------------------------------------------------------------
56985720
--echo # -- End of 10.0 tests.
56995721
--echo # -----------------------------------------------------------------

sql/sql_lex.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,7 @@ void st_select_lex::init_select()
19431943
m_agg_func_used= false;
19441944
name_visibility_map= 0;
19451945
join= 0;
1946+
lock_type= TL_READ_DEFAULT;
19461947
}
19471948

19481949
/*

sql/sql_lex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,9 @@ class st_select_lex: public st_select_lex_node
846846
/* namp of nesting SELECT visibility (for aggregate functions check) */
847847
nesting_map name_visibility_map;
848848

849+
/* it is for correct printing SELECT options */
850+
thr_lock_type lock_type;
851+
849852
void init_query();
850853
void init_select();
851854
st_select_lex_unit* master_unit();

sql/sql_select.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24592,6 +24592,12 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
2459224592
// limit
2459324593
print_limit(thd, str, query_type);
2459424594

24595+
// lock type
24596+
if (lock_type == TL_READ_WITH_SHARED_LOCKS)
24597+
str->append(" lock in share mode");
24598+
else if (lock_type == TL_WRITE)
24599+
str->append(" for update");
24600+
2459524601
// PROCEDURE unsupported here
2459624602
}
2459724603

sql/sql_view.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,15 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
430430
lex->link_first_table_back(view, link_to_local);
431431
view->open_type= OT_BASE_ONLY;
432432

433+
/*
434+
ignore lock specs for CREATE statement
435+
*/
436+
if (lex->current_select->lock_type != TL_READ_DEFAULT)
437+
{
438+
lex->current_select->set_lock_for_tables(TL_READ_DEFAULT);
439+
view->mdl_request.set_type(MDL_EXCLUSIVE);
440+
}
441+
433442
if (open_temporary_tables(thd, lex->query_tables) ||
434443
open_and_lock_tables(thd, lex->query_tables, TRUE, 0))
435444
{

sql/sql_yacc.yy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8491,12 +8491,14 @@ select_lock_type:
84918491
| FOR_SYM UPDATE_SYM
84928492
{
84938493
LEX *lex=Lex;
8494+
lex->current_select->lock_type= TL_WRITE;
84948495
lex->current_select->set_lock_for_tables(TL_WRITE);
84958496
lex->safe_to_cache_query=0;
84968497
}
84978498
| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
84988499
{
84998500
LEX *lex=Lex;
8501+
lex->current_select->lock_type= TL_READ_WITH_SHARED_LOCKS;
85008502
lex->current_select->
85018503
set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
85028504
lex->safe_to_cache_query=0;

0 commit comments

Comments
 (0)