• T
    Add Partitioned Indexes · 9d40d472
    Taylor Vesely 提交于
    This commit adds partitioned indexes from upstream Postgres. This commit is
    mostly cherry-picked from Postgres 11 and bug fixes from Postgres 12.
    
    Differences from upstream:
     - Postgres has two additional relkind's - RELKIND_PARTITIONED_TABLE and
       RELKIND_PARTITIONED_INDEX, which have no on disk storage. Greenplum does not
       have these additional relkinds. Thus, partitioned indexes have physical
       storage.
     - CREATE INDEX ON ONLY <table> DDL has not yet been implemented
     - ALTER INDEX ATTACH PARTITION DDL has not yet been implemented
    
    Constraint changes:
     - Constraints and their backing index have the same names. Thus, partitions of
       a table no longer share the same constraint name, and are instead related to
       their parent via INTERNAL_AUTO dependencies.
    
    Index changes:
     - Child partition indexes can no longer be directly dropped, and must be
       dropped from their root. This includes mid-level and leaf indexes.
     - Adding indexes to mid-level partitions cascade to their children.
    
    These changes are mostly cherry-picked from:
    commit 8b08f7d4
    Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
    Date:   Fri Jan 19 11:49:22 2018 -0300
    
        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
    
    Changes were also cherry-picked from the following Postgres commits:
      eb7ed3f3 - Allow UNIQUE indexes on partitioned tables
      ae366aa5 - Detach constraints when partitions are detached
      19184fcc - Simplify coding to detach constraints when detaching partition
      c7d43c4d - Correct attach/detach logic for FKs in partitions
      17f206fb - Set pg_class.relhassubclass for partitioned indexes
    Co-authored-by: NKalen Krempely <kkrempely@pivotal.io>
    9d40d472
partition.out 531.9 KB