Skip to content

Commit

Permalink
MDEV-19540: 10.4 allow lock options with SELECT in brackets which pre…
Browse files Browse the repository at this point in the history
…vious version do not

Check locking options and brackets combinations.
  • Loading branch information
sanja-byelkin committed May 21, 2019
1 parent fceffcd commit 1921df6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mysql-test/main/parser.result
Original file line number Diff line number Diff line change
Expand Up @@ -1770,3 +1770,18 @@ ERROR HY000: Unknown system variable 'password'
SELECT @@GLOBAL.role;
ERROR HY000: Unknown system variable 'role'
End of 10.3 tests
#
# MDEV-19540: 10.4 allow lock options with SELECT in brackets
# which previous version do not
#
create table t1 (a int);
(select * from t1) for update;
ERROR HY000: Incorrect usage of lock options and SELECT in brackets
(select * from t1) union (select * from t1) for update;
ERROR HY000: Incorrect usage of lock options and SELECT in brackets
(select * from t1 for update);
a
select * from t1 for update;
a
drop table t1;
# End of 10.4 tests
16 changes: 16 additions & 0 deletions mysql-test/main/parser.test
Original file line number Diff line number Diff line change
Expand Up @@ -1537,3 +1537,19 @@ SELECT @@GLOBAL.password;
SELECT @@GLOBAL.role;

--echo End of 10.3 tests

--echo #
--echo # MDEV-19540: 10.4 allow lock options with SELECT in brackets
--echo # which previous version do not
--echo #

create table t1 (a int);
--error ER_WRONG_USAGE
(select * from t1) for update;
--error ER_WRONG_USAGE
(select * from t1) union (select * from t1) for update;
(select * from t1 for update);
select * from t1 for update;
drop table t1;

--echo # End of 10.4 tests
8 changes: 7 additions & 1 deletion sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9246,6 +9246,12 @@ SELECT_LEX_UNIT *LEX::parsed_select_expr_cont(SELECT_LEX_UNIT *unit,
SELECT_LEX_UNIT *LEX::parsed_body_select(SELECT_LEX *sel,
Lex_order_limit_lock * l)
{
if (sel->braces && l && l->lock.defined_lock)
{
my_error(ER_WRONG_USAGE, MYF(0), "lock options",
"SELECT in brackets");
return NULL;
}
if (!(sel= parsed_select(sel, l)))
return NULL;

Expand Down Expand Up @@ -9519,7 +9525,7 @@ bool SELECT_LEX_UNIT::set_lock_to_the_last_select(Lex_select_lock l)
if (sel->braces)
{
my_error(ER_WRONG_USAGE, MYF(0), "lock options",
"End SELECT expression");
"SELECT in brackets");
return TRUE;
}
l.set_to(sel);
Expand Down

0 comments on commit 1921df6

Please sign in to comment.