From: Thomas Kellerer <shammat@gmx.net>
To: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Suggestion: provide a "TRUNCATE PARTITION" command
Date: Fri, 8 Jan 2021 17:38:10 +0100
Message-ID: <999c4e39-ec8d-35db-f77e-06361861fe4e@gmx.net> (raw)
In-Reply-To: <CAHOFxGogGwo14J0r5_BfSDR4=UtH-W48FKOk_3tKDftYFK0j2g@mail.gmail.com>
References: <99277f39-f1a1-6da5-176c-3def058cf568@gmx.net>
<CAHOFxGogGwo14J0r5_BfSDR4=UtH-W48FKOk_3tKDftYFK0j2g@mail.gmail.com>
Michael Lewis schrieb am 08.01.2021 um 16:32:
> On Fri, Jan 8, 2021 at 2:36 AM Thomas Kellerer <shammat@gmx.net <mailto:shammat@gmx.net>> wrote:
>
> Hello,
>
> I wonder if it made sense to add a "TRUNCATE PARTITION" command to Postgres?
>
> Especially during bulk loads it's more efficient to TRUNCATE a partition if I know I want to replace all rows, rather than doing a DELETE.
>
> Currently this requires dynamic SQL which isn't always feasible (and might get complicated quickly).
>
> So I was thinking that a new command to allow truncating partitions by identifying the partitions by "value" rather by name might be helpful in that case.
>
> Something along the lines of:
>
> truncate partitions of base_table
> for values in (...);
>
> If the IN part allowed for sub-queries then this could be used to gather the partition keys from e.g. a staging table.
>
>
> For me, it seems too easily error prone such that a single typo in
> the IN clause may result in an entire partition being removed that
> wasn't supposed to be targeted.
I don't see how this is more dangerous then:
delete from base_table
where partition_key in (...);
which would serve the same purpose, albeit less efficient.
> Given the user still needs to
> manually generate that list somehow, I don't see it as a huge effort
> to query the partitions and run individual commands to truncate or
> detach several partitions manually.
Well, the list could come from e.g. a staging table, e.g. "for values IN (select some_column from staging_table)"
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: shammat@gmx.net
Subject: Re: Suggestion: provide a "TRUNCATE PARTITION" command
In-Reply-To: <999c4e39-ec8d-35db-f77e-06361861fe4e@gmx.net>
References: <99277f39-f1a1-6da5-176c-3def058cf568@gmx.net> <CAHOFxGogGwo14J0r5_BfSDR4=UtH-W48FKOk_3tKDftYFK0j2g@mail.gmail.com> <999c4e39-ec8d-35db-f77e-06361861fe4e@gmx.net>
* 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