From 0e8a19b2fa2d8c673f0a2e4a8ca0f9176f4a89cc Mon Sep 17 00:00:00 2001 From: bash <31279994+hermensbas@users.noreply.github.com> Date: Thu, 1 May 2025 01:14:51 +0200 Subject: [PATCH] check if already exist before apply (#1254) --- .../updates/db_playerbots/2025_04_26_00.sql | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/data/sql/playerbots/updates/db_playerbots/2025_04_26_00.sql b/data/sql/playerbots/updates/db_playerbots/2025_04_26_00.sql index b2a9500e..3a5fdb4c 100644 --- a/data/sql/playerbots/updates/db_playerbots/2025_04_26_00.sql +++ b/data/sql/playerbots/updates/db_playerbots/2025_04_26_00.sql @@ -1,9 +1,25 @@ --- ########################################################## --- # Playerbots RandomBots Performance Update --- # Add missing index to reduce Deadlocks --- # Author: Raz0r1337 aka St0ny --- # Date: 2025-04-26 --- ########################################################## - -ALTER TABLE `playerbots_random_bots` -ADD INDEX `idx_owner_bot_event` (`owner`, `bot`, `event`); +-- ########################################################## +-- # Playerbots RandomBots Performance Update +-- # Add missing index to reduce Deadlocks +-- # Author: Raz0r1337 aka St0ny +-- # Date: 2025-04-26 +-- ########################################################## + +-- Check if the index already exists +SET @index_exists := ( + SELECT COUNT(1) + FROM INFORMATION_SCHEMA.STATISTICS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = 'playerbots_random_bots' + AND INDEX_NAME = 'idx_owner_bot_event' +); + +-- Conditionally create the index only if it doesn't exist +SET @ddl := IF(@index_exists = 0, + 'ALTER TABLE `playerbots_random_bots` ADD INDEX `idx_owner_bot_event` (`owner`, `bot`, `event`);', + 'SELECT "Index idx_owner_bot_event already exists.";' +); + +PREPARE stmt FROM @ddl; +EXECUTE stmt; +DEALLOCATE PREPARE stmt;