MM-70511: Optimize FileInfo and Channels bulk-indexing queries (#38206)

* Add (CreateAt, Id) indices on FileInfo, Channels

* Optimize FileInfo and Channels indexing queries

* make generated

* Update expected indices in the Channels table

* Remove indices

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Alejandro García Montoro
2026-09-08 11:56:56 +00:00
committed by GitHub
co-authored by Mattermost Build
parent 0d79d72074
commit a66e9c034b
2 changed files with 2 additions and 14 deletions
@@ -4451,13 +4451,7 @@ func (s SqlChannelStore) GetChannelsBatchForIndexing(startTime int64, startChann
query := s.getQueryBuilder().
Select(channelSliceColumns(false)...).
From("Channels").
Where(sq.Or{
sq.Gt{"CreateAt": startTime},
sq.And{
sq.Eq{"CreateAt": startTime},
sq.Gt{"Id": startChannelID},
},
}).
Where("(CreateAt, Id) > (?, ?)", startTime, startChannelID).
Where(sq.Eq{"Type": messageChannelTypes}).
OrderBy("CreateAt ASC", "Id ASC").
Limit(uint64(limit))
@@ -714,13 +714,7 @@ func (fs SqlFileInfoStore) GetFilesBatchForIndexing(startTime int64, startFileID
query := fs.getQueryBuilder().
Select(fs.queryFields...).
From("FileInfo").
Where(sq.Or{
sq.Gt{"FileInfo.CreateAt": startTime},
sq.And{
sq.Eq{"FileInfo.CreateAt": startTime},
sq.Gt{"FileInfo.Id": startFileID},
},
}).
Where("(FileInfo.CreateAt, FileInfo.Id) > (?, ?)", startTime, startFileID).
OrderBy("FileInfo.CreateAt ASC, FileInfo.Id ASC").
Limit(uint64(limit))