behaviour change - default_tablesapce + partition table

From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: behaviour change - default_tablesapce + partition table
Date: 2019-05-17 03:40:10
Message-ID: CAGPqQf0cYjm1=rjxk_6gU0SjUS70=yFUAdCJLwWzh9bhNJnyVg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Consider the below test:

create tablespace mytbs location '/home/rushabh/mywork/workspace/pg/';
create table test ( a int , b int ) partition by list (a);

set default_tablespace to mytbs;
create table test_p1 partition of test for values in (1);

In the above test, after the setting the default_tablespace I am creating
a partition table and expecting that to get created under "mytbs"
tablespace.

But that is not the case:

postgres(at)66247=#select relname, reltablespace from pg_class where relname =
'test_p1';
relname | reltablespace
---------+---------------
test_p1 | 0
(1 row)

I noticed the behaviour change for default_tablespace with partition table
with below commit.

commit 87259588d0ab0b8e742e30596afa7ae25caadb18
Author: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Date: Thu Apr 25 10:20:23 2019 -0400

Fix tablespace inheritance for partitioned rels

Commit ca4103025dfe left a few loose ends. The most important one
(broken pg_dump output) is already fixed by virtue of commit
3b23552ad8bb, but some things remained:

I don't think that new behaviour is intended and if it's an intended change
than need to fix pg_dump as well - other wise lets say,
1) create the above test on v11
2) take a dump
3) restore on v12

will end up partition into wrong tablesapce.

Looking at the commit changes, it seems like at condition when no other
tablespace is specified, we default the tablespace to the parent partitioned
table's.

else if (stmt->partbound)
{
/*
* For partitions, when no other tablespace is specified, we default
* the tablespace to the parent partitioned table's.
*/
Assert(list_length(inheritOids) == 1);
tablespaceId = get_rel_tablespace(linitial_oid(inheritOids));
}

But here it doesn't consider the default_tablespace if the parent
partitioned
tablespace is an InvalidOid (which was the care before this commit).

PFA patch to fix the same.

Thanks,

--
Rushabh Lathia
www.EnterpriseDB.com

Attachment Content-Type Size
default_tablespace_for_partition.patch text/x-patch 587 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2019-05-17 03:46:11 Re: Adding a test for speculative insert abort case
Previous Message Andres Freund 2019-05-17 03:04:04 Re: Statistical aggregate functions are not working with PARTIAL aggregation