pgsql: Fix tablespace inheritance for partitioned rels

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

pgsql: Fix tablespace inheritance for partitioned rels

Álvaro Herrera
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:

* When ALTER TABLE rewrites tables, the indexes must remain in the
  tablespace they were originally in.  This didn't work because
  index recreation during ALTER TABLE runs manufactured SQL (yuck),
  which runs afoul of default_tablespace in competition with the parent
  relation tablespace.  To fix, reset default_tablespace to the empty
  string temporarily, and add the TABLESPACE clause as appropriate.

* Setting a partitioned rel's tablespace to the database default is
  confusing; if it worked, it would direct the partitions to that
  tablespace regardless of default_tablespace.  But in reality it does
  not work, and making it work is a larger project.  Therefore, throw
  an error when this condition is detected, to alert the unwary.

Add some docs and tests, too.

Author: Álvaro Herrera
Discussion: https://postgr.es/m/CAKJS1f_1c260nOt_vBJ067AZ3JXptXVRohDVMLEBmudX1YEx-A@...

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/87259588d0ab0b8e742e30596afa7ae25caadb18

Modified Files
--------------
doc/src/sgml/config.sgml                  |   3 +-
doc/src/sgml/ref/create_table.sgml        |   6 +-
src/backend/bootstrap/bootparse.y         |   2 +
src/backend/commands/indexcmds.c          |  27 ++-
src/backend/commands/matview.c            |   2 +-
src/backend/commands/tablecmds.c          |  34 +--
src/backend/commands/tablespace.c         |  16 +-
src/backend/nodes/copyfuncs.c             |   2 +
src/backend/nodes/equalfuncs.c            |   2 +
src/backend/nodes/outfuncs.c              |   4 +
src/backend/parser/gram.y                 |   2 +
src/backend/parser/parse_utilcmd.c        |   2 +
src/backend/utils/adt/ruleutils.c         |  19 +-
src/include/catalog/catversion.h          |   2 +-
src/include/commands/tablespace.h         |   2 +-
src/include/nodes/parsenodes.h            |   4 +
src/test/regress/input/tablespace.source  |  90 ++++++++
src/test/regress/output/tablespace.source | 334 ++++++++++++++++++++++++++++++
18 files changed, 519 insertions(+), 34 deletions(-)