From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru> |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Add SPLIT PARTITION/MERGE PARTITIONS commands |
Date: | 2025-06-06 07:13:22 |
Message-ID: | CACJufxHBhjeXgG=d6h+cVcQLU-yif2FWGLypu-MUoyywDOEyKQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | Content-Type | Size |
---|---|---|
v41-0001-misc-fixes-in-createTableConstraints.no-cfbot | application/octet-stream | 2.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2025-06-06 07:14:32 | pg_dump --with-* options |
Previous Message | Nisha Moond | 2025-06-06 07:07:30 | Re: Fix slot synchronization with two_phase decoding enabled |