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

Function transformIndexConstraints

src/backend/parser/parse_utilcmd.c:3175–3283  ·  view source on GitHub ↗

* transformIndexConstraints * Handle UNIQUE, PRIMARY KEY, EXCLUDE constraints, which create indexes. * We also merge in any index definitions arising from * LIKE ... INCLUDING INDEXES. */

Source from the content-addressed store, hash-verified

3173 * LIKE ... INCLUDING INDEXES.
3174 */
3175static void
3176transformIndexConstraints(CreateStmtContext *cxt)
3177{
3178 IndexStmt *index;
3179 List *indexlist = NIL;
3180 List *finalindexlist = NIL;
3181 ListCell *lc;
3182
3183 /*
3184 * Run through the constraints that need to generate an index. For PRIMARY
3185 * KEY, mark each column as NOT NULL and create an index. For UNIQUE or
3186 * EXCLUDE, create an index as for PRIMARY KEY, but do not insist on NOT
3187 * NULL.
3188 */
3189 foreach(lc, cxt->ixconstraints)
3190 {
3191 Constraint *constraint = lfirst_node(Constraint, lc);
3192
3193 Assert(constraint->contype == CONSTR_PRIMARY ||
3194 constraint->contype == CONSTR_UNIQUE ||
3195 constraint->contype == CONSTR_EXCLUSION);
3196
3197 index = transformIndexConstraint(constraint, cxt);
3198
3199 indexlist = lappend(indexlist, index);
3200 }
3201
3202 /*
3203 * Scan the index list and remove any redundant index specifications. This
3204 * can happen if, for instance, the user writes UNIQUE PRIMARY KEY. A
3205 * strict reading of SQL would suggest raising an error instead, but that
3206 * strikes me as too anal-retentive. - tgl 2001-02-14
3207 *
3208 * XXX in ALTER TABLE case, it'd be nice to look for duplicate
3209 * pre-existing indexes, too.
3210 */
3211 if (cxt->pkey != NULL)
3212 {
3213 /* Make sure we keep the PKEY index in preference to others... */
3214 finalindexlist = list_make1(cxt->pkey);
3215 }
3216
3217 foreach(lc, indexlist)
3218 {
3219 bool keep = true;
3220 bool defer = false;
3221 ListCell *k;
3222
3223 index = lfirst(lc);
3224
3225 /* if it's pkey, it's already in finalindexlist */
3226 if (index == cxt->pkey)
3227 continue;
3228
3229 foreach(k, finalindexlist)
3230 {
3231 IndexStmt *priorindex = lfirst(k);
3232

Callers 2

transformCreateStmtFunction · 0.85
transformAlterTableStmtFunction · 0.85

Calls 5

transformIndexConstraintFunction · 0.85
lappendFunction · 0.85
equalFunction · 0.85
list_concatFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected