From a1956948961d4e86ea799edc56a723a8aebc8752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Garc=C3=ADa=20Montoro?= Date: Thu, 8 Jun 2023 12:15:49 +0200 Subject: [PATCH] Run the UPDATE only when needed (#23228) --- server/scripts/esrupgrades/esr.5.37-7.8.mysql.up.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/scripts/esrupgrades/esr.5.37-7.8.mysql.up.sql b/server/scripts/esrupgrades/esr.5.37-7.8.mysql.up.sql index 63e5899860..2c2d271351 100644 --- a/server/scripts/esrupgrades/esr.5.37-7.8.mysql.up.sql +++ b/server/scripts/esrupgrades/esr.5.37-7.8.mysql.up.sql @@ -869,6 +869,9 @@ BEGIN DECLARE CreateIndexCreateAt BOOLEAN; DECLARE CreateIndexCreateAtQuery TEXT DEFAULT NULL; + -- Condition to control whether to update the RootId column. + DECLARE UpdateRootId BOOLEAN; + SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Posts' AND table_schema = DATABASE() @@ -909,7 +912,10 @@ BEGIN IF DropParentId THEN SET DropParentIdQuery = 'DROP COLUMN ParentId'; - UPDATE Posts SET RootId = ParentId WHERE RootId = '' AND RootId != ParentId; + SELECT COUNT(*) FROM Posts WHERE RootId != ParentId INTO UpdateRootId; + IF UpdateRootId THEN + UPDATE Posts SET RootId = ParentId WHERE RootId = '' AND RootId != ParentId; + END IF; END IF; IF ModifyFileIds THEN