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 CAEzWdqf+b+7JDRNzJVqWKyF8N8Aa2CZC5B_o1xZLDWozqV-RUA@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>)
List pgsql-general


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

However, maybe you didn't mean that. There are relatively few
applications where thousands of users log in within a second. Maybe you
just meant that there would be thousands of users logged in in total. If
so, how many simultaneus queries do you really expect?

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.


Thank you so much. I need to get back on the exact number of such queries which can hit the database. However, as 1000 of users will be there, so the possibility of all logging into the system on the same page at same time needs to be found out. Will double check on this.

However,  when you said caching :- The results on the base tables are going to be ~30-50 million. This landing page has filters on it so it may be of 30+ different combinations based on the user's choice. So do you suggest , we will populate the base data in a materialized view(named like "landing page data") which we can refresh (maybe once in ~5 minutes behind the scenes) and then that can be queried in the landing page directly. And we can have suitable indexes created on the materialized view based on the dynamic filter criteria?

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Top -N Query performance issue and high CPU usage
Next
From: yudhi s
Date:
Subject: Re: Top -N Query performance issue and high CPU usage