* ALTER TABLE xxx EXPAND PARTITION PREPARE * * Update a partition table's "numsegments" value to current cluster size, * change policy type of leaf partitions to randomly, * the policy type of root and interior partitions are the same as before. * * For external(foreign) tables, only writable external tables have distribution * policy. So for writable external leaf partitions, expansion is
| 18505 | * Add parameter numsegments, see ATExecExpandTable for details. |
| 18506 | */ |
| 18507 | static void |
| 18508 | ATExecExpandPartitionTablePrepare(Relation rel, int numsegments) |
| 18509 | { |
| 18510 | Oid relid = RelationGetRelid(rel); |
| 18511 | |
| 18512 | if (GpPolicyIsRandomPartitioned(rel->rd_cdbpolicy) || rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) |
| 18513 | { |
| 18514 | GpPolicy *new_policy; |
| 18515 | MemoryContext oldcontext; |
| 18516 | |
| 18517 | /* |
| 18518 | * we only change numsegments for root/interior/leaf partitions distributed randomly |
| 18519 | * and root/interior partitions distributed by hash, and change the numsegments of policy to |
| 18520 | * current cluster size |
| 18521 | */ |
| 18522 | oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel)); |
| 18523 | new_policy = GpPolicyCopy(rel->rd_cdbpolicy); |
| 18524 | new_policy->numsegments = numsegments; |
| 18525 | MemoryContextSwitchTo(oldcontext); |
| 18526 | |
| 18527 | GpPolicyReplace(relid, new_policy); |
| 18528 | /* We should make the policy between on-disk catalog and on-memory relation cache consistently */ |
| 18529 | rel->rd_cdbpolicy = new_policy; |
| 18530 | } |
| 18531 | else |
| 18532 | { |
| 18533 | if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) |
| 18534 | { |
| 18535 | /* |
| 18536 | * For external|foreign leaves, only writable external |
| 18537 | * table has policy entry and need to be handled. |
| 18538 | */ |
| 18539 | if (rel_is_external_table(relid)) |
| 18540 | { |
| 18541 | ExtTableEntry *ext = GetExtTableEntry(relid); |
| 18542 | if (ext->iswritable) |
| 18543 | { |
| 18544 | GpPolicy *new_policy; |
| 18545 | MemoryContext oldcontext; |
| 18546 | |
| 18547 | /* Just modify the numsegments for external writable leaves */ |
| 18548 | oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel)); |
| 18549 | new_policy = GpPolicyCopy(rel->rd_cdbpolicy); |
| 18550 | new_policy->numsegments = numsegments; |
| 18551 | MemoryContextSwitchTo(oldcontext); |
| 18552 | |
| 18553 | GpPolicyReplace(relid, new_policy); |
| 18554 | /* We should make the policy between on-disk catalog and on-memory relation cache consistently */ |
| 18555 | rel->rd_cdbpolicy = new_policy; |
| 18556 | } |
| 18557 | } |
| 18558 | } |
| 18559 | else |
| 18560 | { |
| 18561 | GpPolicy *new_policy; |
| 18562 | MemoryContext oldcontext; |
| 18563 | |
| 18564 | /* we change policy type to randomly for regular leaf partitions distributed by hash */ |
no test coverage detected