diff options
Diffstat (limited to 'scripts/sys_schema')
-rw-r--r-- | scripts/sys_schema/CMakeLists.txt | 1 | ||||
-rw-r--r-- | scripts/sys_schema/procedures/create_synonym_db.sql | 20 | ||||
-rw-r--r-- | scripts/sys_schema/procedures/ps_setup_save.sql | 9 | ||||
-rw-r--r-- | scripts/sys_schema/procedures/table_exists.sql | 20 |
4 files changed, 38 insertions, 12 deletions
diff --git a/scripts/sys_schema/CMakeLists.txt b/scripts/sys_schema/CMakeLists.txt index f2f206a1a93..ccb268cc4fd 100644 --- a/scripts/sys_schema/CMakeLists.txt +++ b/scripts/sys_schema/CMakeLists.txt @@ -167,6 +167,7 @@ SET(files ${CMAKE_CURRENT_SOURCE_DIR}/after_setup.sql) ENDIF() +SET_PROPERTY(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${files}) SET(CMAKE_CONFIGURABLE_FILE_CONTENT) FOREACH(f ${files}) diff --git a/scripts/sys_schema/procedures/create_synonym_db.sql b/scripts/sys_schema/procedures/create_synonym_db.sql index 703ec9bff3b..e373a9b4ee6 100644 --- a/scripts/sys_schema/procedures/create_synonym_db.sql +++ b/scripts/sys_schema/procedures/create_synonym_db.sql @@ -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), diff --git a/scripts/sys_schema/procedures/ps_setup_save.sql b/scripts/sys_schema/procedures/ps_setup_save.sql index a5a2197e935..b7843ecd1f2 100644 --- a/scripts/sys_schema/procedures/ps_setup_save.sql +++ b/scripts/sys_schema/procedures/ps_setup_save.sql @@ -80,14 +80,11 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp_setup_instruments; DROP TEMPORARY TABLE IF EXISTS tmp_threads; - CREATE TEMPORARY TABLE tmp_setup_actors LIKE performance_schema.setup_actors; - CREATE TEMPORARY TABLE tmp_setup_consumers LIKE performance_schema.setup_consumers; - CREATE TEMPORARY TABLE tmp_setup_instruments LIKE performance_schema.setup_instruments; + CREATE TEMPORARY TABLE tmp_setup_actors AS SELECT * FROM performance_schema.setup_actors; + CREATE TEMPORARY TABLE tmp_setup_consumers AS SELECT * FROM performance_schema.setup_consumers; + CREATE TEMPORARY TABLE tmp_setup_instruments AS SELECT * FROM performance_schema.setup_instruments; CREATE TEMPORARY TABLE tmp_threads (THREAD_ID bigint unsigned NOT NULL PRIMARY KEY, INSTRUMENTED enum('YES','NO') NOT NULL); - INSERT INTO tmp_setup_actors SELECT * FROM performance_schema.setup_actors; - INSERT INTO tmp_setup_consumers SELECT * FROM performance_schema.setup_consumers; - INSERT INTO tmp_setup_instruments SELECT * FROM performance_schema.setup_instruments; INSERT INTO tmp_threads SELECT THREAD_ID, INSTRUMENTED FROM performance_schema.threads; ELSE SIGNAL SQLSTATE VALUE '90000' diff --git a/scripts/sys_schema/procedures/table_exists.sql b/scripts/sys_schema/procedures/table_exists.sql index 8a17e0e19f4..0f7640329e7 100644 --- a/scripts/sys_schema/procedures/table_exists.sql +++ b/scripts/sys_schema/procedures/table_exists.sql @@ -133,6 +133,8 @@ CREATE DEFINER='mariadb.sys'@'localhost' PROCEDURE table_exists ( CONTAINS SQL BEGIN DECLARE v_error BOOLEAN DEFAULT FALSE; + DECLARE db_quoted VARCHAR(64); + DECLARE table_quoted VARCHAR(64); DECLARE v_table_type VARCHAR(16) DEFAULT ''; DECLARE v_system_db BOOLEAN DEFAULT LOWER(in_db) IN ('information_schema', 'performance_schema'); @@ -140,19 +142,28 @@ BEGIN DECLARE CONTINUE HANDLER FOR 1146 SET v_error = TRUE; SET out_exists = ''; + SET db_quoted = sys.quote_identifier(in_db); + SET table_quoted = sys.quote_identifier(in_table); -- Verify whether the table name exists as a normal table IF (EXISTS(SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = in_db AND TABLE_NAME = in_table)) THEN -- Unfortunately the only way to determine whether there is also a temporary table is to try to create -- a temporary table with the same name. If it succeeds the table didn't exist as a temporary table. IF v_system_db = FALSE THEN - SET @sys.tmp.table_exists.SQL = CONCAT('CREATE TEMPORARY TABLE `', in_db, '`.`', in_table, '` (id INT PRIMARY KEY)'); + SET @sys.tmp.table_exists.SQL = CONCAT('CREATE TEMPORARY TABLE ', + db_quoted, + '.', + table_quoted, + '(id INT PRIMARY KEY)'); PREPARE stmt_create_table FROM @sys.tmp.table_exists.SQL; EXECUTE stmt_create_table; DEALLOCATE PREPARE stmt_create_table; -- The temporary table was created, i.e. it didn't exist. Remove it again so we don't leave garbage around. - SET @sys.tmp.table_exists.SQL = CONCAT('DROP TEMPORARY TABLE `', in_db, '`.`', in_table, '`'); + SET @sys.tmp.table_exists.SQL = CONCAT('DROP TEMPORARY TABLE ', + db_quoted, + '.', + table_quoted); PREPARE stmt_drop_table FROM @sys.tmp.table_exists.SQL; EXECUTE stmt_drop_table; DEALLOCATE PREPARE stmt_drop_table; @@ -174,7 +185,10 @@ BEGIN -- If it does it's possible to SELECT from the table without causing an error. -- If it does not exist even a PREPARE using the table will fail. IF v_system_db = FALSE THEN - SET @sys.tmp.table_exists.SQL = CONCAT('SELECT COUNT(*) FROM `', in_db, '`.`', in_table, '`'); + SET @sys.tmp.table_exists.SQL = CONCAT('SELECT COUNT(*) FROM ', + db_quoted, + '.', + table_quoted); PREPARE stmt_select FROM @sys.tmp.table_exists.SQL; IF (NOT v_error) THEN DEALLOCATE PREPARE stmt_select; |