changeset 7166:b55d4257f8e0

add UNIQUE to PublicIndex + added a new AttachedFilesUuid index
author Alain Mazy <am@orthanc.team>
date Wed, 07 Oct 2026 16:10:07 +0200
parents 6d0f6a686b71
children adb7b4290ab3
files NEWS OrthancServer/CMakeLists.txt OrthancServer/Sources/Database/InstallAttachedFilesUuidIndex.sql OrthancServer/Sources/Database/MakePublicIndexUnique.sql OrthancServer/Sources/Database/PrepareDatabase.sql OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/ServerEnumerations.h
diffstat 7 files changed, 74 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Sep 30 14:58:05 2026 +0200
+++ b/NEWS	Wed Oct 07 16:10:07 2026 +0200
@@ -8,6 +8,8 @@
   - Optimized some queries to access single resources.
   - Optimized many queries thanks to improved query planning.  An Optimization step can
     sometimes run at startup which slows down the Orthanc startup.
+  - Added/updated 2 indexes: the first startup with this version migth be slower to rebuild
+    these indexes.
 
 Plugin SDK
 ----------
--- a/OrthancServer/CMakeLists.txt	Wed Sep 30 14:58:05 2026 +0200
+++ b/OrthancServer/CMakeLists.txt	Wed Oct 07 16:10:07 2026 +0200
@@ -277,6 +277,8 @@
   INSTALL_KEY_VALUE_STORES_AND_QUEUES ${CMAKE_SOURCE_DIR}/Sources/Database/InstallKeyValueStoresAndQueues.sql
   ADD_TIMEOUT_TO_QUEUES             ${CMAKE_SOURCE_DIR}/Sources/Database/AddTimeoutToQueues.sql
   INSTALL_DICOM_IDENTIFIERS_INDEX_3 ${CMAKE_SOURCE_DIR}/Sources/Database/InstallDicomIdentifiersIndex3.sql
+  MAKE_PUBLIC_INDEX_UNIQUE          ${CMAKE_SOURCE_DIR}/Sources/Database/MakePublicIndexUnique.sql
+  INSTALL_ATTACHED_FILES_UUID_INDEX ${CMAKE_SOURCE_DIR}/Sources/Database/InstallAttachedFilesUuidIndex.sql
   )
 
 if (STANDALONE_BUILD)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Sources/Database/InstallAttachedFilesUuidIndex.sql	Wed Oct 07 16:10:07 2026 +0200
@@ -0,0 +1,22 @@
+-- Orthanc - A Lightweight, RESTful DICOM Store
+-- Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+-- Department, University Hospital of Liege, Belgium
+-- Copyright (C) 2017-2023 Osimis S.A., Belgium
+-- Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+-- Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+--
+-- This program is free software: you can redistribute it and/or
+-- modify it under the terms of the GNU General Public License as
+-- published by the Free Software Foundation, either version 3 of the
+-- License, or (at your option) any later version.
+-- 
+-- This program is distributed in the hope that it will be useful, but
+-- WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+CREATE UNIQUE INDEX AttachedFilesUuidIndex ON AttachedFiles(uuid)
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Sources/Database/MakePublicIndexUnique.sql	Wed Oct 07 16:10:07 2026 +0200
@@ -0,0 +1,27 @@
+-- Orthanc - A Lightweight, RESTful DICOM Store
+-- Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+-- Department, University Hospital of Liege, Belgium
+-- Copyright (C) 2017-2023 Osimis S.A., Belgium
+-- Copyright (C) 2024-2026 Orthanc Team SRL, Belgium
+-- Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+--
+-- This program is free software: you can redistribute it and/or
+-- modify it under the terms of the GNU General Public License as
+-- published by the Free Software Foundation, either version 3 of the
+-- License, or (at your option) any later version.
+-- 
+-- This program is distributed in the hope that it will be useful, but
+-- WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+-- this script add the "unique" constrain to the PublicIndex
+DROP INDEX PublicIndex;
+CREATE UNIQUE INDEX PublicIndex ON Resources(publicId);
+
+-- Record that this upgrade has been performed
+
+INSERT INTO GlobalProperties VALUES (8, 1);  -- GlobalProperty_SQLiteIsPublicIndexUnique
--- a/OrthancServer/Sources/Database/PrepareDatabase.sql	Wed Sep 30 14:58:05 2026 +0200
+++ b/OrthancServer/Sources/Database/PrepareDatabase.sql	Wed Oct 07 16:10:07 2026 +0200
@@ -99,7 +99,7 @@
        );
 
 CREATE INDEX ChildrenIndex ON Resources(parentId);
