Re: CPU Consuming query. Sequential scan despite indexing. - Mailing list pgsql-performance

From aditya desai
Subject Re: CPU Consuming query. Sequential scan despite indexing.
Date
Msg-id CAN0SRDH2A_nq1jvpz92xWtaFPq1xLxOK9V35i1Hi+M2FZc0J=w@mail.gmail.com
Whole thread Raw
In response to Re: CPU Consuming query. Sequential scan despite indexing.  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-performance
Hi David,
Thanks for the suggestion. Let me try to implement this as well. WIll get back to you soon.

Regards,
Aditya.

On Thu, Oct 22, 2020 at 11:03 AM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Wed, Oct 21, 2020 at 10:22 PM aditya desai <admad123@gmail.com> wrote:
As per application team, it is business requirement to show last 60 days worth data.

I didn't look deeply but it sounds like you are looking backwards into 60 days worth of detail every single time you perform the query and computing an aggregate directly from the detail.  Stop doing that.  By way of example, at the end of every day compute the aggregates on the relevant dimensions and save them.  Then query the saved aggregates from previous days and add them to the computed aggregate from the current day's detail.

David J.

pgsql-performance by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: CPU Consuming query. Sequential scan despite indexing.
Next
From: Mats Olsen
Date:
Subject: Re: Query Performance / Planner estimate off