PostgreSQL Source Code git master
|
#include "postgres.h"
#include "access/genam.h"
#include "access/gist.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/heap.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
#include "commands/defrem.h"
#include "common/int.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Go to the source code of this file.
Functions | |
Oid | CreateConstraintEntry (const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isEnforced, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, const int16 *fkDeleteSetCols, int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int16 conInhCount, bool conNoInherit, bool conPeriod, bool is_internal) |
bool | ConstraintNameIsUsed (ConstraintCategory conCat, Oid objId, const char *conname) |
bool | ConstraintNameExists (const char *conname, Oid namespaceid) |
char * | ChooseConstraintName (const char *name1, const char *name2, const char *label, Oid namespaceid, List *others) |
HeapTuple | findNotNullConstraintAttnum (Oid relid, AttrNumber attnum) |
HeapTuple | findNotNullConstraint (Oid relid, const char *colname) |
HeapTuple | findDomainNotNullConstraint (Oid typid) |
AttrNumber | extractNotNullColumn (HeapTuple constrTup) |
bool | AdjustNotNullInheritance (Oid relid, AttrNumber attnum, bool is_local, bool is_no_inherit) |
List * | RelationGetNotNullConstraints (Oid relid, bool cooked, bool include_noinh) |
void | RemoveConstraintById (Oid conId) |
void | RenameConstraintById (Oid conId, const char *newname) |
void | AlterConstraintNamespaces (Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved) |
void | ConstraintSetParentConstraint (Oid childConstrId, Oid parentConstrId, Oid childTableId) |
Oid | get_relation_constraint_oid (Oid relid, const char *conname, bool missing_ok) |
Bitmapset * | get_relation_constraint_attnos (Oid relid, const char *conname, bool missing_ok, Oid *constraintOid) |
Oid | get_relation_idx_constraint_oid (Oid relationId, Oid indexId) |
Oid | get_domain_constraint_oid (Oid typid, const char *conname, bool missing_ok) |
Bitmapset * | get_primary_key_attnos (Oid relid, bool deferrableOk, Oid *constraintOid) |
void | DeconstructFkConstraintRow (HeapTuple tuple, int *numfks, AttrNumber *conkey, AttrNumber *confkey, Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs, int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols) |
void | FindFKPeriodOpers (Oid opclass, Oid *containedbyoperoid, Oid *aggedcontainedbyoperoid) |
bool | check_functional_grouping (Oid relid, Index varno, Index varlevelsup, List *grouping_columns, List **constraintDeps) |
bool AdjustNotNullInheritance | ( | Oid | relid, |
AttrNumber | attnum, | ||
bool | is_local, | ||
bool | is_no_inherit | ||
) |
Definition at line 731 of file pg_constraint.c.
References attnum, CatalogTupleUpdate(), ereport, errcode(), errmsg(), ERROR, findNotNullConstraintAttnum(), get_rel_name(), GETSTRUCT, HeapTupleIsValid, NameStr, pg_add_s16_overflow(), RowExclusiveLock, HeapTupleData::t_self, table_close(), and table_open().
Referenced by AddRelationNewConstraints().
void AlterConstraintNamespaces | ( | Oid | ownerId, |
Oid | oldNspId, | ||
Oid | newNspId, | ||
bool | isType, | ||
ObjectAddresses * | objsMoved | ||
) |
Definition at line 1014 of file pg_constraint.c.
References add_exact_object_address(), BTEqualStrategyNumber, CatalogTupleUpdate(), GETSTRUCT, heap_copytuple(), HeapTupleIsValid, InvalidOid, InvokeObjectPostAlterHook, sort-test::key, object_address_present(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by AlterTableNamespaceInternal(), and AlterTypeNamespaceInternal().
bool check_functional_grouping | ( | Oid | relid, |
Index | varno, | ||
Index | varlevelsup, | ||
List * | grouping_columns, | ||
List ** | constraintDeps | ||
) |
Definition at line 1684 of file pg_constraint.c.
References bms_add_member(), bms_is_subset(), FirstLowInvalidHeapAttributeNumber, get_primary_key_attnos(), IsA, lappend_oid(), lfirst, Var::varattno, Var::varlevelsup, and Var::varno.
Referenced by substitute_grouped_columns_mutator().
char * ChooseConstraintName | ( | const char * | name1, |
const char * | name2, | ||
const char * | label, | ||
Oid | namespaceid, | ||
List * | others | ||
) |
Definition at line 509 of file pg_constraint.c.
References AccessShareLock, BTEqualStrategyNumber, CStringGetDatum(), HeapTupleIsValid, label, lfirst, makeObjectName(), NAMEDATALEN, ObjectIdGetDatum(), pfree(), ScanKeyInit(), snprintf, strlcpy(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by addFkConstraint(), AddRelationNewConstraints(), AddRelationNotNullConstraints(), ATExecAddConstraint(), ATExecSetNotNull(), domainAddCheckConstraint(), and domainAddNotNullConstraint().
bool ConstraintNameExists | ( | const char * | conname, |
Oid | namespaceid | ||
) |
Definition at line 455 of file pg_constraint.c.
References AccessShareLock, BTEqualStrategyNumber, CStringGetDatum(), HeapTupleIsValid, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by ChooseRelationName().
bool ConstraintNameIsUsed | ( | ConstraintCategory | conCat, |
Oid | objId, | ||
const char * | conname | ||
) |
Definition at line 410 of file pg_constraint.c.
References AccessShareLock, BTEqualStrategyNumber, CONSTRAINT_DOMAIN, CONSTRAINT_RELATION, CStringGetDatum(), HeapTupleIsValid, InvalidOid, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by addFkConstraint(), AddRelationNewConstraints(), ATExecAddConstraint(), domainAddCheckConstraint(), domainAddNotNullConstraint(), index_create(), and RenameConstraintById().
Definition at line 1083 of file pg_constraint.c.
References Assert, CatalogTupleUpdate(), deleteDependencyRecordsForClass(), DEPENDENCY_PARTITION_PRI, DEPENDENCY_PARTITION_SEC, elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, heap_copytuple(), HeapTupleIsValid, InvalidOid, ObjectAddressSet, ObjectIdGetDatum(), OidIsValid, pg_add_s16_overflow(), recordDependencyOn(), ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().
Referenced by ATExecAttachPartitionIdx(), AttachPartitionEnsureIndexes(), DefineIndex(), DetachPartitionFinalize(), and tryAttachPartitionForeignKey().
Oid CreateConstraintEntry | ( | const char * | constraintName, |
Oid | constraintNamespace, | ||
char | constraintType, | ||
bool | isDeferrable, | ||
bool | isDeferred, | ||
bool | isEnforced, | ||
bool | isValidated, | ||
Oid | parentConstrId, | ||
Oid | relId, | ||
const int16 * | constraintKey, | ||
int | constraintNKeys, | ||
int | constraintNTotalKeys, | ||
Oid | domainId, | ||
Oid | indexRelId, | ||
Oid | foreignRelId, | ||
const int16 * | foreignKey, | ||
const Oid * | pfEqOp, | ||
const Oid * | ppEqOp, | ||
const Oid * | ffEqOp, | ||
int | foreignNKeys, | ||
char | foreignUpdateType, | ||
char | foreignDeleteType, | ||
const int16 * | fkDeleteSetCols, | ||
int | numFkDeleteSetCols, | ||
char | foreignMatchType, | ||
const Oid * | exclOp, | ||
Node * | conExpr, | ||
const char * | conBin, | ||
bool | conIsLocal, | ||
int16 | conInhCount, | ||
bool | conNoInherit, | ||
bool | conPeriod, | ||
bool | is_internal | ||
) |
Definition at line 51 of file pg_constraint.c.
References add_exact_object_address(), Assert, BoolGetDatum(), CatalogTupleInsert(), CharGetDatum(), ObjectAddress::classId, construct_array_builtin(), CStringGetTextDatum, DEPENDENCY_AUTO, DEPENDENCY_NORMAL, free_object_addresses(), GetNewOidWithIndex(), heap_form_tuple(), i, Int16GetDatum(), InvokeObjectPostCreateHookArg, NameGetDatum(), namestrcpy(), new_object_addresses(), ObjectAddressSet, ObjectAddressSubSet, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, palloc(), PointerGetDatum(), record_object_address_dependencies(), recordDependencyOnSingleRelExpr(), RelationGetDescr, RowExclusiveLock, table_close(), table_open(), and values.
Referenced by addFkConstraint(), CreateTriggerFiringOn(), domainAddCheckConstraint(), domainAddNotNullConstraint(), index_constraint_create(), StoreRelCheck(), and StoreRelNotNull().
void DeconstructFkConstraintRow | ( | HeapTuple | tuple, |
int * | numfks, | ||
AttrNumber * | conkey, | ||
AttrNumber * | confkey, | ||
Oid * | pf_eq_oprs, | ||
Oid * | pp_eq_oprs, | ||
Oid * | ff_eq_oprs, | ||
int * | num_fk_del_set_cols, | ||
AttrNumber * | fk_del_set_cols | ||
) |
Definition at line 1495 of file pg_constraint.c.
References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, DatumGetArrayTypeP, DatumGetPointer(), elog, ERROR, INDEX_MAX_KEYS, pfree(), SysCacheGetAttr(), and SysCacheGetAttrNotNull().
Referenced by CloneFkReferenced(), CloneFkReferencing(), DetachPartitionFinalize(), RelationGetFKeyList(), and ri_LoadConstraintInfo().
AttrNumber extractNotNullColumn | ( | HeapTuple | constrTup | ) |
Definition at line 696 of file pg_constraint.c.
References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, Assert, DatumGetArrayTypeP, elog, ERROR, GETSTRUCT, and SysCacheGetAttrNotNull().
Referenced by dropconstraint_internal(), findNotNullConstraintAttnum(), MergeConstraintsIntoExisting(), pg_get_constraintdef_worker(), RelationGetNotNullConstraints(), and RemoveInheritance().
Definition at line 652 of file pg_constraint.c.
References AccessShareLock, BTEqualStrategyNumber, GETSTRUCT, heap_copytuple(), HeapTupleIsValid, sort-test::key, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by AlterDomainNotNull().
Definition at line 1623 of file pg_constraint.c.
References COMPARE_CONTAINED_BY, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, get_opclass_opfamily_and_input_type(), GetOperatorFromCompareType(), and InvalidOid.
Referenced by ATAddForeignKeyConstraint(), and ri_LoadConstraintInfo().
Definition at line 636 of file pg_constraint.c.
References attnum, findNotNullConstraintAttnum(), get_attnum(), and InvalidAttrNumber.
Referenced by dropconstraint_internal().
HeapTuple findNotNullConstraintAttnum | ( | Oid | relid, |
AttrNumber | attnum | ||
) |
Definition at line 585 of file pg_constraint.c.
References AccessShareLock, attnum, BTEqualStrategyNumber, extractNotNullColumn(), GETSTRUCT, heap_copytuple(), HeapTupleIsValid, sort-test::key, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by AdjustNotNullInheritance(), ATExecDropNotNull(), ATExecSetNotNull(), findNotNullConstraint(), and MergeAttributesIntoExisting().
Definition at line 1350 of file pg_constraint.c.
References AccessShareLock, BTEqualStrategyNumber, CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, format_type_be(), GETSTRUCT, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum(), OidIsValid, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by get_object_address(), and rename_constraint_internal().
Definition at line 1409 of file pg_constraint.c.
References AccessShareLock, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, bms_add_member(), BTEqualStrategyNumber, DatumGetArrayTypeP, elog, ERROR, FirstLowInvalidHeapAttributeNumber, GETSTRUCT, heap_getattr(), HeapTupleIsValid, i, InvalidOid, ObjectIdGetDatum(), RelationGetDescr, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by check_functional_grouping().
Bitmapset * get_relation_constraint_attnos | ( | Oid | relid, |
const char * | conname, | ||
bool | missing_ok, | ||
Oid * | constraintOid | ||
) |
Definition at line 1214 of file pg_constraint.c.
References AccessShareLock, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, bms_add_member(), BTEqualStrategyNumber, CStringGetDatum(), DatumGetArrayTypeP, elog, ereport, errcode(), errmsg(), ERROR, FirstLowInvalidHeapAttributeNumber, get_rel_name(), GETSTRUCT, heap_getattr(), HeapTupleIsValid, i, InvalidOid, ObjectIdGetDatum(), OidIsValid, RelationGetDescr, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by transformOnConflictArbiter().
Definition at line 1157 of file pg_constraint.c.
References AccessShareLock, BTEqualStrategyNumber, CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, get_rel_name(), GETSTRUCT, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum(), OidIsValid, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by expandTableLikeClause(), get_object_address_relobject(), and rename_constraint_internal().
Definition at line 1303 of file pg_constraint.c.
References AccessShareLock, BTEqualStrategyNumber, GETSTRUCT, InvalidOid, sort-test::key, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by ATExecAttachPartitionIdx(), AttachPartitionEnsureIndexes(), DefineIndex(), and DetachPartitionFinalize().
Definition at line 793 of file pg_constraint.c.
References AccessShareLock, CookedConstraint::attnum, BTEqualStrategyNumber, Constraint::conname, CookedConstraint::conoid, CONSTR_NOTNULL, CookedConstraint::contype, Constraint::contype, Constraint::deferrable, CookedConstraint::expr, extractNotNullColumn(), get_attname(), GETSTRUCT, HeapTupleIsValid, CookedConstraint::inhcount, Constraint::initdeferred, Constraint::initially_valid, CookedConstraint::is_enforced, Constraint::is_enforced, CookedConstraint::is_local, CookedConstraint::is_no_inherit, Constraint::is_no_inherit, Constraint::keys, lappend(), list_make1, Constraint::location, makeNode, makeString(), CookedConstraint::name, NameStr, NIL, ObjectIdGetDatum(), palloc(), pstrdup(), ScanKeyInit(), CookedConstraint::skip_validation, Constraint::skip_validation, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().
Referenced by MergeAttributes(), and transformTableLikeClause().
void RemoveConstraintById | ( | Oid | conId | ) |
Definition at line 871 of file pg_constraint.c.
References AccessExclusiveLock, CatalogTupleDelete(), CatalogTupleUpdate(), elog, ERROR, GETSTRUCT, heap_freetuple(), HeapTupleIsValid, NoLock, ObjectIdGetDatum(), OidIsValid, RelationGetRelationName, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), and table_open().
Referenced by doDeletion().
void RenameConstraintById | ( | Oid | conId, |
const char * | newname | ||
) |
Definition at line 962 of file pg_constraint.c.
References CatalogTupleUpdate(), CONSTRAINT_DOMAIN, CONSTRAINT_RELATION, ConstraintNameIsUsed(), elog, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, format_type_be(), get_rel_name(), GETSTRUCT, heap_freetuple(), HeapTupleIsValid, InvokeObjectPostAlterHook, namestrcpy(), ObjectIdGetDatum(), OidIsValid, RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), and table_open().
Referenced by rename_constraint_internal(), and RenameRelationInternal().