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

Function transformIndexConstraint

src/backend/parser/parse_utilcmd.c:3295–3820  ·  view source on GitHub ↗

* transformIndexConstraint * Transform one UNIQUE, PRIMARY KEY, or EXCLUDE constraint for * transformIndexConstraints. * * We return an IndexStmt. For a PRIMARY KEY constraint, we additionally * produce NOT NULL constraints, either by marking ColumnDefs in cxt->columns * as is_not_null or by adding an ALTER TABLE SET NOT NULL command to * cxt->alist. */

Source from the content-addressed store, hash-verified

3293 * cxt->alist.
3294 */
3295static IndexStmt *
3296transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
3297{
3298 IndexStmt *index;
3299 List *notnullcmds = NIL;
3300 ListCell *lc;
3301
3302 index = makeNode(IndexStmt);
3303
3304 index->unique = (constraint->contype != CONSTR_EXCLUSION);
3305 index->primary = (constraint->contype == CONSTR_PRIMARY);
3306 if (index->primary)
3307 {
3308 if (cxt->pkey != NULL)
3309 ereport(ERROR,
3310 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3311 errmsg("multiple primary keys for table \"%s\" are not allowed",
3312 cxt->relation->relname),
3313 parser_errposition(cxt->pstate, constraint->location)));
3314 cxt->pkey = index;
3315
3316 /*
3317 * In ALTER TABLE case, a primary index might already exist, but
3318 * DefineIndex will check for it.
3319 */
3320 }
3321 index->isconstraint = true;
3322 index->deferrable = constraint->deferrable;
3323 index->initdeferred = constraint->initdeferred;
3324
3325 if (constraint->conname != NULL)
3326 index->idxname = pstrdup(constraint->conname);
3327 else
3328 index->idxname = NULL; /* DefineIndex will choose name */
3329
3330 index->relation = cxt->relation;
3331 index->accessMethod = constraint->access_method ? constraint->access_method : default_index_access_method;
3332 index->options = constraint->options;
3333 index->tableSpace = constraint->indexspace;
3334 index->whereClause = constraint->where_clause;
3335 index->indexParams = NIL;
3336 index->indexIncludingParams = NIL;
3337 index->excludeOpNames = NIL;
3338 index->idxcomment = NULL;
3339 index->indexOid = InvalidOid;
3340 index->oldNode = InvalidOid;
3341 index->oldCreateSubid = InvalidSubTransactionId;
3342 index->oldFirstRelfilenodeSubid = InvalidSubTransactionId;
3343 index->transformed = false;
3344 index->concurrent = false;
3345 index->if_not_exists = false;
3346 index->reset_default_tblspc = constraint->reset_default_tblspc;
3347
3348 /*
3349 * If it's ALTER TABLE ADD CONSTRAINT USING INDEX, look up the index and
3350 * verify it's usable, then extract the implied column name list. (We
3351 * will not actually need the column name list at runtime, but we need it
3352 * now to check for duplicate column entries below.)

Callers 1

Calls 15

parser_errpositionFunction · 0.85
get_relname_relidFunction · 0.85
index_openFunction · 0.85
get_index_constraintFunction · 0.85
IsIndexAccessMethodFunction · 0.85
SysCacheGetAttrFunction · 0.85
get_attoptionsFunction · 0.85
GetDefaultOpClassFunction · 0.85
lappendFunction · 0.85

Tested by

no test coverage detected