pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Alexander Rumyantsev <alexander@rumyantsev.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Correct way of using complex expressions as partitioning key
Date: Fri, 27 Oct 2023 10:33:48 +0200
Message-ID: <0ce0470f4727ea3f5253999640f3fdc633459c33.camel@cybertec.at> (raw)
In-Reply-To: <20D8B5BB-DB0B-400D-8560-2F5765361CB1@rumyantsev.com>
References: <20D8B5BB-DB0B-400D-8560-2F5765361CB1@rumyantsev.com>

On Fri, 2023-10-27 at 07:27 +0300, Alexander Rumyantsev wrote:
> Is there some correct way to use complex expressions as a key for partitioned table?
> Inserting works as expected, but select runs over all partitions until use complete
> partition key expression as predicate
> 
> test=# create table test (
>         id text,
>         v1 bigint,
>         v2 bigint
> )
> partition by range (((v1 + v2) % 10));
> CREATE TABLE
> 
> test=# explain analyze select * from test where v1 = 100 and v2 = 100;
> [no partition pruning]
> 
> test=# explain analyze select * from test where ((v1 + v2) % 10) = 0 and v1 = 100 and v2 = 100;
> [partition pruning]

Yes, you only get partition pruning if the WHERE clause contains a comparison with
the partitioning key.  There is no way around that.

Yours,
Laurenz Albe





view thread (3+ messages)  latest in thread

Message-ID: <0ce0470f4727ea3f5253999640f3fdc633459c33.camel@cybertec.at>
Permalink:  ../0ce0470f4727ea3f5253999640f3fdc633459c33.camel@cybertec.at/
Also on:    postgresql.org/message-id/0ce0470f4727ea3f5253999640f3fdc633459c33.camel@cybertec.at

 · 

reply

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: laurenz.albe@cybertec.at, alexander@rumyantsev.com
  Subject: Re: Correct way of using complex expressions as partitioning key
  In-Reply-To: <0ce0470f4727ea3f5253999640f3fdc633459c33.camel@cybertec.at>
  References: <20D8B5BB-DB0B-400D-8560-2F5765361CB1@rumyantsev.com> <0ce0470f4727ea3f5253999640f3fdc633459c33.camel@cybertec.at>

* 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