* 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. */
| 2413 | * CreateStmt. |
| 2414 | */ |
| 2415 | static DistributedBy * |
| 2416 | transformDistributedBy(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 | * |
no test coverage detected