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

Function transformDistributedBy

src/backend/parser/parse_utilcmd.c:2415–3105  ·  view source on GitHub ↗

* Process a DISTRIBUTED BY clause. * * If no DISTRIBUTED BY was given, this deduces a suitable default based on * various things. * * NOTE: We cannot form a GpPolicy object yet, because we don't know the * attribute numbers the columns will get. With inheritance, the table might * inherit more columns from a parent table, which are not visible in the * CreateStmt. */

Source from the content-addressed store, hash-verified

2413 * CreateStmt.
2414 */
2415static DistributedBy *
2416transformDistributedBy(ParseState *pstate,
2417 CreateStmtContext *cxt,
2418 DistributedBy *distributedBy,
2419 DistributedBy *likeDistributedBy,
2420 bool bQuiet)
2421{
2422 ListCell *keys = NULL;
2423 List *distrkeys = NIL;
2424 ListCell *lc;
2425 int numsegments;
2426
2427 /*
2428 * utility mode creates can't have a policy. Only the QD can have policies
2429 */
2430 if (Gp_role != GP_ROLE_DISPATCH && !IsBinaryUpgrade)
2431 return NULL;
2432
2433 if (distributedBy && distributedBy->numsegments > 0)
2434 /* If numsegments is set in DISTRIBUTED BY use the specified value */
2435 numsegments = distributedBy->numsegments;
2436 else
2437 /* Otherwise use DEFAULT as numsegments */
2438 numsegments = GP_POLICY_DEFAULT_NUMSEGMENTS();
2439
2440 /* Explicitly specified distributed randomly, no further check needed */
2441 if (distributedBy &&
2442 (distributedBy->ptype == POLICYTYPE_PARTITIONED && distributedBy->keyCols == NIL))
2443 {
2444 distributedBy->numsegments = numsegments;
2445 return distributedBy;
2446 }
2447
2448 /* Check replicated policy */
2449 if (distributedBy && distributedBy->ptype == POLICYTYPE_REPLICATED)
2450 {
2451 if (cxt->inhRelations != NIL)
2452 ereport(ERROR,
2453 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2454 errmsg("INHERITS clause cannot be used with DISTRIBUTED REPLICATED clause")));
2455
2456 distributedBy->numsegments = numsegments;
2457 return distributedBy;
2458 }
2459
2460 if (distributedBy)
2461 distrkeys = distributedBy->keyCols;
2462
2463 /*
2464 * If distributedBy is NIL, the user did not explicitly say what he
2465 * wanted for a distribution policy. So, we need to assign one.
2466 */
2467 if (distrkeys == NIL)
2468 {
2469 /*
2470 * If we have a PRIMARY KEY or UNIQUE constraints, derive the distribution key
2471 * from them.
2472 *

Callers 2

transformCreateStmtFunction · 0.85

Calls 15

lappendFunction · 0.85
GpPolicyIsReplicatedFunction · 0.85
relation_openrvFunction · 0.85
RelationGetIndexListFunction · 0.85
index_openFunction · 0.85
index_closeFunction · 0.85
table_closeFunction · 0.85
typenameTypeIdFunction · 0.85
parser_errpositionFunction · 0.85
errcodeFunction · 0.50

Tested by

no test coverage detected