Indexes for inequalities

From: Stephen Froehlich <s(dot)froehlich(at)cablelabs(dot)com>
To: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Indexes for inequalities
Date: 2018-04-13 17:09:58
Message-ID: CY1PR0601MB1210EFB80DBB4E0B3F89934EE5B30@CY1PR0601MB1210.namprd06.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi All,

I am creating an intersect table where I have a relationship that is true for a period of time and then a series of observations, so we're looking at something like:

SELECT * FROM

observations
INNER JOIN
relationships
ON (observations.id = relationships.id AND observations.time >= relationships.time_from AND observations.time < relationships.time_to)

How do I best build indexes on "relationships", which is a few hundred thousand lines in length for a fast join? Do I build one on all three columns (id, time_from, time_to) or three separate indexes for each column or some other combo? It's a small enough table where space isn't a worry, but speed will be as "observations" is several terabytes in size.

This is PostgreSQL 10, so we can CREATE STATISTICS, but the id, is an md5 (its hashed data), so it is therefore completely orthogonal on its own.

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 Tom Lane 2018-04-13 17:24:04 Re: Indexes for inequalities
Previous Message Amit S. 2018-04-13 13:51:32 Re: dual active 2-node cluster?