Re: Add SPLIT PARTITION/MERGE PARTITIONS commands - Mailing list pgsql-hackers

From jian he
Subject Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date
Msg-id CACJufxHBhjeXgG=d6h+cVcQLU-yif2FWGLypu-MUoyywDOEyKQ@mail.gmail.com
Whole thread Raw
In response to Re: Add SPLIT PARTITION/MERGE PARTITIONS commands  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
hi.

in createTableConstraints
+ /* Add a pre-cooked default expression. */
+ StoreAttrDefault(newRel, num, def, true);
+
+ /* Store CHECK constraints. */
+ StoreConstraints(newRel, cookedConstraints, false);
Here, StoreConstraints last argument should be set to true?
see also StoreAttrDefault.


+static void
+createTableConstraints(Relation modelRel, Relation newRel)
+ /*
+ * Construct a map from the LIKE relation's attnos to the child rel's.
+ * This re-checks type match etc, although it shouldn't be possible to
+ * have a failure since both tables are locked.
+ */
+ attmap = build_attrmap_by_name(RelationGetDescr(newRel),
+   tupleDesc,
+   false);
+
+ /* Cycle for default values. */
+ for (parent_attno = 1; parent_attno <= tupleDesc->natts; parent_attno++)
+ {
+ Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
+ parent_attno - 1);
+
+ /* Ignore dropped columns in the parent. */
+ if (attribute->attisdropped)
+ continue;
+
+ /* Copy default, if present and it should be copied. */
+ if (attribute->atthasdef)
+ {
+ Node   *this_default = NULL;
+ AttrDefault *attrdef = constr->defval;
+ bool found_whole_row;
+ int16 num;
+ Node   *def;
+
+ /* Find default in constraint structure */
+ for (int i = 0; i < constr->num_defval; i++)
+ {
+ if (attrdef[i].adnum == parent_attno)
+ {
+ this_default = stringToNode(attrdef[i].adbin);
+ break;
+ }
+ }
+ if (this_default == NULL)
+ elog(ERROR, "default expression not found for attribute %d of
relation \"%s\"",
+ parent_attno, RelationGetRelationName(modelRel));
you can use TupleDescGetDefault, build_generation_expression
to simplify the above code.

The attached patch fixes the above issues.
it is based on v41-0001-Implement-ALTER-TABLE-.-MERGE-PARTITIONS-.-comma.patch
----------------------
Do getAttributesList need to care about pg_attribute.attidentity?
currently MERGE PARTITION seems to work fine with identity columns,
this issue i didn't dig deeper.

I am wondering right after createPartitionTable,
do we need a CommandCounterIncrement?
because later moveMergedTablesRows will use the output of createPartitionTable.

Attachment

pgsql-hackers by date:

Previous
From: Nisha Moond
Date:
Subject: Re: Fix slot synchronization with two_phase decoding enabled
Next
From: Peter Eisentraut
Date:
Subject: pg_dump --with-* options