]> granicus.if.org Git - icinga2/commitdiff
ido: Drop unused instance_id indices from comments, downtimes and their related histo...
authorEric Lippmann <eric.lippmann@netways.de>
Thu, 26 Oct 2017 11:59:37 +0000 (13:59 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 7 Nov 2017 15:37:12 +0000 (16:37 +0100)
lib/db_ido_mysql/schema/upgrade/2.8.0.sql
lib/db_ido_pgsql/schema/upgrade/2.8.0.sql

index 5fed9831258efca725490d22da1823094df5ed9d..db546d00725060c4edc6241b413f0ae1e805b15e 100644 (file)
@@ -9,6 +9,58 @@
 
 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
 
+-- --------------------------------------------------------
+-- Helper functions and procedures for DROP INDEX IF EXISTS
+-- --------------------------------------------------------
+
+DELIMITER //
+DROP FUNCTION IF EXISTS ido_index_exists //
+CREATE FUNCTION ido_index_exists(
+  f_table_name varchar(64),
+  f_index_name varchar(64)
+)
+  RETURNS BOOL
+  DETERMINISTIC
+  READS SQL DATA
+  BEGIN
+    DECLARE index_exists BOOL DEFAULT FALSE;
+    SELECT EXISTS (
+        SELECT 1
+        FROM information_schema.statistics
+        WHERE table_schema = SCHEMA()
+              AND table_name = f_table_name
+              AND index_name = f_index_name
+    ) INTO index_exists;
+    RETURN index_exists;
+  END //
+
+DROP PROCEDURE IF EXISTS ido_drop_index_if_exists //
+CREATE PROCEDURE ido_drop_index_if_exists (
+  IN p_table_name varchar(64),
+  IN p_index_name varchar(64)
+)
+  DETERMINISTIC
+  MODIFIES SQL DATA
+  BEGIN
+    IF ido_index_exists(p_table_name, p_index_name)
+    THEN
+      SET @ido_drop_index_sql = CONCAT('ALTER TABLE `', SCHEMA(), '`.`', p_table_name, '` DROP INDEX `', p_index_name, '`');
+      PREPARE stmt FROM @ido_drop_index_sql;
+      EXECUTE stmt;
+      DEALLOCATE PREPARE stmt;
+      SET @ido_drop_index_sql = NULL;
+    END IF;
+  END //
+DELIMITER ;
+
+CALL ido_drop_index_if_exists('icinga_downtimehistory', 'instance_id');
+CALL ido_drop_index_if_exists('icinga_scheduleddowntime', 'instance_id');
+CALL ido_drop_index_if_exists('icinga_commenthistory', 'instance_id');
+CALL ido_drop_index_if_exists('icinga_comments', 'instance_id');
+
+DROP FUNCTION ido_index_exists;
+DROP PROCEDURE ido_drop_index_if_exists;
+
 -- -----------------------------------------
 -- #5458 IDO: Improve downtime removal/cancel
 -- -----------------------------------------
index 8e49f17ebb885e1f954901ee2ff4f28eb7e4b2bc..cae9b66999619861e32c857387d772f4cbfd6c3c 100644 (file)
@@ -7,6 +7,11 @@
 -- Please check https://docs.icinga.com for upgrading information!
 -- -----------------------------------------
 
+ALTER TABLE icinga_downtimehistory DROP CONSTRAINT IF EXISTS UQ_downtimehistory;
+ALTER TABLE icinga_scheduleddowntime DROP CONSTRAINT IF EXISTS UQ_scheduleddowntime;
+ALTER TABLE icinga_commenthistory DROP CONSTRAINT IF EXISTS UQ_commenthistory;
+ALTER TABLE icinga_comments DROP CONSTRAINT IF EXISTS UQ_comments;
+
 -- -----------------------------------------
 -- #5458 IDO: Improve downtime removal/cancel
 -- -----------------------------------------