mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-03 11:43:51 +00:00
Optimizing a few more combined migrations (#5821)
* Add indexes after insert to search_combined. * Add indexes after for inbox_combined. * Move index after for modlog combined. * Fixing unique.
This commit is contained in:
parent
99ec0b7116
commit
7e55a39677
3 changed files with 15 additions and 15 deletions
|
@ -74,8 +74,6 @@ CREATE TABLE modlog_combined (
|
|||
mod_transfer_community_id int UNIQUE REFERENCES mod_transfer_community ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_modlog_combined_published ON modlog_combined (published DESC, id DESC);
|
||||
|
||||
-- Updating the history
|
||||
-- Not doing a union all here, because there's way too many null columns
|
||||
INSERT INTO modlog_combined (published, admin_allow_instance_id)
|
||||
|
@ -197,6 +195,8 @@ SELECT
|
|||
FROM
|
||||
mod_transfer_community;
|
||||
|
||||
CREATE INDEX idx_modlog_combined_published ON modlog_combined (published DESC, id DESC);
|
||||
|
||||
-- Make sure only one of the columns is not null
|
||||
ALTER TABLE modlog_combined
|
||||
ADD CONSTRAINT modlog_combined_check CHECK (num_nonnulls (admin_allow_instance_id, admin_block_instance_id, admin_purge_comment_id, admin_purge_community_id, admin_purge_person_id, admin_purge_post_id, mod_add_id, mod_add_community_id, mod_ban_id, mod_ban_from_community_id, mod_feature_post_id, mod_hide_community_id, mod_lock_post_id, mod_remove_comment_id, mod_remove_community_id, mod_remove_post_id, mod_transfer_community_id) = 1),
|
||||
|
|
|
@ -10,8 +10,7 @@ CREATE TABLE person_post_mention (
|
|||
recipient_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE NOT NULL,
|
||||
post_id int REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE NOT NULL,
|
||||
read boolean DEFAULT FALSE NOT NULL,
|
||||
published timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (recipient_id, post_id)
|
||||
published timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE inbox_combined (
|
||||
|
@ -23,10 +22,6 @@ CREATE TABLE inbox_combined (
|
|||
private_message_id int UNIQUE REFERENCES private_message ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_inbox_combined_published ON inbox_combined (published DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_inbox_combined_published_asc ON inbox_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
||||
|
||||
-- Updating the history
|
||||
INSERT INTO inbox_combined (published, comment_reply_id, person_comment_mention_id, person_post_mention_id, private_message_id)
|
||||
SELECT
|
||||
|
@ -65,9 +60,14 @@ SELECT
|
|||
FROM
|
||||
private_message;
|
||||
|
||||
CREATE INDEX idx_inbox_combined_published ON inbox_combined (published DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_inbox_combined_published_asc ON inbox_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
||||
|
||||
ALTER TABLE person_post_mention
|
||||
ALTER CONSTRAINT person_post_mention_recipient_id_fkey NOT DEFERRABLE,
|
||||
ALTER CONSTRAINT person_post_mention_post_id_fkey NOT DEFERRABLE;
|
||||
ALTER CONSTRAINT person_post_mention_post_id_fkey NOT DEFERRABLE,
|
||||
ADD CONSTRAINT person_post_mention_unique UNIQUE (recipient_id, post_id);
|
||||
|
||||
-- Make sure only one of the columns is not null
|
||||
ALTER TABLE inbox_combined
|
||||
|
|
|
@ -15,12 +15,6 @@ CREATE TABLE search_combined (
|
|||
person_id int UNIQUE REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_search_combined_published ON search_combined (published DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_search_combined_published_asc ON search_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_search_combined_score ON search_combined (score DESC, id DESC);
|
||||
|
||||
-- Add published to person_aggregates (it was missing for some reason)
|
||||
ALTER TABLE person_aggregates
|
||||
ADD COLUMN published timestamptz NOT NULL DEFAULT now();
|
||||
|
@ -76,6 +70,12 @@ SELECT
|
|||
FROM
|
||||
person_aggregates;
|
||||
|
||||
CREATE INDEX idx_search_combined_published ON search_combined (published DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_search_combined_published_asc ON search_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_search_combined_score ON search_combined (score DESC, id DESC);
|
||||
|
||||
-- Make sure only one of the columns is not null
|
||||
ALTER TABLE search_combined
|
||||
ADD CONSTRAINT search_combined_check CHECK (num_nonnulls (post_id, comment_id, community_id, person_id) = 1),
|
||||
|
|
Loading…
Reference in a new issue