]> granicus.if.org Git - postgresql/commit
Make sure ALTER TABLE preserves index tablespaces.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 Nov 2016 18:45:56 +0000 (13:45 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 Nov 2016 18:45:56 +0000 (13:45 -0500)
commite0375d77b691f6cab70934c63d3212a4713f66df
treed2dc4e021b7a5243ed00eeb53c5c6d2eae0827a6
parent3de257f602550407ba095189feb6d3db8cd02b22
Make sure ALTER TABLE preserves index tablespaces.

When rebuilding an existing index, ALTER TABLE correctly kept the
physical file in the same tablespace, but it messed up the pg_class
entry if the index had been in the database's default tablespace
and "default_tablespace" was set to some non-default tablespace.
This led to an inaccessible index.

Fix by fixing pg_get_indexdef_string() to always include a tablespace
clause, whether or not the index is in the default tablespace.  The
previous behavior was installed in commit 537e92e41, and I think it just
wasn't thought through very clearly; certainly the possible effect of
default_tablespace wasn't considered.  There's some risk in changing the
behavior of this function, but there are no other call sites in the core
code.  Even if it's being used by some third party extension, it's fairly
hard to envision a usage that is okay with a tablespace clause being
appended some of the time but can't handle it being appended all the time.

Back-patch to all supported versions.

Code fix by me, investigation and test cases by Michael Paquier.

Discussion: <1479294998857-5930602.post@n3.nabble.com>
src/backend/utils/adt/ruleutils.c
src/test/regress/input/tablespace.source
src/test/regress/output/tablespace.source