* transformAlterTableStmt - * parse analysis for ALTER TABLE * * Returns the transformed AlterTableStmt. There may be additional actions * to be done before and after the transformed statement, which are returned * in *beforeStmts and *afterStmts as lists of utility command parsetrees. * * To avoid race conditions, it's important that this function rely only on * the passed-in relid (and
| 4421 | * relation. |
| 4422 | */ |
| 4423 | AlterTableStmt * |
| 4424 | transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, |
| 4425 | const char *queryString, |
| 4426 | List **beforeStmts, List **afterStmts) |
| 4427 | { |
| 4428 | Relation rel; |
| 4429 | TupleDesc tupdesc; |
| 4430 | ParseState *pstate; |
| 4431 | CreateStmtContext cxt; |
| 4432 | List *save_alist; |
| 4433 | ListCell *lcmd, |
| 4434 | *l; |
| 4435 | List *newcmds = NIL; |
| 4436 | bool skipValidation = true; |
| 4437 | AlterTableCmd *newcmd; |
| 4438 | ParseNamespaceItem *nsitem; |
| 4439 | |
| 4440 | /* |
| 4441 | * transformAlterTableStmt should not be called by QE, |
| 4442 | * the QE should use the results dispatched from QD. |
| 4443 | */ |
| 4444 | Assert(Gp_role != GP_ROLE_EXECUTE); |
| 4445 | /* |
| 4446 | * We must not scribble on the passed-in AlterTableStmt, so copy it. (This |
| 4447 | * is overkill, but easy.) |
| 4448 | */ |
| 4449 | stmt = copyObject(stmt); |
| 4450 | |
| 4451 | /* Caller is responsible for locking the relation */ |
| 4452 | rel = relation_open(relid, NoLock); |
| 4453 | tupdesc = RelationGetDescr(rel); |
| 4454 | |
| 4455 | /* Set up pstate */ |
| 4456 | pstate = make_parsestate(NULL); |
| 4457 | pstate->p_sourcetext = queryString; |
| 4458 | nsitem = addRangeTableEntryForRelation(pstate, |
| 4459 | rel, |
| 4460 | AccessShareLock, |
| 4461 | NULL, |
| 4462 | false, |
| 4463 | true); |
| 4464 | addNSItemToQuery(pstate, nsitem, false, true, true); |
| 4465 | |
| 4466 | /* Set up CreateStmtContext */ |
| 4467 | cxt.pstate = pstate; |
| 4468 | if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) |
| 4469 | { |
| 4470 | cxt.stmtType = "ALTER FOREIGN TABLE"; |
| 4471 | cxt.isforeign = true; |
| 4472 | } |
| 4473 | else |
| 4474 | { |
| 4475 | cxt.stmtType = "ALTER TABLE"; |
| 4476 | cxt.isforeign = false; |
| 4477 | } |
| 4478 | cxt.relation = stmt->relation; |
| 4479 | cxt.rel = rel; |
| 4480 | cxt.inhRelations = NIL; |
no test coverage detected