public inbox for [email protected]  
help / color / mirror / Atom feed
Re: Design for dashboard query
2+ messages / 2 participants
[nested] [flat]

* Re: Design for dashboard query
@ 2024-06-15 15:14 Sushrut Shivaswamy <[email protected]>
  2024-06-15 20:09 ` Re: Design for dashboard query yudhi s <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Sushrut Shivaswamy @ 2024-06-15 15:14 UTC (permalink / raw)
  To: sud <[email protected]>; +Cc: pgsql-general <[email protected]>

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’m 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 <[email protected]> wrote:

> Hello All,
>
> Its postgres version 15.4. We are having a requirement in which aggregated
> 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 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 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.
>
>
>


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Design for dashboard query
  2024-06-15 15:14 Re: Design for dashboard query Sushrut Shivaswamy <[email protected]>
@ 2024-06-15 20:09 ` yudhi s <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: yudhi s @ 2024-06-15 20:09 UTC (permalink / raw)
  To: Sushrut Shivaswamy <[email protected]>; +Cc: sud <[email protected]>; pgsql-general <[email protected]>

>
>
> On Sat, 15 Jun 2024 at 6:54 PM, sud <[email protected]> wrote:
>
>> Hello All,
>>
>> Its postgres version 15.4. We are having a requirement in which
>> aggregated 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
>> 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 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.
>>
>>
>>
Yes incremental refresh is by default not available but you can do the
refresh using "concurrently" keyword which will be online i believe and
won't block your ongoing  queries if any.

And there are some other ways like create another view(say mv_new) with
exactly the same definition and refresh that with whatever interval you
want and then switch the views with the original one using the rename
command.


ALTER MATERIALIZED VIEW mv RENAME TO mv_old;
ALTER MATERIALIZED VIEW mv_new RENAME TO mv;
DROP MATERIALIZED VIEW mv_old;

Or

have a log table created (say transaction_log) and populate it using
triggers with each delta insert/update/delete on the transaction table. And
then schedule a cron job which will periodically flush the rows from the
transaction_log table to the materialized view. This will achieve your
incremental refresh.


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-06-15 20:09 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-15 15:14 Re: Design for dashboard query Sushrut Shivaswamy <[email protected]>
2024-06-15 20:09 ` yudhi s <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox