Joining 1-minute data with 5-minute data

From: Stephen Froehlich <s(dot)froehlich(at)cablelabs(dot)com>
To: "pgsql-novice(at)lists(dot)postgresql(dot)org" <pgsql-novice(at)lists(dot)postgresql(dot)org>
Subject: Joining 1-minute data with 5-minute data
Date: 2020-01-27 16:35:06
Message-ID: CY4PR0601MB3651B3C9AFAABD90CC261FF9E50B0@CY4PR0601MB3651.namprd06.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have a couple of relatively large tables, each with 100-500 million lines (at least in each monthly partition).

One has data every 1 minute, and the other has data every 5 minutes, and I'd like to be able to join them (i.e. with each minute in the 5-minute span rounded down to the beginning of that 5-minute interval).

I'm currently running PostgreSQL 11. An upgrade to 12 (for calculated fields) is possible but annoying at the moment. (i.e. I'll do it if its worth it, but I'm otherwise planning on holding off until the Ubuntu 20.40LTS release for that upgrade process.)

What is the most efficient (i.e. performant) way to do that join?

* Create an index for the 1-min table something like (trunc(time_stamp::int / 300) * 300)::timestamp with time zone
* Is there a more efficient way to round to 5 minutes?
* Encode the time stamp for the 5-min table as a tstzrange and create a gist index on that column?
* Manually add a 5-minute rounded column to the 1-minute table and index that?
* Something I have missed entirely?

Thanks,
Stephen

________________________________
Stephen Froehlich
Sr. Strategist, CableLabs(r)

s(dot)froehlich(at)cablelabs(dot)com<mailto:s(dot)froehlich(at)cablelabs(dot)com>
Tel: +1 (303) 661-3708

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Laurenz Albe 2020-01-28 08:43:57 Re: Joining 1-minute data with 5-minute data
Previous Message Tom Browder 2020-01-24 13:27:35 Re: Read only role for backup