From 0797e8233ea2a09d376f4c9654bee772bf0663dc Mon Sep 17 00:00:00 2001 From: Mark Davies Date: Wed, 3 Dec 2014 15:49:01 +0000 Subject: [PATCH] First batch of database indexes Added in support of Issue #31, Database Performance Improvements. Note creation of 1.2.12 db patch script - may need renaming or other special treatment when merging this branch. --- dba/davical.sql | 11 ++++++++--- dba/patches/1.2.12.sql | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 dba/patches/1.2.12.sql diff --git a/dba/davical.sql b/dba/davical.sql index e1f28097..20f5b7e1 100644 --- a/dba/davical.sql +++ b/dba/davical.sql @@ -115,8 +115,9 @@ CREATE TABLE collection ( description TEXT DEFAULT '', UNIQUE(user_no,dav_name) ); - ALTER TABLE collection ADD CONSTRAINT unique_path UNIQUE (dav_name); +CREATE INDEX collection_dav_name_idx ON collection (dav_name); + -- The main event. Where we store the things the calendar throws at us. CREATE TABLE caldav_data ( @@ -135,6 +136,8 @@ CREATE TABLE caldav_data ( PRIMARY KEY ( user_no, dav_name ) ); CREATE INDEX caldav_data_collection_id_fkey ON caldav_data(collection_id); +CREATE INDEX caldav_data_dav_name_idx ON caldav_data (dav_name); + -- The parsed calendar item. Here we have pulled those events/todos/journals apart somewhat. CREATE TABLE calendar_item ( @@ -175,7 +178,7 @@ CREATE TABLE calendar_item ( PRIMARY KEY ( user_no, dav_name ) ); CREATE INDEX calendar_item_collection_id_fkey ON calendar_item(collection_id); - +CREATE INDEX calendar_item_dav_name_idx ON calendar_item (dav_name); -- Each user can be related to each other user. This mechanism can also @@ -311,6 +314,8 @@ CREATE TABLE sync_tokens ( collection_id INT8 REFERENCES collection(collection_id) ON DELETE CASCADE ON UPDATE CASCADE, modification_time TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp ); +CREATE INDEX sync_tokens_collection_idx ON sync_tokens (collection_id); + CREATE TABLE sync_changes ( sync_time TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp, @@ -444,4 +449,4 @@ $$ LANGUAGE plpgsql ; ALTER TABLE dav_binding ADD CONSTRAINT "dav_name_does_not_exist" CHECK (NOT real_path_exists(dav_name)); -SELECT new_db_revision(1,2,11, 'Novembre' ); +SELECT new_db_revision(1,2,12, 'Decembre' ); diff --git a/dba/patches/1.2.12.sql b/dba/patches/1.2.12.sql new file mode 100644 index 00000000..dd222e91 --- /dev/null +++ b/dba/patches/1.2.12.sql @@ -0,0 +1,22 @@ + +-- Apply database indexes in support of Issue #31 Database performance improvements + +BEGIN; +SELECT check_db_revision(1,2,11); + +-- These two indexes improves performance of the stored function write_sync_change(), which is called on every calendar item update +CREATE INDEX sync_tokens_collection_idx ON sync_tokens (collection_id); +CREATE INDEX caldav_data_dav_name_idx ON caldav_data (dav_name); + +-- Improves performance of the stored function sync_dav_id(), which is called via a trigger on any insert or update on caldav_data +CREATE INDEX calendar_item_dav_name_idx ON calendar_item (dav_name); + +-- Speeds up construction of CalDAVRequest, in particular when DaviCAL attempts to determine the "correct" URL for a calendar collection +CREATE INDEX collection_dav_name_idx ON collection (dav_name); + + +SELECT new_db_revision(1,2,12, 'Decembre' ); + +COMMIT; +ROLLBACK; +