add partition reloptions when split partition or merge partition

This commit is contained in:
wuyuechuan 2021-08-13 12:17:23 +08:00
parent a189abd40e
commit 5eb44eed53
3 changed files with 78 additions and 67 deletions

View File

@ -21406,7 +21406,7 @@ static Oid AddTemporaryPartition(Relation partTableRel, RangePartitionDefState*
bucketOid,
partDef,
partTableRel->rd_rel->relowner,
(Datum)0,
(Datum)new_reloptions,
isTimestamptz);
// We must bump the command counter to make the newly-created
@ -21582,6 +21582,17 @@ static void fastAddPartition(Relation partTableRel, List* destPartDefList, List*
pgPartRel = relation_open(PartitionRelationId, RowExclusiveLock);
bool isNull = false;
HeapTuple tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(partTableRel->rd_id));
Datum relOptions = SysCacheGetAttr(RELOID, tuple, Anum_pg_class_reloptions, &isNull);
List* oldRelOptions = untransformRelOptions(relOptions);
Datum newRelOptions = transformRelOptions((Datum)0, oldRelOptions, NULL, NULL, false, false);
ReleaseSysCache(tuple);
if (oldRelOptions != NIL) {
list_free_ext(oldRelOptions);
}
foreach (cell, destPartDefList) {
RangePartitionDefState* partDef = (RangePartitionDefState*)lfirst(cell);
@ -21592,7 +21603,7 @@ static void fastAddPartition(Relation partTableRel, List* destPartDefList, List*
bucketOid,
partDef,
partTableRel->rd_rel->relowner,
(Datum)0,
(Datum)newRelOptions,
isTimestamptz);
*newPartOidList = lappend_oid(*newPartOidList, newPartOid);

View File

@ -707,41 +707,41 @@ order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;
ALTER TABLE alter_table SPLIT PARTITION p0 AT (2500) INTO (PARTITION p10, PARTITION p11) update global index;
select part.relname, part.indextblid, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible,
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples, part.reloptions
from pg_class class, pg_partition part, pg_index ind where class.relname = 'alter_table' and ind.indrelid = class.oid and part.parentid = ind.indrelid
order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;
relname | indextblid | parttype | rangenum | intervalnum | partstrategy | relallvisible | reltoastrelid | partkey | interval | boundaries | reltuples
-------------+------------+----------+----------+-------------+--------------+---------------+---------------+---------+----------+------------+-----------
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0
p10 | 0 | p | 0 | 0 | r | 0 | 0 | | | {2500} | 2499
p10 | 0 | p | 0 | 0 | r | 0 | 0 | | | {2500} | 2499
p10 | 0 | p | 0 | 0 | r | 0 | 0 | | | {2500} | 2499
p11 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 2500
p11 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 2500
p11 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 2500
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0
relname | indextblid | parttype | rangenum | intervalnum | partstrategy | relallvisible | reltoastrelid | partkey | interval | boundaries | reltuples | reloptions
-------------+------------+----------+----------+-------------+--------------+---------------+---------------+---------+----------+------------+-----------+---------------------------------------------------
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p10 | 0 | p | 0 | 0 | r | 0 | 0 | | | {2500} | 2499 | {orientation=row,compression=no,wait_clean_gpi=y}
p10 | 0 | p | 0 | 0 | r | 0 | 0 | | | {2500} | 2499 | {orientation=row,compression=no,wait_clean_gpi=y}
p10 | 0 | p | 0 | 0 | r | 0 | 0 | | | {2500} | 2499 | {orientation=row,compression=no,wait_clean_gpi=y}
p11 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 2500 | {orientation=row,compression=no,wait_clean_gpi=y}
p11 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 2500 | {orientation=row,compression=no,wait_clean_gpi=y}
p11 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 2500 | {orientation=row,compression=no,wait_clean_gpi=y}
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000 | {orientation=row,compression=no}
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000 | {orientation=row,compression=no}
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000 | {orientation=row,compression=no}
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000 | {orientation=row,compression=no}
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000 | {orientation=row,compression=no}
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000 | {orientation=row,compression=no}
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000 | {orientation=row,compression=no}
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000 | {orientation=row,compression=no}
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000 | {orientation=row,compression=no}
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000 | {orientation=row,compression=no}
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000 | {orientation=row,compression=no}
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000 | {orientation=row,compression=no}
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001 | {orientation=row,compression=no}
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001 | {orientation=row,compression=no}
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001 | {orientation=row,compression=no}
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0 | {orientation=row,compression=no}
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0 | {orientation=row,compression=no}
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0 | {orientation=row,compression=no}
(30 rows)
explain (costs off) select count(*) from alter_table where INV_DATE_SK < 10000;
@ -888,38 +888,38 @@ order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;
ALTER TABLE alter_table MERGE PARTITIONS p10, p11 INTO PARTITION p1 update global index;
select part.relname, part.indextblid, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible,
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples, part.reloptions
from pg_class class, pg_partition part, pg_index ind where class.relname = 'alter_table' and ind.indrelid = class.oid and part.parentid = ind.indrelid
order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;
relname | indextblid | parttype | rangenum | intervalnum | partstrategy | relallvisible | reltoastrelid | partkey | interval | boundaries | reltuples
-------------+------------+----------+----------+-------------+--------------+---------------+---------------+---------+----------+------------+-----------
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0
p1 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 0
p1 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 0
p1 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 0
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0
relname | indextblid | parttype | rangenum | intervalnum | partstrategy | relallvisible | reltoastrelid | partkey | interval | boundaries | reltuples | reloptions
-------------+------------+----------+----------+-------------+--------------+---------------+---------------+---------+----------+------------+-----------+---------------------------------------------------
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
alter_table | 0 | r | 0 | 0 | r | 0 | 0 | 1 | | | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p1 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 0 | {orientation=row,compression=no}
p1 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 0 | {orientation=row,compression=no}
p1 | 0 | p | 0 | 0 | r | 0 | 0 | | | {5000} | 0 | {orientation=row,compression=no}
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p2 | 0 | p | 0 | 0 | r | 0 | 0 | | | {20000} | 0 | {orientation=row,compression=no,wait_clean_gpi=y}
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000 | {orientation=row,compression=no}
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000 | {orientation=row,compression=no}
p3 | 0 | p | 0 | 0 | r | 0 | 0 | | | {30000} | 10000 | {orientation=row,compression=no}
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000 | {orientation=row,compression=no}
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000 | {orientation=row,compression=no}
p4 | 0 | p | 0 | 0 | r | 0 | 0 | | | {40000} | 10000 | {orientation=row,compression=no}
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000 | {orientation=row,compression=no}
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000 | {orientation=row,compression=no}
p5 | 0 | p | 0 | 0 | r | 0 | 0 | | | {50000} | 10000 | {orientation=row,compression=no}
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000 | {orientation=row,compression=no}
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000 | {orientation=row,compression=no}
p6 | 0 | p | 0 | 0 | r | 0 | 0 | | | {60000} | 10000 | {orientation=row,compression=no}
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001 | {orientation=row,compression=no}
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001 | {orientation=row,compression=no}
p7 | 0 | p | 0 | 0 | r | 0 | 0 | | | {100001} | 40001 | {orientation=row,compression=no}
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0 | {orientation=row,compression=no}
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0 | {orientation=row,compression=no}
p8 | 0 | p | 0 | 0 | r | 0 | 0 | | | {500000} | 0 | {orientation=row,compression=no}
(27 rows)
explain (costs off) select count(*) from alter_table where INV_DATE_SK < 10000;

View File

@ -175,7 +175,7 @@ order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;
ALTER TABLE alter_table SPLIT PARTITION p0 AT (2500) INTO (PARTITION p10, PARTITION p11) update global index;
select part.relname, part.indextblid, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible,
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples, part.reloptions
from pg_class class, pg_partition part, pg_index ind where class.relname = 'alter_table' and ind.indrelid = class.oid and part.parentid = ind.indrelid
order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;
@ -211,7 +211,7 @@ order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;
ALTER TABLE alter_table MERGE PARTITIONS p10, p11 INTO PARTITION p1 update global index;
select part.relname, part.indextblid, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible,
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples
part.reltoastrelid, part.partkey, part.interval, part.boundaries, part.reltuples, part.reloptions
from pg_class class, pg_partition part, pg_index ind where class.relname = 'alter_table' and ind.indrelid = class.oid and part.parentid = ind.indrelid
order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11;