Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
От | jian he |
---|---|
Тема | Re: Add SPLIT PARTITION/MERGE PARTITIONS commands |
Дата | |
Msg-id | CACJufxHBhjeXgG=d6h+cVcQLU-yif2FWGLypu-MUoyywDOEyKQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Add SPLIT PARTITION/MERGE PARTITIONS commands (jian he <jian.universality@gmail.com>) |
Список | 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.
Вложения
В списке pgsql-hackers по дате отправления: