mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
messages: Add new conditional versions of subject indexes.
Indexes on topic ("subject") are polluted by the existence of DMs,
which all have empty topics, and as such skew the statistics greatly.
This is particularly important given the new use of the empty topic
for the "general chat" function -- left as-is, the database makes bad
query plans because it believes the topic is vastly more common than
it actually is.
We move the old indexes to a new name with `_all`, and
recreate (concurrently) the same indexes but with a condition on
is_channel_message. These new indexes are unused at current, until
the query-building logic adds limits on is_channel_message; see the
following commit.
This commit is contained in:
committed by
Tim Abbott
parent
eba1c3afd4
commit
33e1d583bf
@@ -205,6 +205,29 @@ class Message(AbstractMessage):
|
||||
"date_sent",
|
||||
name="zerver_message_realm_date_sent",
|
||||
),
|
||||
models.Index(
|
||||
# To be removed shortly
|
||||
"realm_id",
|
||||
Upper("subject"),
|
||||
F("id").desc(nulls_last=True),
|
||||
name="zerver_message_realm_upper_subject_all",
|
||||
),
|
||||
models.Index(
|
||||
# To be removed shortly
|
||||
"realm_id",
|
||||
"recipient_id",
|
||||
Upper("subject"),
|
||||
F("id").desc(nulls_last=True),
|
||||
name="zerver_message_realm_recipient_upper_subject_all",
|
||||
),
|
||||
models.Index(
|
||||
# To be removed shortly
|
||||
"realm_id",
|
||||
"recipient_id",
|
||||
"subject",
|
||||
F("id").desc(nulls_last=True),
|
||||
name="zerver_message_realm_recipient_subject_all",
|
||||
),
|
||||
models.Index(
|
||||
# For users searching by topic (but not stream), which
|
||||
# is done case-insensitively
|
||||
@@ -212,6 +235,7 @@ class Message(AbstractMessage):
|
||||
Upper("subject"),
|
||||
F("id").desc(nulls_last=True),
|
||||
name="zerver_message_realm_upper_subject",
|
||||
condition=Q(is_channel_message=True),
|
||||
),
|
||||
models.Index(
|
||||
# Most stream/topic searches are case-insensitive by
|
||||
@@ -223,6 +247,7 @@ class Message(AbstractMessage):
|
||||
Upper("subject"),
|
||||
F("id").desc(nulls_last=True),
|
||||
name="zerver_message_realm_recipient_upper_subject",
|
||||
condition=Q(is_channel_message=True),
|
||||
),
|
||||
models.Index(
|
||||
# Used by already_sent_mirrored_message_id, and when
|
||||
@@ -233,6 +258,7 @@ class Message(AbstractMessage):
|
||||
"subject",
|
||||
F("id").desc(nulls_last=True),
|
||||
name="zerver_message_realm_recipient_subject",
|
||||
condition=Q(is_channel_message=True),
|
||||
),
|
||||
models.Index(
|
||||
# Only used by update_first_visible_message_id
|
||||
|
||||
Reference in New Issue
Block a user