Re: Top -N Query performance issue and high CPU usage - Mailing list pgsql-general

From yudhi s
Subject Re: Top -N Query performance issue and high CPU usage
Date
Msg-id CAEzWdqcAbi0GYp_K64oZTeUeN3YN7-eFQ2m2fZDRvmnJx5Lb5w@mail.gmail.com
Whole thread Raw
In response to Re: Top -N Query performance issue and high CPU usage  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
Responses Re: Top -N Query performance issue and high CPU usage
List pgsql-general


On Mon, Feb 2, 2026 at 3:17 AM Peter J. Holzer <hjp-pgsql@hjp.at> wrote:

If you do have that many simultaneous accesses to the landing page, and
you can't speed up the query significantly (I take it you've seen the
suggestion to check whether there's an index on
APP_schema.txn_tbl.tran_date), then maybe you don't need to perform it
for every user? I don't know what the query is supposed to do, but
unless the "ent_id" is really a user id, it doesn't seem to be specific
to the user. So maybe you can cache the result for a minute or an hour
and show the same result to everybody who logs in during that time.

       

There was no index on column  tran_date  , I created one and it's making the query finish in  ~200ms, a lot faster than in the past. Below is the portion of the query and its plan which actually consumes most of the resource and time post the new index creation.


1) Now the part  which takes time is the "nested loop" join on the "ent_id"  column. Can we do anything to make it much better/faster?

2) Also another question I had was,  with this new index the table scan of txn_tbl is now fully eliminated by the "Index Scan Backward" even i have other columns from that table projected in the query, so how its getting all those column values without visiting table but just that index scan backward operation?


pgsql-general by date:

Previous
From: Thiemo Kellner
Date:
Subject: Re: Top -N Query performance issue and high CPU usage
Next
From: Ron Johnson
Date:
Subject: Re: Top -N Query performance issue and high CPU usage