diff PostgreSQL/Plugins/SQL/PrepareIndex.sql @ 572:6667bd31beaf find-refactoring

ReadOnly mode continued
author Alain Mazy <am@orthanc.team>
date Thu, 26 Sep 2024 17:24:29 +0200
parents 11c6bcc9d1f2
children
line wrap: on
line diff
--- a/PostgreSQL/Plugins/SQL/PrepareIndex.sql	Mon Sep 23 16:06:53 2024 +0200
+++ b/PostgreSQL/Plugins/SQL/PrepareIndex.sql	Thu Sep 26 17:24:29 2024 +0200
@@ -545,7 +545,28 @@
         PERFORM PatientAddedOrUpdated(patient_internal_id, 1);
     END IF;  
 END;
+$body$ LANGUAGE plpgsql;
 
+-- function to compute a statistic in a ReadOnly transaction
+CREATE OR REPLACE FUNCTION ComputeStatisticsReadOnly(
+    IN statistics_key INTEGER,
+    OUT accumulated_value BIGINT
+) RETURNS BIGINT AS $body$
+
+DECLARE
+    current_value BIGINT;
+    
+BEGIN
+
+    SELECT VALUE from GlobalIntegers
+    INTO current_value
+    WHERE key = statistics_key;
+
+    SELECT sum(value) + current_value FROM GlobalIntegersChanges
+    INTO accumulated_value
+    WHERE key = statistics_key;
+
+END;
 $body$ LANGUAGE plpgsql;
 
 
@@ -559,3 +580,4 @@
 INSERT INTO GlobalProperties VALUES (11, 3); -- GlobalProperty_HasCreateInstance  -- this is actually the 3rd version of HasCreateInstance
 INSERT INTO GlobalProperties VALUES (12, 1); -- GlobalProperty_HasFastCountResources
 INSERT INTO GlobalProperties VALUES (13, 1); -- GlobalProperty_GetLastChangeIndex
+INSERT INTO GlobalProperties VALUES (14, 1); -- GlobalProperty_HasComputeStatisticsReadOnly