From: Niels Jespersen <NJN@dst.dk>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: design partioning scheme for selecting from latest partition
Date: Mon, 22 Mar 2021 14:40:32 +0000
Message-ID: <5de5c8b614544d7ba782b15ffb12e5da@dst.dk> (raw)
Hello
I have a table partitioned like this
drop table if exists s cascade;
create table s
(
version int not null,
a int,
b int
) partition by list (version);
-- Add tens of partitions
-- Load millions of rows in each partition
-- 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.
Is there another way to do this in a cheaper way.
For now I have created a materialized view based on the select above, thus only scanning for max partition only once.
Niels Jespersen
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
Subject: Re: design partioning scheme for selecting from latest partition
In-Reply-To: <5de5c8b614544d7ba782b15ffb12e5da@dst.dk>
References: <5de5c8b614544d7ba782b15ffb12e5da@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