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.94.2) (envelope-from ) id 1sIV83-00G2yb-Rc for pgsql-general@arkaria.postgresql.org; Sat, 15 Jun 2024 15:15:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sIV72-00EWYE-Na for pgsql-general@arkaria.postgresql.org; Sat, 15 Jun 2024 15:14:41 +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.94.2) (envelope-from ) id 1sIV72-00EWY5-9l for pgsql-general@lists.postgresql.org; Sat, 15 Jun 2024 15:14:41 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sIV70-001ofY-77 for pgsql-general@lists.postgresql.org; Sat, 15 Jun 2024 15:14:40 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2ec002caf3eso50716301fa.1 for ; Sat, 15 Jun 2024 08:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718464477; x=1719069277; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gUQxkuF951mpl74fJN57zkJahzj0kDAut430KWD9G3A=; b=NCjBgjLk6Jjd+L84nagGbkdtchiusJfCR0jqUK8+GojQfMIGCaOmGLtvbmJBlpQk6D o84N3e9/5ewpkqXlUw6IWfQICpCARsaJGI3Me+qTaYjkjdzCZj5biFTmqI0ZlvL1LYN8 ABwKhLhUnxdBFRIT7Kl/XDW/95g3Q05Ro6CDVIIxRxhzKeBUaPbgC3Hcq/xjihbXXe2N L/apWpPtlXupvZ1dz65t2gjT4ghpiEzpGJEg0Ac2dGF17eLbsj3WrzpJv7Y3Zr+wwMK6 oMxd8QQE/i85WexPimjypVdGFZ6ysRrqH12f2seqIonzkd2zWDPxXgei6R/5Lk5qtG28 53Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718464477; x=1719069277; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gUQxkuF951mpl74fJN57zkJahzj0kDAut430KWD9G3A=; b=ZylVWmGJj3Ece8d08IpyAq1wo8mEk+dCardKfJnDZZnbObiLAvIFv/fheV9nXqfd2h im8uyE8EtRuYaaCrmop1+BmuK2IjdSNPqs+pmVuub6BRi4k1FaVqtGYqkBUaSq15t0cN NO9t8nXldcdyuRwSHYiy/eTMgozLunZU2Ms5CVnqytxu+XYR5wYIAkfpB1CDBL+1tVHk UIcDssNuyWvMuheW+rJ7UdRaooxcRzNHvt71/I7iu0S9/Nh6GNKyeikRRkwXz8rq8l/a 3+vCoVhTwPiuBVEeh2s3ZLVLu+vDyZpiMZgLKoDegNWv26PgNC1nntSD135weWcSiE6X VPGA== X-Gm-Message-State: AOJu0Yz8g3TgapUh6RmjNj4KNUPCc9/FsLcq5qbt8qpDM+VRxts9aF/N +8Ti6uvDcHtF5mQXt0dKzLhx6fDnnpl61mPrsn3hKV3+9JcZJCMz7ZumgxeYuWNCRJY//UUtGWh xCQVx1Y82RRzxiAGgVo9CPXQJLdtokg== X-Google-Smtp-Source: AGHT+IH9/n+5HJyw65oFck/JfhYcLfPnEMIldtK92EVNagFJ2/NwZd4bXBjzjwEFxLY8GFWXQxSp/07uIPZ0FN+hBH8= X-Received: by 2002:a2e:83d0:0:b0:2eb:ebe9:f76d with SMTP id 38308e7fff4ca-2ec0e482652mr44705271fa.16.1718464476725; Sat, 15 Jun 2024 08:14:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Sushrut Shivaswamy Date: Sat, 15 Jun 2024 20:44:24 +0530 Message-ID: Subject: Re: Design for dashboard query To: sud Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000b1cbd0061aef304b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b1cbd0061aef304b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Have you tried creating an index on the user ID column? Scanning the entire table to apply granular filters on a few attributes seems unnecessary. Materialised views make sense if you want to aggregate some columns and query a subset of the data but would recommend trying indexes first. Finally, shameless plug but consider using the pg_analytica extension that enables fast analytic queries on the tables which is ideal for analytics use cases like dashboards. https://github.com/sushrut141/pg_analytica I=E2=80=99m the author of the extension and am looking for initial users to= try it out. Thanks, Sushrut On Sat, 15 Jun 2024 at 6:54 PM, sud wrote: > Hello All, > > Its postgres version 15.4. We are having a requirement in which aggregate= d > information for all the users has to be displayed on the UI screen. It > should show that information on the screen. So basically, it would be > scanning the full table data which is billions of rows across many months > and then join with other master tables and aggregate those and then displ= ay > the results based on the input "user id" filter. > > In such a scenario we are thinking of using a materialized view on top of > the base tables which will store the base information and refresh those > periodically to show the data based on the input user id. However i am > seeing , postgres not supporting incremental refresh of materialized view > and full refresh can take longer. So , do we have any other option > available? Additionally , It should not impact or block the online users > querying the same materialized view when the refresh is happening. > > > --000000000000b1cbd0061aef304b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Have you tried creating an index on the user ID column?
Scanning the entire table to apply granular filters o= n a few attributes seems unnecessary.

Materialised views make sense if you want to aggregate some c= olumns and query a subset of the data but would recommend trying indexes fi= rst.

Finally, shameless = plug but consider using the pg_analytica extension that enables fast analyt= ic queries on the tables which is ideal for analytics use cases like dashbo= ards.
I=E2=80= =99m the author of the extension and am looking for initial users to try it= out.

Thanks,
Sushrut


On Sat, 15 Jun 2024 = at 6:54 PM, sud <suds1434@gmail.co= m> wrote:

= Hello All,

Its postgres version 15.4. = We are having a requirement in which aggregated information for all the use= rs has to be displayed on the UI screen. It should show that information on= the screen. So basically, it would be scanning the full table data which i= s billions of rows across many months and then join with other master table= s and aggregate those and then display the results based on the input "= ;user id" filter.

In such a scenario we= are thinking of using a materialized view on top of the base tables which = will store the base information and refresh those periodically to show the = data based on the input user id. However i am seeing , postgres not suppor= ting incremental refresh of materialized view and full refresh can take lon= ger. So , do we have any other option available? Additionally = , It should not impact or block the online users querying the same material= ized view when the refresh is happening.


<= /div>
--000000000000b1cbd0061aef304b--