mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-23 23:29:31 -04:00
* MM-45956: Optimize FileInfo stats query We Denormalize Post.ChannelId on FileInfo.ChannelId ```release-note The file info stats query is now optimized by denormalizing the channelID column into the table itself. This will speed up the query to get the file count for a channel on clicking the RHS. Migration times: On a MySQL 8.0.31 DB with 1405 rows in FileInfo and 11M posts, it took around 0.3s On a Postgres 12.14 DB with 1731 rows in FileInfo and 11M posts, it took around 0.27s ``` https://mattermost.atlassian.net/browse/MM-45956
3 lines
288 B
SQL
3 lines
288 B
SQL
ALTER TABLE fileinfo ADD COLUMN IF NOT EXISTS channelid varchar(26);
|
|
UPDATE fileinfo SET channelid = posts.channelid FROM posts WHERE fileinfo.channelid IS NULL AND fileinfo.postid = posts.id;
|
|
CREATE INDEX IF NOT EXISTS idx_fileinfo_channel_id_create_at ON fileinfo(channelid, createat);
|