From: Niels Jespersen <NJN@dst.dk>
To: Francisco Olarte <folarte@peoplecall.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: SV: design partioning scheme for selecting from latest partition
Date: Tue, 23 Mar 2021 05:28:54 +0000
Message-ID: <bf8e07677539487bac1afb67298474cd@dst.dk> (raw)
In-Reply-To: <CA+bJJbx6CQ2O9oAcSBeGi-puV14SZzc0O6VYAu50ndO5895vEA@mail.gmail.com>
References: <5de5c8b614544d7ba782b15ffb12e5da@dst.dk>
<CA+bJJbx6CQ2O9oAcSBeGi-puV14SZzc0O6VYAu50ndO5895vEA@mail.gmail.com>
>Fra: Francisco Olarte <folarte@peoplecall.com>
>Sendt: 22. marts 2021 20:04
>Til: Niels Jespersen <NJN@dst.dk>
>Cc: pgsql-general@lists.postgresql.org
>Emne: Re: design partioning scheme for selecting from latest partition
>
>Niels:
>
>On Mon, Mar 22, 2021 at 3:40 PM Niels Jespersen <NJN@dst.dk> wrote:
>...
>> -- Then I want to be able to do this wothout scanning all partitions for the highest version number.
>>
>> select s.* from s where s.version = (select max(version) from s);
>
>> I could add an index on the version column. But the only use would be to the newest partition, so that seems a bit like overkill, indexing 100 of milliomns of rows.
>
>Without an index, or some caching, you would need to scan partitions.
>...
>Even if you can do something like that, without an index you will need a full scan, or do some trigger magic and keep a cache ( just keep versio, count(*) on a table and maintain it ). If your partitions are ordered, you can always keep the last one indexed, or if you know versions do not decrease, you may keep things cached. This seems to be the kind of problem where the generic solution is hard but a little insider knowledge can accelerate it a lot.
>
>Regards.
> Francisco Olarte.
Thank you Francisco
I think I will revisit the whole design. Better do it right.
Niels
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: NJN@dst.dk, folarte@peoplecall.com
Subject: Re: design partioning scheme for selecting from latest partition
In-Reply-To: <bf8e07677539487bac1afb67298474cd@dst.dk>
References: <5de5c8b614544d7ba782b15ffb12e5da@dst.dk> <CA+bJJbx6CQ2O9oAcSBeGi-puV14SZzc0O6VYAu50ndO5895vEA@mail.gmail.com> <bf8e07677539487bac1afb67298474cd@dst.dk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox