From 334b199e7af42f14c048f50f70441c4d4f336796 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 3 Aug 2022 10:31:18 +0530 Subject: [PATCH] Optimize AnalyticsPostCount (#20727) We use * instead of a column name to use index-only scan always even when other column filters are applied. Right now, index-only scan will only get applied in the basic query of "select count(p.id) as value from posts p". But it won't get applied if the query is "select count(p.id) as value from posts p where p.deleteat=0". So this is a minor optimization which improves some corner cases. This was found from the slow query monitoring. ```release-note NONE ``` --- store/sqlstore/post_store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index 3659708401..a2e8c228e7 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -2195,7 +2195,7 @@ func (s *SqlPostStore) AnalyticsPostCountsByDay(options *model.AnalyticsPostCoun func (s *SqlPostStore) AnalyticsPostCount(options *model.PostCountOptions) (int64, error) { query := s.getQueryBuilder(). - Select("COUNT(p.Id) AS Value"). + Select("COUNT(*) AS Value"). From("Posts p") if options.TeamId != "" {