From a74b415dc62faa2b761e5725a0e98694c1983b9c Mon Sep 17 00:00:00 2001 From: dbs Date: Fri, 4 Jun 2010 03:54:14 +0000 Subject: [PATCH] Improve circ transaction performance by indexing NULL circs (Launchpad 587031) Creating a unique index on target_copy in the action.circulation table where the checkin_time is NULL will increase the speed of circ transactions, particularly on systems with a lot of traffic. The uniqueness also ensures that a given item will not be able to be checked out multiple times concurrently. Thanks to James Fournie from BC Sitka for suggesting the index in Launchpad bug 587031! git-svn-id: svn://svn.open-ils.org/ILS/trunk@16589 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/090.schema.action.sql | 2 +- Open-ILS/src/sql/Pg/upgrade/0292.schema.action-target_copy-index.sql | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0292.schema.action-target_copy-index.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 3a93091b87..15b9afbdcf 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -65,7 +65,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0291'); -- dbs +INSERT INTO config.upgrade_log (version) VALUES ('0292'); -- dbs CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index 8914d8779e..f575055340 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -147,7 +147,7 @@ CREATE INDEX circ_all_usr_idx ON action.circulation ( usr ); CREATE INDEX circ_circ_staff_idx ON action.circulation ( circ_staff ); CREATE INDEX circ_checkin_staff_idx ON action.circulation ( checkin_staff ); CREATE UNIQUE INDEX circ_parent_idx ON action.circulation ( parent_circ ) WHERE parent_circ IS NOT NULL; - +CREATE UNIQUE INDEX only_one_concurrent_checkout_per_copy ON action.circulation(target_copy) WHERE checkin_time IS NULL; CREATE TRIGGER mat_summary_create_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_create ('circulation'); CREATE TRIGGER mat_summary_change_tgr AFTER UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE money.mat_summary_update (); diff --git a/Open-ILS/src/sql/Pg/upgrade/0292.schema.action-target_copy-index.sql b/Open-ILS/src/sql/Pg/upgrade/0292.schema.action-target_copy-index.sql new file mode 100644 index 0000000000..054ee56da9 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0292.schema.action-target_copy-index.sql @@ -0,0 +1,4 @@ +BEGIN; +INSERT INTO config.upgrade_log (version) VALUES ('0292'); -- dbs +CREATE UNIQUE INDEX only_one_concurrent_checkout_per_copy ON action.circulation(target_copy) WHERE checkin_time IS NULL; +COMMIT; -- 2.11.0