MCPcopy Create free account
hub / github.com/apache/cloudberry / generatePartitions

Function generatePartitions

src/backend/parser/parse_partition_gp.c:1480–1744  ·  view source on GitHub ↗

* Create a list of CreateStmts, to create partitions based on 'gpPartDef' * specification. */

Source from the content-addressed store, hash-verified

1478 * specification.
1479 */
1480List *
1481generatePartitions(Oid parentrelid, GpPartitionDefinition *gpPartSpec,
1482 PartitionSpec *subPartSpec, const char *queryString,
1483 List *parentoptions, const char *parentaccessmethod,
1484 List *parentattenc, CreateStmtOrigin origin)
1485{
1486 Relation parentrel;
1487 List *result = NIL;
1488 ParseState *pstate;
1489 ListCell *lc;
1490 List *ancestors = get_partition_ancestors(parentrelid);
1491 partname_comp partcomp = {.tablename=NULL, .level=0, .partnum=0};
1492 bool isSubTemplate = false;
1493 List *penc_cls_before_merge = NIL;
1494 List *penc_cls = NIL;
1495 List *parent_tblenc = NIL;
1496 bool hasImplicitRangeBounds;
1497
1498 partcomp.level = list_length(ancestors) + 1;
1499 if (0 < gp_max_partition_level && partcomp.level > gp_max_partition_level)
1500 {
1501 ereport(ERROR,
1502 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
1503 errmsg("Exceeds maximum configured partitioning level of %d", gp_max_partition_level)));
1504 }
1505
1506 pstate = make_parsestate(NULL);
1507 pstate->p_sourcetext = queryString;
1508
1509 parentrel = table_open(parentrelid, NoLock);
1510
1511 /* Remove "tablename" cell from parentOptions, if exists */
1512 extract_tablename_from_options(&parentoptions);
1513
1514 if (subPartSpec && subPartSpec->gpPartDef)
1515 {
1516 Assert(subPartSpec->gpPartDef->isTemplate);
1517 isSubTemplate = subPartSpec->gpPartDef->isTemplate;
1518 /*
1519 * If the subpartition specification is read from gp_partition_template
1520 * catalog, we don't need to call StoreGpPartitionTemplate. This will
1521 * help to save some IO since StoreGpPartitionTemplate trying to scan
1522 * gp_partition_template.
1523 */
1524 if (isSubTemplate && !subPartSpec->gpPartDef->fromCatalog)
1525 StoreGpPartitionTemplate(ancestors ? llast_oid(ancestors) : parentrelid,
1526 partcomp.level, subPartSpec->gpPartDef);
1527 }
1528
1529 foreach(lc, parentattenc)
1530 {
1531 Node *n = lfirst(lc);
1532 if (IsA(n, ColumnReferenceStorageDirective))
1533 parent_tblenc = lappend(parent_tblenc, lfirst(lc));
1534 }
1535
1536 foreach(lc, gpPartSpec->partDefElems)
1537 {

Callers 2

ProcessUtilitySlowFunction · 0.85
ATExecGPPartCmdsFunction · 0.85

Calls 15

get_partition_ancestorsFunction · 0.85
list_lengthFunction · 0.85
make_parsestateFunction · 0.85
table_openFunction · 0.85
StoreGpPartitionTemplateFunction · 0.85
lappendFunction · 0.85
list_copyFunction · 0.85
merge_partition_encodingFunction · 0.85
parser_errpositionFunction · 0.85
lconsFunction · 0.85
generateDefaultPartitionFunction · 0.85

Tested by

no test coverage detected