From eb0f0b6c4fa14d556232011fcc133ff6b7210ae8 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 2 Oct 2023 10:27:41 +0800 Subject: [PATCH] improve data migration speed --- .../0128.do.create_index_for_foreign_key.sql | 12 ++++++++++++ .../0128.undo.create_index_for_foreign_key.sql | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 packages/db/migrations/0128.do.create_index_for_foreign_key.sql create mode 100755 packages/db/migrations/0128.undo.create_index_for_foreign_key.sql diff --git a/packages/db/migrations/0128.do.create_index_for_foreign_key.sql b/packages/db/migrations/0128.do.create_index_for_foreign_key.sql new file mode 100755 index 000000000..4ed33d1ad --- /dev/null +++ b/packages/db/migrations/0128.do.create_index_for_foreign_key.sql @@ -0,0 +1,12 @@ +-- Type: DO +-- Name: create_index_for_foreign_key +-- Description: Create index for foreign keys on entity_label and highlight tables + +BEGIN; + +CREATE INDEX IF NOT EXISTS entity_labels_library_item_id_idx ON omnivore.entity_labels(library_item_id) +CREATE INDEX IF NOT EXISTS entity_labels_highlight_id_idx ON omnivore.entity_labels(highlight_id); + +CREATE INDEX IF NOT EXISTS highlight_library_item_id_idx ON omnivore.highlight (library_item_id); + +COMMIT; diff --git a/packages/db/migrations/0128.undo.create_index_for_foreign_key.sql b/packages/db/migrations/0128.undo.create_index_for_foreign_key.sql new file mode 100755 index 000000000..34e0aba57 --- /dev/null +++ b/packages/db/migrations/0128.undo.create_index_for_foreign_key.sql @@ -0,0 +1,12 @@ +-- Type: UNDO +-- Name: create_index_for_foreign_key +-- Description: Create index for foreign keys on entity_label and highlight tables + +BEGIN; + +DROP INDEX IF EXISTS highlight_library_item_id_idx; + +DROP INDEX IF EXISTS entity_labels_highlight_id_idx; +DROP INDEX IF EXISTS entity_labels_library_item_id_idx; + +COMMIT;