1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Simplify index_[constraint_]create API

Instead of passing large swaths of boolean arguments, define some flags
that can be used in a bitmask.  This makes it easier not only to figure
out what each call site is doing, but also to add some new flags.

The flags are split in two -- one set for index_create directly and
another for constraints.  index_create() itself receives both, and then
passes down the latter to index_constraint_create(), which can also be
called standalone.

Discussion: https://postgr.es/m/20171023151251.j75uoe27gajdjmlm@alvherre.pgsql
Reviewed-by: Simon Riggs
This commit is contained in:
Alvaro Herrera
2017-11-14 15:19:05 +01:00
parent 591c504fad
commit a61f5ab986
5 changed files with 104 additions and 79 deletions

View File

@ -6836,6 +6836,7 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel,
char *constraintName;
char constraintType;
ObjectAddress address;
bits16 flags;
Assert(IsA(stmt, IndexStmt));
Assert(OidIsValid(index_oid));
@ -6880,16 +6881,18 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel,
constraintType = CONSTRAINT_UNIQUE;
/* Create the catalog entries for the constraint */
flags = INDEX_CONSTR_CREATE_UPDATE_INDEX |
INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS |
(stmt->initdeferred ? INDEX_CONSTR_CREATE_INIT_DEFERRED : 0) |
(stmt->deferrable ? INDEX_CONSTR_CREATE_DEFERRABLE : 0) |
(stmt->primary ? INDEX_CONSTR_CREATE_MARK_AS_PRIMARY : 0);
address = index_constraint_create(rel,
index_oid,
indexInfo,
constraintName,
constraintType,
stmt->deferrable,
stmt->initdeferred,
stmt->primary,
true, /* update pg_index */
true, /* remove old dependencies */
flags,
allowSystemTableMods,
false); /* is_internal */