Local partitioned indexes
commit8b08f7d4820fd7a8ef6152a9dd8c6e3cb01e5f99
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 19 Jan 2018 14:49:22 +0000 (19 11:49 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 19 Jan 2018 14:49:22 +0000 (19 11:49 -0300)
tree0ecb879a9568e7e14275afe72a77e316e72376c6
parent1ef61ddce9086c30a18a6ecc48bc3ce0ef62cb39
Local partitioned indexes

When CREATE INDEX is run on a partitioned table, create catalog entries
for an index on the partitioned table (which is just a placeholder since
the table proper has no data of its own), and recurse to create actual
indexes on the existing partitions; create them in future partitions
also.

As a convenience gadget, if the new index definition matches some
existing index in partitions, these are picked up and used instead of
creating new ones.  Whichever way these indexes come about, they become
attached to the index on the parent table and are dropped alongside it,
and cannot be dropped on isolation unless they are detached first.

To support pg_dump'ing these indexes, add commands
    CREATE INDEX ON ONLY <table>
(which creates the index on the parent partitioned table, without
recursing) and
    ALTER INDEX ATTACH PARTITION
(which is used after the indexes have been created individually on each
partition, to attach them to the parent index).  These reconstruct prior
database state exactly.

Reviewed-by: (in alphabetical order) Peter Eisentraut, Robert Haas, Amit
Langote, Jesper Pedersen, Simon Riggs, David Rowley
Discussion: https://postgr.es/m/20171113170646.gzweigyrgg6pwsg4@alvherre.pgsql
49 files changed:
doc/src/sgml/catalogs.sgml
doc/src/sgml/ref/alter_index.sgml
doc/src/sgml/ref/alter_table.sgml
doc/src/sgml/ref/create_index.sgml
doc/src/sgml/ref/reindex.sgml
src/backend/access/common/reloptions.c
src/backend/access/heap/heapam.c
src/backend/access/index/indexam.c
src/backend/bootstrap/bootparse.y
src/backend/catalog/aclchk.c
src/backend/catalog/dependency.c
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/catalog/objectaddress.c
src/backend/catalog/pg_depend.c
src/backend/catalog/pg_inherits.c
src/backend/catalog/toasting.c
src/backend/commands/indexcmds.c
src/backend/commands/tablecmds.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/outfuncs.c
src/backend/parser/gram.y
src/backend/parser/parse_utilcmd.c
src/backend/tcop/utility.c
src/backend/utils/adt/amutils.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/cache/relcache.c
src/bin/pg_dump/common.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/pg_dump_sort.c
src/bin/pg_dump/t/002_pg_dump.pl
src/bin/psql/describe.c
src/bin/psql/tab-complete.c
src/include/catalog/dependency.h
src/include/catalog/index.h
src/include/catalog/pg_class.h
src/include/catalog/pg_inherits_fn.h
src/include/commands/defrem.h
src/include/nodes/execnodes.h
src/include/nodes/parsenodes.h
src/include/parser/parse_utilcmd.h
src/test/regress/expected/alter_table.out
src/test/regress/expected/indexing.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/serial_schedule
src/test/regress/sql/alter_table.sql
src/test/regress/sql/indexing.sql [new file with mode: 0644]