• M
    Resolve FIXME for validatepart by passing relpersistence of root · 263355cf
    Melanie Plageman 提交于
    MergeAttributes was used in atpxPart_validate_spec to get the schema and
    constraints to make a new leaf partition as part of ADD or SPLIT
    PARTITION. It was likely used as a convenience, since it already
    existed, and seems like the wrong function for the job.
    
    Previously atpxPart_validate_spec simply hard-coded in false for the relation
    persistence since the parameter was simply `isTemp`. Once the options
    for relation persistence were expanded to included unlogged, this
    paramter was changed to take a relpersistence. In MergeAttributes, for
    the part which we actually hit when calling it from here (we pass in the
    schema as NIL and therefore hit only half of the MergeAttributes code)
    the `supers` parameter is actually that of the parent partition and
    includes relpersistence, so, by passing in the relpersistence of the
    parent as relpersistence here, the checks we do around relpersistence are
    redundant because we are comparing the parent's relpersistence to its
    own. However, because, currently, this function is only called when we
    are making a new relation that, because we don't allow a different
    persistence to be specified for the child would actually just be using
    the relpersistence of the parent anyway, by passing it in hard-coded we
    would actually be incorrectly assuming that we are creating a permanent
    relation always.
    
    Since MergeAttributes was overkill, we wrote a new helper
    function, SetSchemaAndConstraints, to get the schema and constraints of
    a relation. This function doesn't do very many special validation checks
    that may be required by callers when using it in the context of
    partition tables (so user beware), however, it is probably only useful
    in the context of partition tables because it assumes constraints will
    be cooked, which, wouldn't be the case for all relations.
    We split it into two smaller inline functions for clarity. We also felt
    this would be a useful helper function in general, so we extern'd it.
    
    This commit also sets the relpersistence that is used to make the leaf
    partition when adding a new partition or splitting an existing a partition.
    
    makeRangeVar is a function from upstream which is basically a
    constructor. It sets relpersistence in the RangeVar to a hard-coded
    value of RELPERSISTENCE_PERMANENT. However, because we use the root
    partition to get the constraints and column information for the new
    leaf, after we use the default construction of the RangeVar, we need to
    set the relpersistence to that of the parent.
    
    This commit specifically only sets it back for the case in which we are
    adding a partition with `ADD PARTITION` or through `SPLIT PARTITION`.
    
    Without this commit, a leaf partition of an unlogged table created
    through `ADD PARTITION` or `SPLIT PARTITION` would incorrectly have its
    relpersistence set to permanent.
    Co-authored-by: NAlexandra Wang <lewang@pivotal.io>
    Co-authored-by: NMelanie Plageman <mplageman@pivotal.io>
    263355cf
cdbpartition.c 217.2 KB