mirror of https://github.com/citusdata/citus.git
Merge pull request #3873 from citusdata/refactor/implement-explicit-index
Implement IndexIsImpliedByAConstraintpull/3875/head
commit
741e808049
|
@ -674,31 +674,12 @@ GetTableIndexAndConstraintCommands(Oid relationId)
|
||||||
{
|
{
|
||||||
Form_pg_index indexForm = (Form_pg_index) GETSTRUCT(heapTuple);
|
Form_pg_index indexForm = (Form_pg_index) GETSTRUCT(heapTuple);
|
||||||
Oid indexId = indexForm->indexrelid;
|
Oid indexId = indexForm->indexrelid;
|
||||||
bool isConstraint = false;
|
|
||||||
char *statementDef = NULL;
|
char *statementDef = NULL;
|
||||||
|
|
||||||
/*
|
bool indexImpliedByConstraint = IndexImpliedByAConstraint(indexForm);
|
||||||
* A primary key index is always created by a constraint statement.
|
|
||||||
* A unique key index or exclusion index is created by a constraint
|
|
||||||
* if and only if the index has a corresponding constraint entry in pg_depend.
|
|
||||||
* Any other index form is never associated with a constraint.
|
|
||||||
*/
|
|
||||||
if (indexForm->indisprimary)
|
|
||||||
{
|
|
||||||
isConstraint = true;
|
|
||||||
}
|
|
||||||
else if (indexForm->indisunique || indexForm->indisexclusion)
|
|
||||||
{
|
|
||||||
Oid constraintId = get_index_constraint(indexId);
|
|
||||||
isConstraint = OidIsValid(constraintId);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isConstraint = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the corresponding constraint or index statement */
|
/* get the corresponding constraint or index statement */
|
||||||
if (isConstraint)
|
if (indexImpliedByConstraint)
|
||||||
{
|
{
|
||||||
Oid constraintId = get_index_constraint(indexId);
|
Oid constraintId = get_index_constraint(indexId);
|
||||||
Assert(constraintId != InvalidOid);
|
Assert(constraintId != InvalidOid);
|
||||||
|
@ -736,6 +717,40 @@ GetTableIndexAndConstraintCommands(Oid relationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IndexImpliedByAConstraint is an helper function to be used while scanning
|
||||||
|
* pg_index. It returns true if the index identified by the given indexForm is
|
||||||
|
* implied by a constraint. Note that caller is responsible for passing a valid
|
||||||
|
* indexFrom, which means an alive heap tuple which is of form Form_pg_index.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
IndexImpliedByAConstraint(Form_pg_index indexForm)
|
||||||
|
{
|
||||||
|
Assert(indexForm != NULL);
|
||||||
|
|
||||||
|
bool indexImpliedByConstraint = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A primary key index is always created by a constraint statement.
|
||||||
|
* A unique key index or exclusion index is created by a constraint
|
||||||
|
* if and only if the index has a corresponding constraint entry in
|
||||||
|
* pg_depend. Any other index form is never associated with a constraint.
|
||||||
|
*/
|
||||||
|
if (indexForm->indisprimary)
|
||||||
|
{
|
||||||
|
indexImpliedByConstraint = true;
|
||||||
|
}
|
||||||
|
else if (indexForm->indisunique || indexForm->indisexclusion)
|
||||||
|
{
|
||||||
|
Oid constraintId = get_index_constraint(indexForm->indexrelid);
|
||||||
|
|
||||||
|
indexImpliedByConstraint = OidIsValid(constraintId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexImpliedByConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ShardStorageType returns the shard storage type according to relation type.
|
* ShardStorageType returns the shard storage type according to relation type.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -105,6 +105,7 @@ extern Oid ResolveRelationId(text *relationName, bool missingOk);
|
||||||
extern List * GetTableDDLEvents(Oid relationId, bool forShardCreation);
|
extern List * GetTableDDLEvents(Oid relationId, bool forShardCreation);
|
||||||
extern List * GetTableCreationCommands(Oid relationId, bool forShardCreation);
|
extern List * GetTableCreationCommands(Oid relationId, bool forShardCreation);
|
||||||
extern List * GetTableIndexAndConstraintCommands(Oid relationId);
|
extern List * GetTableIndexAndConstraintCommands(Oid relationId);
|
||||||
|
extern bool IndexImpliedByAConstraint(Form_pg_index indexForm);
|
||||||
extern char ShardStorageType(Oid relationId);
|
extern char ShardStorageType(Oid relationId);
|
||||||
extern void CheckDistributedTable(Oid relationId);
|
extern void CheckDistributedTable(Oid relationId);
|
||||||
extern void CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
|
extern void CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
|
||||||
|
|
Loading…
Reference in New Issue