Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vmlNP-00FzOM-2H for pgsql-general@arkaria.postgresql.org; Mon, 02 Feb 2026 04:17:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vmlNN-00BcKi-2M for pgsql-general@arkaria.postgresql.org; Mon, 02 Feb 2026 04:17:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vmlNN-00BcKa-13 for pgsql-general@lists.postgresql.org; Mon, 02 Feb 2026 04:17:26 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vmlNL-00000000bqx-3Fd9 for pgsql-general@lists.postgresql.org; Mon, 02 Feb 2026 04:17:25 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-b872f1c31f1so520540366b.0 for ; Sun, 01 Feb 2026 20:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770005837; cv=none; d=google.com; s=arc-20240605; b=PtqMZD2Fd2grSbggVqVJfjQ2tV3/WViFZlV39dfV3Kj9CPfnCdCrJWR4U2a6USaZsV d5JMWPvarmoZGwfcJZTDBx4MCkYitFyD57sSnsE8/7hKInM3JmX9GQoXt9Clks2wFiVb mWOzj5/rM+gJMqABQ9MExMPfkhJtjt4o+ge0cn7ZTfk94112be5rRrLByc+Tln+O12IQ yNaLf/sdzPi2zRleAj75rCryqnnWFVEYwc1VlHznYUl8a4I7LH82LthS8MeNl3yqkWtw zbGdl2XPLwz/bZ0F8Rzrz/oIl8kwrGdMrvdXAn+DNnc2UKzrXreUtI0hwg9xlkjSnYS6 y3wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6yn+jHQTz2O3M5tldpoN4/KpWQAHUxasgREpmpVLYfo=; fh=UwVCGV+zCPlUK7krddwDC4+9ECYdhhxxTQU+oOVrAGQ=; b=f6Vnnqgo3g8tFe8ETGuZHQLnUtyLxDIcWhiiEnmg5UPXX226m75j7y++MxXDtze08R c81C/Gq/WnFKor1M2wwV38ECq+1w45Wkks+Xm/eUWGkT9QHBg5pHCdbsbbyJZRMZ/fxQ 1he2HMUfxPmtkTTkyrzfISP1FWHppHhyX0iVG2e6f06usIseQjEPjpA5wa7gJC6scYfg oR3S8zumyc+K3Zq8x42TwBGa9l5xxCGUWOlCti6RBB20FyThsrHg8gBgNzvkxxY7nllf DZKnisiT6dU0zdPemeLoXsfuBSCvMw6G3jW7EeRpXp5xknX2LlvjJnr6JZgrs7UqS2m8 xSJA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770005837; x=1770610637; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=6yn+jHQTz2O3M5tldpoN4/KpWQAHUxasgREpmpVLYfo=; b=lQ2tckNf81LeVEkezTiulQPt6Y1hg+4QxyQXjVkSqJa7E95EFbWabzj1N9xnjKQwGG eOclboonsrQ6UKhKz1p6Z3m2U/k5ShAb/vdy5qIWKO6l2XZZXO4T8sBdforKoHrWVBpk /q9p9dwiO/+jTWkFxIv6xOXwT4I5qAxXoEqPL2coCIAWRtpREsm4T8G54eeG5XKRmdEc 8i49Xht2BYfknZe7w2SHEY6AHLIaU+rz7mpfcrcvE7ddcDuHbsK5new4GRLy1kQ686An wHFp5aHxcdqcgZp1lHiXMYisQuuWzMNLEpKcLLRZ1HPYiRhIYQlR8kDhKAj0O2E3+VZb 6rIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770005837; x=1770610637; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6yn+jHQTz2O3M5tldpoN4/KpWQAHUxasgREpmpVLYfo=; b=EwEEUEgW+4GOR7YGvpPf6h3107BPjLYkG/1B32pT8hGEV65Vy69daZtUDWrgH6/Fay EgRu5SvMugo+Q1xtwemh+jUYjYenPJC554PT/zMWxUNMcQoMuVFW9ROARf5pf9BXSaKy ekyDPE1Y4VS3uRAPuiPMEebyqQte1d4HPxzyCX4x4GuFYWjEQO7POyaUl+389fVjqjFU RvlfYQhydLmN8wwmtFq0D33ooyPvx2csEKiLpPZq1dnDlJ9rbJovkHNj7sBvKUxs5h9X esnlNcevlBNVEziEPYEU+61BupP6AJIp7eYpS18kKKC0xhbzHB91qPe5KkoNZveCld6l HdRA== X-Gm-Message-State: AOJu0YzIv+lVzOOfGcyz0ZlGbSSg8HF7JXHwQ02IPrZIsH2Kzl/J1Dj0 kC5v5ST3Nq8OChNvw76lM4nTm754BVH6wp2t5f72V0xez4RbKuXYFZYaZNKpjE000I6g1Q3OdQT is7p5lUGTd8EpYdZ42wdUYpIs7Gtn+x0qboTP X-Gm-Gg: AZuq6aLDz8HRfPJKOinruP+uYy1ZIBBODzwW6iv0CXv3lQL1jMkCL72ZdMs9MUhEW/z v14gdeK8K345bOqB4UMz8q6j7lV/5EcR4Ap/cmvdTc3fSVGEiQszNrv9QPQ2IbHPVeqMoCy1RK0 saJzM5MNRHBEzxy1m4F15KrUruS/83bVksKbPAoqG3XEuVz69SHAIAeiAwmhRgNkpfC2QB8/iVj OYZyAG9BXAuo73GZUfu7tgPoV2fFCTryfkWEnCedV3AINBlkfEVhHXXTf2HKu1U8K044MXkmwR+ Qm0tEI3FHoh+mk/hnKA8xGw2 X-Received: by 2002:a17:907:72c5:b0:b8a:f225:ede8 with SMTP id a640c23a62f3a-b8dff68478emr599326166b.41.1770005837323; Sun, 01 Feb 2026 20:17:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: yudhi s Date: Mon, 2 Feb 2026 09:47:06 +0530 X-Gm-Features: AZwV_Qhr-1LiUB5paCqb9JRNtr4MEsX5kOx6Kvkr1R9tKEOtI_9EE0MGfscT_EE Message-ID: Subject: Re: Top -N Query performance issue and high CPU usage To: pgsql-general@lists.postgresql.org, Ron Johnson , hjp-pgsql@hjp.at Content-Type: multipart/alternative; boundary="0000000000002f20490649cf99a3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002f20490649cf99a3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 2, 2026 at 3:17=E2=80=AFAM Peter J. Holzer w= rote: > > 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? --0000000000002f20490649cf99a3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Mon, Feb 2, 2026 at 3:17= =E2=80=AFAM Peter J. Holzer <hjp-pgs= ql@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 t= he
suggestion to check whether there's an index on
APP_schema.txn_tbl.tran_date), then maybe you don't need to perform it<= br> 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 b= e 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 t= he exact number of such queries which can hit the database. However, as 100= 0 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,=C2=A0 when you said caching :- The = results on the base tables are going to be ~30-50 million. This landing pag= e 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 r= efresh (maybe once in ~5 minutes behind the scenes) and then that can=C2=A0= be queried in the landing page directly. And we can have suitable indexes c= reated on the materialized view based on the dynamic filter criteria?
=
--0000000000002f20490649cf99a3--