revision-id: 53d1bde4487ab58d0a6ea1d7ad077f00c495ac82 (mariadb-10.4.4-116-g53d1bde4487) parent(s): fae1319450eea47e9bb6d33cf5134671931b5fdc author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2019-05-21 15:33:35 +0200 message: MDEV-19540: 10.4 allow lock options with SELECT in brackets which previous version do not Check locking options and brackets combinations. --- mysql-test/main/parser.result | 15 +++++++++++++++ mysql-test/main/parser.test | 16 ++++++++++++++++ sql/sql_lex.cc | 8 +++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/parser.result b/mysql-test/main/parser.result index 34c119a322e..2e2342161fc 100644 --- a/mysql-test/main/parser.result +++ b/mysql-test/main/parser.result @@ -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 diff --git a/mysql-test/main/parser.test b/mysql-test/main/parser.test index 3a7c4f6467e..35a2334eec2 100644 --- a/mysql-test/main/parser.test +++ b/mysql-test/main/parser.test @@ -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 diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 5550306877a..634ad6f6bfb 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -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; @@ -9513,7 +9519,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);