Mercurial > hg > orthanc-databases
view PostgreSQL/Plugins/SQL/Upgrades/Rev2ToRev3.sql @ 595:272eeb046a88 find-refactoring
Introduced a new ChildCount table in PG to improve retrieval of NumberOfRelatedStudyInstances and other similar tags that could consume up to 95% of a request time + added a DB-Housekeeper thread to populate the new table
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 26 Nov 2024 17:59:14 +0100 |
parents | |
children |
line wrap: on
line source
-- This file contains part of the changes required to upgrade from Revision 2 to Revision 3 (DB version 6 and revision 2) -- It actually contains only the changes that: -- can not be executed with an idempotent statement in SQL -- or would polute the PrepareIndex.sql -- do facilite an up-time upgrade -- This file is executed only if the current schema is in revision 2 and it is executed -- before PrepareIndex.sql that is idempotent. -- create a new ChildrenIndex2 that is replacing ChildrenIndex. -- We create it in this partial update so it can be created while the system is up ! DO $$ DECLARE pg_version text; BEGIN SELECT version() INTO pg_version; IF substring(pg_version from 'PostgreSQL (\d+)\.')::int >= 11 THEN -- PostgreSQL 11 or later EXECUTE 'CREATE INDEX IF NOT EXISTS ChildrenIndex2 ON Resources USING btree (parentId ASC NULLS LAST) INCLUDE (publicId, internalId)'; ELSE EXECUTE 'CREATE INDEX IF NOT EXISTS ChildrenIndex2 ON Resources USING btree (parentId ASC NULLS LAST, publicId, internalId)'; END IF; END $$; DROP INDEX IF EXISTS ChildrenIndex; -- replaced by ChildrenIndex2 but no need to uninstall ChildrenIndex2 when downgrading -- other changes performed in PrepareIndex.sql: -- add ChildCount tables and triggers