Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
От | jian he |
---|---|
Тема | Re: Add SPLIT PARTITION/MERGE PARTITIONS commands |
Дата | |
Msg-id | CACJufxFGPLTDW55bgaBTH1uCf0=YUZUVKWFrTBvOZNYKc49MxA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Add SPLIT PARTITION/MERGE PARTITIONS commands (Dmitry Koval <d.koval@postgrespro.ru>) |
Ответы |
Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Re: Add SPLIT PARTITION/MERGE PARTITIONS commands |
Список | pgsql-hackers |
hi. the following are review of v40-0001-Implement-ALTER-TABLE-.-MERGE-PARTITIONS-.-comma.patch ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022) INTO sales_feb_mar_apr2022; There are no tests when sales_feb2022 or sales_mar2022 have any constraints. a partition can have its own constraint. What should we do when any to be merged partition has constraints? ---------------------------------------------------------------- DROP TABLE IF EXISTS sales_range cascade; CREATE TABLE sales_range (salesperson_id INT, salesperson_name text, sales_amount INT generated always as (1) stored, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'); CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'); ALTER TABLE sales_feb2022 ALTER COLUMN sales_amount SET EXPRESSION AS (10); ALTER TABLE sales_mar2022 ALTER COLUMN sales_amount SET EXPRESSION AS (20); ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022) INTO sales_feb_mar2022; with v40, sales_feb_mar2022 column sales_int generated expression is (generated always as (1) stored) maybe this is what we expected. but we should have some tests on it. ---------------------------------------------------------------- DROP TABLE IF EXISTS sales_range cascade; CREATE TABLE sales_range (salesperson_id INT, salesperson_name text, sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'); CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'); CREATE VIEW x AS SELECT * FROM sales_mar2022; ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022) INTO sales_feb_mar2022; ERROR: cannot drop table public.sales_mar2022 because other objects depend on it DETAIL: view public.x depends on table public.sales_mar2022 HINT: Use DROP ... CASCADE to drop the dependent objects too. Maybe this is expected, but we need to mention it somewhere and have some tests on it. saying that MERGE PARTITIONS will effectively drop the partitions, so if any object depends on that partition then MERGE PARTITIONS can not be done. ---------------------------------------------------------------- + */ +static Relation +createPartitionTable(RangeVar *newPartName, Relation modelRel, Oid ownerId) +{ + Relation newRel; + Oid newRelId; + TupleDesc descriptor; + List *colList = NIL; + Oid relamId; + Oid namespaceId; + + /* If existing rel is temp, it must belong to this session */ + if (modelRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && + !modelRel->rd_islocaltemp) + ereport(ERROR, + errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot create as partition of temporary relation of another session")); Looking at it, modelRel is the partitioned table we called ALTER TABLE. for example: ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022) INTO sales_feb_mar2022; modelRel is sales_range. so this error check can be performed as early as the transformPartitionCmdForMerge stage? ---------------------------------------------------------------- + /* Look up the access method for new relation. */ + relamId = (modelRel->rd_rel->relam != InvalidOid) ? modelRel->rd_rel->relam : HEAP_TABLE_AM_OID; looking at the output of "select * from pg_am;". i think, we can do the following way: if (modelRel->rd_rel->relam) elog(ERROR, "error"); relamId = modelRel->rd_rel->relam; ---------------------------------------------------------------- Attached is some refactoring in moveMergedTablesRows, hope it's straightforward. for example: + /* Extract data from old tuple. */ + slot_getallattrs(srcslot); + + if (tuple_map) + { + /* Need to use map to copy attributes. */ + insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot); + } execute_attr_map_slot will call "slot_getallattrs(srcslot);" so the first one is unncessary. + srcslot = MakeSingleTupleTableSlot(RelationGetDescr(mergingPartition), + table_slot_callbacks(mergingPartition)); can change to srcslot = table_slot_create(mergingPartition, NULL);
Вложения
В списке pgsql-hackers по дате отправления: