1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-28342: sys.create_synonym_db fails when a temporary table masks a base table

- This commit rely on MDEV-28391
- When temporary table shadows the base table, error is raised (it can be changed if needed),
  since the procedure is relying on creating the views and view cannot be created from the temporary table.

- Reviewed by: <wlad@mariadb.com>
This commit is contained in:
anel
2022-04-22 06:34:12 -07:00
committed by Anel Husakovic
parent b729896d00
commit c1063a1bed
3 changed files with 48 additions and 3 deletions

View File

@@ -97,9 +97,8 @@ BEGIN
DECLARE v_db_err_msg TEXT;
DECLARE v_table VARCHAR(64);
DECLARE v_views_created INT DEFAULT 0;
DECLARE db_doesnt_exist CONDITION FOR SQLSTATE '42000';
DECLARE db_name_exists CONDITION FOR SQLSTATE 'HY000';
DECLARE v_table_exists ENUM('', 'BASE TABLE', 'VIEW', 'TEMPORARY') DEFAULT '';
DECLARE v_temp_table TEXT;
DECLARE c_table_names CURSOR FOR
SELECT TABLE_NAME
@@ -144,6 +143,21 @@ BEGIN
LEAVE c_table_names;
END IF;
-- Check does temporary table shadows the base table. If it is so, terminate.
CALL sys.table_exists(in_db_name, v_table, v_table_exists);
IF (v_table_exists = 'TEMPORARY') THEN
SET v_temp_table =
CONCAT(
'Table',
sys.quote_identifier(in_db_name),
'.',
sys.quote_identifier(v_table),
'shadows base table. View cannot be created! Terminating!');
SIGNAL SQLSTATE 'HY000'
SET MESSAGE_TEXT = v_temp_table;
LEAVE c_table_names;
END IF;
SET @create_view_stmt = CONCAT(
'CREATE SQL SECURITY INVOKER VIEW ',
sys.quote_identifier(in_synonym),