MM-42919: avoid sequential scan on Posts (#19878)
On Postgres, `GetTeamsUnreadForUser` triggers a sequential scan on `Posts`. We can avoid this by querying the `Threads` table directly and only joining to `Posts` to eliminate deleted threads. (We could avoid the latter if we later denormalize `DeleteAt` onto `Threads`.) Fixes: https://mattermost.atlassian.net/browse/MM-42919
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5fee97c51c
Коммит
3016fa6010
@@ -358,12 +358,13 @@ func (s *SqlThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string)
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
repliesQuery, repliesQueryArgs, err := s.getQueryBuilder().
|
repliesQuery, repliesQueryArgs, err := s.getQueryBuilder().
|
||||||
Select("COUNT(DISTINCT(Posts.RootId)) AS Count, TeamId").
|
Select("COUNT(Threads.PostId) AS Count, TeamId").
|
||||||
From("Posts").
|
From("Threads").
|
||||||
LeftJoin("ThreadMemberships ON Posts.RootId = ThreadMemberships.PostId").
|
LeftJoin("ThreadMemberships ON Threads.PostId = ThreadMemberships.PostId").
|
||||||
LeftJoin("Channels ON Posts.ChannelId = Channels.Id").
|
LeftJoin("Channels ON Threads.ChannelId = Channels.Id").
|
||||||
|
LeftJoin("Posts ON Posts.Id = Threads.PostId").
|
||||||
Where(fetchConditions).
|
Where(fetchConditions).
|
||||||
Where("Posts.CreateAt > ThreadMemberships.LastViewed").
|
Where("Threads.LastReplyAt > ThreadMemberships.LastViewed").
|
||||||
GroupBy("Channels.TeamId").
|
GroupBy("Channels.TeamId").
|
||||||
ToSql()
|
ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user