pgsql: Fix tablespace handling for partitioned indexes

Started by Alvaro Herreraabout 8 years ago3 messagescommitters
Jump to latest
#1Alvaro Herrera
alvherre@alvh.no-ip.org

Fix tablespace handling for partitioned indexes

When creating partitioned indexes, the tablespace was not being saved
for the parent index. This meant that subsequently created partitions
would not use the right tablespace for their indexes.

ALTER INDEX SET TABLESPACE and ALTER INDEX ALL IN TABLESPACE raised
errors when tried; fix them too. This requires bespoke code for
ATExecCmd() that applies to the special case when the tablespace move is
just a catalog change.

Discussion: /messages/by-id/20181102003138.uxpaca6qfxzskepi@alvherre.pgsql

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/dfa6081419829ef60d6bc02691616337eeb7f988

Modified Files
--------------
src/backend/catalog/heap.c | 10 +++++-
src/backend/commands/tablecmds.c | 60 +++++++++++++++++++++++++++++--
src/test/regress/input/tablespace.source | 10 ++++++
src/test/regress/output/tablespace.source | 19 +++++++++-
4 files changed, 94 insertions(+), 5 deletions(-)

#2David Rowley
david.rowley@2ndquadrant.com
In reply to: Alvaro Herrera (#1)
Re: pgsql: Fix tablespace handling for partitioned indexes

On Sun, 4 Nov 2018 at 05:33, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

Fix tablespace handling for partitioned indexes

While working on something else, I noticed this:

# create table listp (a int) partition by list(a);
CREATE TABLE
# create index on listp (a) tablespace pg_global; -- properly disallowed
ERROR: only shared relations can be placed in pg_global tablespace
# create index on listp (a);
CREATE INDEX
# alter index listp_a_idx set tablespace pg_global; -- should be disallowed
ALTER INDEX
# create table listp1 partition of listp for values in(1);
ERROR: only shared relations can be placed in pg_global tablespace

A patch to fix is attached.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

disallow_partitioned_indexes_from_being_put_in_pg_global.patchapplication/octet-stream; name=disallow_partitioned_indexes_from_being_put_in_pg_global.patchDownload+6-0
#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: David Rowley (#2)
Re: pgsql: Fix tablespace handling for partitioned indexes

On 2018-Nov-23, David Rowley wrote:

A patch to fix is attached.

Oops! Thanks. Pushed. I added a test line to verify that the error is
thrown.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services