Skip to content

Commit

Permalink
Optimise indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Nov 26, 2024
1 parent d79e4ff commit 9859271
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions thoth-api/migrations/v0.13.1/down.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ DROP INDEX IF EXISTS idx_account_email;
DROP INDEX IF EXISTS idx_publisher_account_account_id;

-- Remove indexes from work table
DROP INDEX IF EXISTS idx_work_work_id;
DROP INDEX IF EXISTS idx_work_doi;
DROP INDEX IF EXISTS idx_work_reference;
DROP INDEX IF EXISTS idx_work_short_abstract_substr;
Expand All @@ -16,24 +15,25 @@ DROP INDEX IF EXISTS idx_work_updated_at_with_relations_desc;
DROP INDEX IF EXISTS idx_work_full_title_asc;
DROP INDEX IF EXISTS idx_work_publication_date_asc;
DROP INDEX IF EXISTS idx_work_publication_date_desc;
DROP INDEX IF EXISTS idx_work_type_status_pub_date_desc;
DROP INDEX IF EXISTS idx_work_books_pub_date_desc;

-- Remove indexes from work_relation table
DROP INDEX IF EXISTS idx_work_relation_relation_ordinal_relator_asc;
DROP INDEX IF EXISTS idx_work_relation_relation_ordinal_related_asc;
DROP INDEX IF EXISTS idx_work_relation_relation_ordinal_relator_relation_type_asc;
DROP INDEX IF EXISTS idx_work_relation_relation_ordinal_related_relation_type_asc;

-- Remove indexes from publisher table
DROP INDEX IF EXISTS idx_publisher_publisher_id;
DROP INDEX IF EXISTS idx_publisher_publisher_name;
DROP INDEX IF EXISTS idx_publisher_publisher_shortname;

-- Remove indexes from imprint table
DROP INDEX IF EXISTS idx_imprint_id;
DROP INDEX IF EXISTS idx_imprint_imprint_name;
DROP INDEX IF EXISTS idx_imprint_imprint_url;
DROP INDEX IF EXISTS idx_imprint_publisher_id;

-- Remove indexes from subject table
DROP INDEX IF EXISTS idx_subject_subject_code_asc;
DROP INDEX IF EXISTS idx_subject_subject_ordinal_asc;

-- Remove indexes from publication table
DROP INDEX IF EXISTS idx_publication_work_id;
Expand Down
17 changes: 11 additions & 6 deletions thoth-api/migrations/v0.13.1/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
CREATE INDEX idx_account_email ON account (email);

-- Indexes publisher_account table
CREATE INDEX idx_publisher_account_account_id ON publisher_account (account_id);
CREATE INDEX ON publisher_account (account_id);

-- Indexes work table
CREATE INDEX idx_work_work_id ON work (work_id);
CREATE INDEX idx_work_doi ON work (doi);
CREATE INDEX idx_work_reference ON work (reference);
CREATE INDEX idx_work_short_abstract_substr ON work (substring(short_abstract FROM 1 FOR 255));
Expand All @@ -16,24 +15,30 @@ CREATE INDEX idx_work_updated_at_with_relations_desc ON work (updated_at_with_re
CREATE INDEX idx_work_full_title_asc ON work (full_title ASC, work_id);
CREATE INDEX idx_work_publication_date_asc ON work (publication_date ASC, work_id);
CREATE INDEX idx_work_publication_date_desc ON work (publication_date DESC, work_id);
CREATE INDEX idx_work_type_status_pub_date_desc
ON work (work_type, work_status, publication_date DESC);
CREATE INDEX idx_work_books_pub_date_desc
ON work (publication_date DESC)
WHERE work_type IN ('monograph', 'edited-book', 'textbook') AND work_status = 'active';

-- Indexes work_relation table
CREATE INDEX idx_work_relation_relation_ordinal_relator_asc ON work_relation (relation_ordinal ASC, relator_work_id);
CREATE INDEX idx_work_relation_relation_ordinal_related_asc ON work_relation (relation_ordinal ASC, related_work_id);
CREATE INDEX idx_work_relation_relation_ordinal_relator_relation_type_asc
ON work_relation (relation_ordinal ASC, relator_work_id, relation_type);
CREATE INDEX idx_work_relation_relation_ordinal_related_relation_type_asc
ON work_relation (relation_ordinal ASC, related_work_id, relation_type);

-- Indexes publisher table
CREATE INDEX idx_publisher_publisher_id ON publisher (publisher_id);
CREATE INDEX idx_publisher_publisher_name ON publisher (publisher_name);
CREATE INDEX idx_publisher_publisher_shortname ON publisher (publisher_shortname);

-- Indexes imprint table
CREATE INDEX idx_imprint_id ON imprint (imprint_id);
CREATE INDEX idx_imprint_imprint_name ON imprint (imprint_name);
CREATE INDEX idx_imprint_imprint_url ON imprint (imprint_url);
CREATE INDEX idx_imprint_publisher_id ON imprint (publisher_id);

-- Indexes subject table
CREATE INDEX idx_subject_subject_code_asc ON subject (subject_code ASC, work_id);
CREATE INDEX idx_subject_subject_ordinal_asc ON subject (subject_ordinal ASC, work_id);

-- Indexes publication table
CREATE INDEX idx_publication_work_id ON publication (work_id);
Expand Down

0 comments on commit 9859271

Please sign in to comment.