-CREATE INDEX PublicIndex ON Resources(publicId);
+CREATE UNIQUE INDEX PublicIndex ON Resources(publicId);  -- unique since 1.13.1
 CREATE INDEX ResourceTypeIndex ON Resources(resourceType);
 CREATE INDEX PatientRecyclingIndex ON PatientRecyclingOrder(patientId);
 
@@ -156,11 +156,14 @@
 ${ADD_TIMEOUT_TO_QUEUES}              -- equivalent to AddTimeoutToQueues.sql
 ${INSTALL_DICOM_IDENTIFIERS_INDEX_3}  -- equivalent to InstallDicomIdentifiersIndex3.sql
 
+-- new in Orthanc 1.13.1 ------------------------ index on AttachedFiles.publicId
+${INSTALL_ATTACHED_FILES_UUID_INDEX}  -- equivalent to InstallAttachedFilesPublicIndex.sql
 
 -- Track the fact that the "revision" column exists in the "Metadata" and "AttachedFiles"
 -- tables, and that the "customData" column exists in the "AttachedFiles" table
 INSERT INTO GlobalProperties VALUES (7, 1);  -- GlobalProperty_SQLiteHasCustomDataAndRevision
 
+INSERT INTO GlobalProperties VALUES (8, 1);  -- GlobalProperty_SQLiteIsPublicIndexUnique
 
 -- Set the version of the database schema
 -- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Wed Sep 30 14:58:05 2026 +0200
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Wed Oct 07 16:10:07 2026 +0200
@@ -2812,6 +2812,7 @@
         InjectEmbeddedScript(query, "${INSTALL_KEY_VALUE_STORES_AND_QUEUES}", ServerResources::INSTALL_KEY_VALUE_STORES_AND_QUEUES);
         InjectEmbeddedScript(query, "${ADD_TIMEOUT_TO_QUEUES}", ServerResources::ADD_TIMEOUT_TO_QUEUES);
         InjectEmbeddedScript(query, "${INSTALL_DICOM_IDENTIFIERS_INDEX_3}", ServerResources::INSTALL_DICOM_IDENTIFIERS_INDEX_3);
+        InjectEmbeddedScript(query, "${INSTALL_ATTACHED_FILES_UUID_INDEX}", ServerResources::INSTALL_ATTACHED_FILES_UUID_INDEX);
 
         db_.Execute(query);
       }
@@ -2884,6 +2885,21 @@
           ExecuteEmbeddedScript(db_, ServerResources::ADD_TIMEOUT_TO_QUEUES);
         }
 
+        // New in Orthanc 1.13.1
+        if (!transaction->LookupGlobalProperty(tmp, GlobalProperty_SQLiteIsPublicIndexUnique, true /* unused in SQLite */)
+            || tmp != "1")
+        {
+          LOG(INFO) << "Upgrading SQLite schema to make PublicIndex unique";
+          ExecuteEmbeddedScript(db_, ServerResources::MAKE_PUBLIC_INDEX_UNIQUE);
+        }
+
+        // New in Orthanc 1.13.1
+        if (!db_.DoesIndexExist("AttachedFilesUuidIndex"))
+        {
+          LOG(INFO) << "Installing the \"AttachedFilesUuidIndex\" index";
+          ExecuteEmbeddedScript(db_, ServerResources::INSTALL_ATTACHED_FILES_UUID_INDEX);
+        }
+
         // New in Orthanc 1.13.1 run optimize at each startup, provided there are enough data to perform a relevant analysis
         Optimize(false);
       }
--- a/OrthancServer/Sources/ServerEnumerations.h	Wed Sep 30 14:58:05 2026 +0200
+++ b/OrthancServer/Sources/ServerEnumerations.h	Wed Oct 07 16:10:07 2026 +0200
@@ -175,6 +175,7 @@
     GlobalProperty_JobsRegistry = 5,
     GlobalProperty_GetTotalSizeIsFast = 6,      // New in Orthanc 1.5.2
     GlobalProperty_SQLiteHasRevisionAndCustomData = 7,     // New in Orthanc 1.12.8
+    GlobalProperty_SQLiteIsPublicIndexUnique = 8,          // New in Orthanc 1.13.1
     GlobalProperty_Modalities = 20,             // New in Orthanc 1.5.0
     GlobalProperty_Peers = 21,                  // New in Orthanc 1.5.0