* ALTER TABLE EXPAND TABLE * * Update a table's "numsegments" value to current cluster size, and move * data as needed to the new segments. * * There are currently only one way we can perform EXPAND TABLE: * * 1. Create a whole new relation file, with the new 'numsegments', copy all * the data to the new reltion file, and swap it in place of the old one. * This is called the "CTAS m
| 18410 | * the numsegments is input of user. |
| 18411 | */ |
| 18412 | static void |
| 18413 | ATExecExpandTable(List **wqueue, Relation rel, AlterTableCmd *cmd, int numsegments) |
| 18414 | { |
| 18415 | AlteredTableInfo *tab; |
| 18416 | AlterTableCmd *rootCmd; |
| 18417 | MemoryContext oldContext; |
| 18418 | Oid relid = RelationGetRelid(rel); |
| 18419 | GpPolicy *newPolicy; |
| 18420 | GpPolicy *policy = rel->rd_cdbpolicy; |
| 18421 | |
| 18422 | if (Gp_role == GP_ROLE_UTILITY) |
| 18423 | ereport(ERROR, |
| 18424 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 18425 | errmsg("EXPAND not supported in utility mode"))); |
| 18426 | |
| 18427 | /* Permissions checks */ |
| 18428 | if (!pg_class_ownercheck(relid, GetUserId())) |
| 18429 | aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_TABLE, |
| 18430 | RelationGetRelationName(rel)); |
| 18431 | |
| 18432 | /* Can't ALTER TABLE SET system catalogs */ |
| 18433 | if (IsSystemRelation(rel)) |
| 18434 | ereport(ERROR, |
| 18435 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 18436 | errmsg("permission denied: \"%s\" is a system catalog", RelationGetRelationName(rel)))); |
| 18437 | |
| 18438 | oldContext = MemoryContextSwitchTo(GetMemoryChunkContext(rel)); |
| 18439 | newPolicy = GpPolicyCopy(policy); |
| 18440 | MemoryContextSwitchTo(oldContext); |
| 18441 | |
| 18442 | tab = linitial(*wqueue); |
| 18443 | rootCmd = (AlterTableCmd *)linitial(tab->subcmds[AT_PASS_MISC]); |
| 18444 | |
| 18445 | if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) |
| 18446 | { |
| 18447 | /* |
| 18448 | * Nothing to do on a partitioned table. But we better recurse to the |
| 18449 | * child partitions. |
| 18450 | */ |
| 18451 | } |
| 18452 | else if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) |
| 18453 | { |
| 18454 | if (rel_is_external_table(relid)) |
| 18455 | { |
| 18456 | ExtTableEntry *ext = GetExtTableEntry(relid); |
| 18457 | |
| 18458 | if (!ext->iswritable) |
| 18459 | { |
| 18460 | /* |
| 18461 | * Skip expanding readable external table, since data is not |
| 18462 | * located inside gpdb |
| 18463 | */ |
| 18464 | return; |
| 18465 | } |
| 18466 | } |
| 18467 | else |
| 18468 | { |
| 18469 | /* Skip expanding foreign table, since data is not located inside gpdb */ |
no test coverage detected