pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #17211: Partitioned index partition does not inherit table partition tablespace
2+ messages / 2 participants
[nested] [flat]
* BUG #17211: Partitioned index partition does not inherit table partition tablespace
@ 2021-10-01 18:07 PG Bug reporting form <noreply@postgresql.org>
2021-10-02 14:33 ` Re: BUG #17211: Partitioned index partition does not inherit table partition tablespace Euler Taveira <euler@eulerto.com>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2021-10-01 18:07 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: gatekeeper.mail@gmail.com
The following bug has been logged on the website:
Bug reference: 17211
Logged by: Andy S
Email address: gatekeeper.mail@gmail.com
PostgreSQL version: 14.0
Operating system: Debian Bullseye
Description:
Suppose we have 2 tablespaces:
pg_default (which is slow)
fast
We also have a partitioned table:
create table a (id serial not null, b int not null primary key, c int not
null, d int) partition by hash (b);
and 2 partitions:
create table a_1 partition of a for values with (modulus 2, remainder 0);
create table a_2 partition of a for values with (modulus 2, remainder 1)
tablespace fast;
This successfully allocates table a_2 pages within the 'fast' tablespace;
but this fails to allocate a_2_pkey primary key index there too and the
result is the index is allocated on tablespace oid(0) which means pg_default
I guess, at least the corresponding relfilenode is allocated within the
pg_default tablespace.
There's also a CREATE TABLE hack for index/constraint declaration within the
command that allows USING INDEX TABLESPACE, though there's an unresolved
error loop in partitioned tables use-case for such a syntax:
create table a_2 partition of a (primary key using index tablespace fast)
for values with (modulus 2, remainder 1) tablespace fast;
fails since there's no primary key definition provided
create table a_2 partition of a (primary key (b) using index tablespace
fast) for values with (modulus 2, remainder 1) tablespace fast;
fails with 'ERROR: multiple primary keys for table "a_2" are not allowed'
The only possibility for a user to then allocate both index(es) and a table
on a non-default tablespace is to create a partition, scan pg_class/pg_index
to find all the names of indexes' partitions allocated for the new table,
traverse them programmatically and ALTER INDEX SET TABLESPACE them. Which
does not seem convenient since there's a simpler syntax/approach for a
regular table.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #17211: Partitioned index partition does not inherit table partition tablespace
2021-10-01 18:07 BUG #17211: Partitioned index partition does not inherit table partition tablespace PG Bug reporting form <noreply@postgresql.org>
@ 2021-10-02 14:33 ` Euler Taveira <euler@eulerto.com>
0 siblings, 0 replies; 2+ messages in thread
From: Euler Taveira @ 2021-10-02 14:33 UTC (permalink / raw)
To: gatekeeper.mail@gmail.com; pgsql-bugs@lists.postgresql.org
On Fri, Oct 1, 2021, at 3:07 PM, PG Bug reporting form wrote:
> Suppose we have 2 tablespaces:
> pg_default (which is slow)
> fast
>
> We also have a partitioned table:
> create table a (id serial not null, b int not null primary key, c int not
> null, d int) partition by hash (b);
>
> and 2 partitions:
> create table a_1 partition of a for values with (modulus 2, remainder 0);
> create table a_2 partition of a for values with (modulus 2, remainder 1)
> tablespace fast;
>
> This successfully allocates table a_2 pages within the 'fast' tablespace;
> but this fails to allocate a_2_pkey primary key index there too and the
> result is the index is allocated on tablespace oid(0) which means pg_default
> I guess, at least the corresponding relfilenode is allocated within the
> pg_default tablespace.
That's how it was designed. TABLESPACE clause at the end of CREATE TABLE set
the tablespace only for the table. The index is stored based on the
default_tablespace [1] value.
Since there is no way to specify USING INDEX TABLESPACE for partitions, you
should set default_tablespace to achieve what you want.
CREATE TABLE a (
id serial NOT NULL,
b int NOT NULL PRIMARY KEY,
c int NOT NULL,
d int
) PARTITION BY hash (b);
CREATE TABLE a_1 PARTITION OF a
FOR VALUES WITH (MODULUS 3, REMAINDER 0);
SET default_tablespace TO 'fast';
-- the TABLESPACE clause is not required
-- table -> fast ; index -> fast
CREATE TABLE a_2 PARTITION OF a
FOR VALUES WITH (MODULUS 3, REMAINDER 1) TABLESPACE fast;
-- table -> tablespace slow ; index -> tablespace fast
CREATE TABLE a_3 PARTITION OF a
FOR VALUES WITH (MODULUS 3, REMAINDER 2) TABLESPACE slow;
RESET default_tablespace;
[1] https://www.postgresql.org/docs/14/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-STATEMENT
--
Euler Taveira
EDB https://www.enterprisedb.com/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2021-10-02 14:33 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 18:07 BUG #17211: Partitioned index partition does not inherit table partition tablespace PG Bug reporting form <noreply@postgresql.org>
2021-10-02 14:33 ` Euler Taveira <euler@eulerto.com>
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