MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / comdb2AddIndexInt

Function comdb2AddIndexInt

sqlite/src/comdb2build.c:5328–5663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5326}
5327
5328static void comdb2AddIndexInt(
5329 Parse *pParse, /* All information about this parse */
5330 char *keyname, /* Index name (Optional) */
5331 ExprList *pList, /* A list of columns to be indexed */
5332 int onError, /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
5333 Expr *pPIWhere, /* WHERE clause for partial indices */
5334 const char *zStart, /* Start of WHERE clause token text */
5335 const char *zEnd, /* End of WHERE clause token text */
5336 int sortOrder, /* Sort order of primary key when pList==NULL */
5337 u8 idxType, /* The index type */
5338 int withOpts, /* WITH options (DATACOPY) */
5339 ExprList *pdList /* A list of columns in the partial datacopy */
5340)
5341{
5342 struct comdb2_ddl_context *ctx = pParse->comdb2_ddl_ctx;
5343 struct comdb2_key *key;
5344
5345 if (use_sqlite_impl(pParse)) {
5346 assert(ctx == 0);
5347 assert(idxType != SQLITE_IDXTYPE_DUPKEY);
5348 sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0, 0, 0, 0,
5349 idxType);
5350 return;
5351 }
5352
5353 if (ctx == 0) {
5354 /* An error must have been set. */
5355 assert(pParse->rc != 0);
5356 return;
5357 }
5358
5359 if ((ctx->flags & DDL_NOOP) != 0) {
5360 return;
5361 }
5362
5363 key = comdb2_calloc(ctx->mem, 1, sizeof(struct comdb2_key));
5364 if (key == 0)
5365 goto oom;
5366
5367 if (keyname) {
5368 if (idxType != SQLITE_IDXTYPE_PRIMARYKEY && is_pk(keyname)) {
5369 pParse->rc = SQLITE_ERROR;
5370 sqlite3ErrorMsg(pParse, "Invalid key name '%s'.", keyname);
5371 goto cleanup;
5372 }
5373 key->name = keyname;
5374 } else {
5375 /* Key name not specified, will be generated later. */
5376 }
5377
5378 switch (idxType) {
5379 case SQLITE_IDXTYPE_APPDEF:
5380 /* For CREATE INDEX, we need to check onError */
5381 if (onError != OE_Abort) {
5382 key->flags |= KEY_DUP;
5383 } else {
5384 key->flags |= KEY_UNIQNULLS;
5385 }

Callers 3

comdb2AddPrimaryKeyFunction · 0.85
comdb2AddIndexFunction · 0.85
comdb2CreateIndexFunction · 0.85

Calls 15

sqlite3CreateIndexFunction · 0.85
comdb2_callocFunction · 0.85
is_pkFunction · 0.85
sqlite3ErrorMsgFunction · 0.85
listc_initFunction · 0.85
listc_ablFunction · 0.85
find_column_by_nameFunction · 0.85
sqlite3GetVdbeFunction · 0.85
sqlite3ExprDescribeFunction · 0.85
comdb2_strndupFunction · 0.85
escape_exprFunction · 0.85

Tested by

no test coverage detected