1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-29537 Creation of view with UNION and SELECT ... FOR UPDATE in definition is failed with error

lock_type is writen in the last SELECT of the unit even if it parsed last,
so it should be printed last from the last select of the unit.
This commit is contained in:
Oleksandr Byelkin
2024-09-20 14:58:23 +02:00
parent cc810e64d4
commit 8d810e9426
5 changed files with 96 additions and 4 deletions

View File

@ -6970,3 +6970,34 @@ DROP VIEW v1;
DROP VIEW v2;
DROP TABLE t;
# End of 10.4 tests
#
# MDEV-29537: Creation of view with UNION and SELECT ... FOR UPDATE
# in definition is failed with error
#
CREATE TABLE t1 (i INT);
CREATE VIEW v1 AS SELECT 1 FROM t1
UNION
SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1
FOR UPDATE;
SELECT * FROM v1;
1
1
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 1 AS `1` from `t1` union select 1 AS `1` from DUAL where 1 group by 1 having 1 order by 1 for update latin1 latin1_swedish_ci
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1 (i INT);
CREATE VIEW v1 AS SELECT 1 FROM t1
UNION
(SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1
FOR UPDATE);
SELECT * FROM v1;
1
1
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 1 AS `1` from `t1` union (select 1 AS `1` from DUAL where 1 group by 1 having 1 for update) latin1 latin1_swedish_ci
DROP VIEW v1;
DROP TABLE t1;
# End of 10.5 tests

View File

@ -6726,3 +6726,35 @@ DROP VIEW v2;
DROP TABLE t;
--echo # End of 10.4 tests
--echo #
--echo # MDEV-29537: Creation of view with UNION and SELECT ... FOR UPDATE
--echo # in definition is failed with error
--echo #
CREATE TABLE t1 (i INT);
CREATE VIEW v1 AS SELECT 1 FROM t1
UNION
SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1
FOR UPDATE;
SELECT * FROM v1;
SHOW CREATE VIEW v1;
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1 (i INT);
CREATE VIEW v1 AS SELECT 1 FROM t1
UNION
(SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1
FOR UPDATE);
SELECT * FROM v1;
SHOW CREATE VIEW v1;
DROP VIEW v1;
DROP TABLE t1;
--echo # End of 10.5 tests

View File

@ -3788,6 +3788,8 @@ void st_select_lex_unit::print(String *str, enum_query_type query_type)
}
else if (saved_fake_select_lex)
saved_fake_select_lex->print_limit(thd, str, query_type);
print_lock_from_the_last_select(str);
}
@ -10612,6 +10614,22 @@ bool SELECT_LEX_UNIT::set_lock_to_the_last_select(Lex_select_lock l)
return FALSE;
}
void SELECT_LEX_UNIT::print_lock_from_the_last_select(String *str)
{
SELECT_LEX *sel= first_select();
while (sel->next_select())
sel= sel->next_select();
if(sel->braces)
return; // braces processed in st_select_lex::print
// lock type
sel->print_lock_type(str);
return;
}
/**
Generate unique name for generated derived table for this SELECT
*/

View File

@ -1042,6 +1042,7 @@ public:
bool check_parameters(SELECT_LEX *main_select);
bool set_lock_to_the_last_select(Lex_select_lock l);
void print_lock_from_the_last_select(String *str);
bool can_be_merged();
@ -1465,6 +1466,7 @@ public:
bool setup_ref_array(THD *thd, uint order_group_num);
uint get_cardinality_of_ref_ptrs_slice(uint order_group_num_arg);
void print(THD *thd, String *str, enum_query_type query_type);
void print_lock_type(String *str);
void print_item_list(THD *thd, String *str, enum_query_type query_type);
void print_set_clause(THD *thd, String *str, enum_query_type query_type);
void print_on_duplicate_key_clause(THD *thd, String *str,

View File

@ -28787,6 +28787,16 @@ void st_select_lex::print_on_duplicate_key_clause(THD *thd, String *str,
}
}
void st_select_lex::print_lock_type(String *str)
{
if (lock_type == TL_READ_WITH_SHARED_LOCKS)
str->append(" lock in share mode");
else if (lock_type == TL_WRITE)
str->append(" for update");
}
void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
{
DBUG_ASSERT(thd);
@ -29059,10 +29069,9 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type 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");
if (braces) /* no braces processed in
SELECT_LEX_UNIT::print_lock_from_the_last_select */
print_lock_type(str);
if ((sel_type == INSERT_CMD || sel_type == REPLACE_CMD) &&
thd->lex->update_list.elements)