500 is raised on pipelines/charts due to query timeout

Summary

/gitlab-org/gitlab-ce/pipelines/charts pages causes 500 to be raised due to

ActiveRecord::QueryCanceled: PG::QueryCanceled: ERROR: canceling statement due to statement timeout :

SELECT COUNT("ci_pipelines"."created_at") AS count_created_at, DATE(ci_pipelines.created_at) AS date_ci_pipelines_created_at 
FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 13083 AND ('2019-09-03 23:59:59.999999' > ci_pipelines.created_at AND 
ci_pipelines.created_at > '2019-08-27 00:00:00') GROUP BY DATE(ci_pipelines.created_at)

The query indeed seems ineffective:

Query Plan: https://explain.depesz.com/s/Vtb2

Steps to reproduce

Visit https://gitlab.com/gitlab-org/gitlab-ce/pipelines/charts multiple times, the error is raised from time to time

Example Project

https://gitlab.com/gitlab-org/gitlab-ce/pipelines/charts

What is the current bug behavior?

Raises 500 from time to time

What is the expected correct behavior?

The page is responsive all the time