mirror of https://github.com/citusdata/citus.git
Refactor the code that extends constraint/index names on shards into a func
parent
ba1ea9b5bd
commit
56f1daa800
|
@ -54,6 +54,9 @@
|
|||
#include "utils/relcache.h"
|
||||
|
||||
/* Local functions forward declarations */
|
||||
static void RelayEventExtendConstraintAndIndexNames(AlterTableStmt *alterTableStmt,
|
||||
Constraint *constraint,
|
||||
uint64 shardId);
|
||||
static bool UpdateWholeRowColumnReferencesWalker(Node *node, uint64 *shardId);
|
||||
|
||||
/* exports for SQL callable functions */
|
||||
|
@ -150,44 +153,8 @@ RelayEventExtendNames(Node *parseTree, char *schemaName, uint64 shardId)
|
|||
if (command->subtype == AT_AddConstraint)
|
||||
{
|
||||
Constraint *constraint = (Constraint *) command->def;
|
||||
char **constraintName = &(constraint->conname);
|
||||
const bool missingOk = false;
|
||||
relationId = RangeVarGetRelid(alterTableStmt->relation,
|
||||
AccessShareLock,
|
||||
missingOk);
|
||||
|
||||
if (constraint->indexname)
|
||||
{
|
||||
char **indexName = &(constraint->indexname);
|
||||
AppendShardIdToName(indexName, shardId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Append shardId to constraint names if
|
||||
* - table is not partitioned or
|
||||
* - constraint is not a CHECK constraint
|
||||
*
|
||||
* We do not want to append shardId to partitioned table shards because
|
||||
* the names of constraints will be inherited, and the shardId will no
|
||||
* longer be valid for the child table.
|
||||
*
|
||||
* See MergeConstraintsIntoExisting function in Postgres that requires
|
||||
* inherited check constraints in child tables to have the same name
|
||||
* with those in parent tables.
|
||||
*/
|
||||
if (!PartitionedTable(relationId) ||
|
||||
constraint->contype != CONSTR_CHECK)
|
||||
{
|
||||
/*
|
||||
* constraint->conname could be empty in the case of
|
||||
* ADD {PRIMARY KEY, UNIQUE} USING INDEX.
|
||||
* In this case, already extended index name will be used by postgres.
|
||||
*/
|
||||
if (constraint->conname != NULL)
|
||||
{
|
||||
AppendShardIdToName(constraintName, shardId);
|
||||
}
|
||||
}
|
||||
RelayEventExtendConstraintAndIndexNames(alterTableStmt, constraint,
|
||||
shardId);
|
||||
}
|
||||
else if (command->subtype == AT_DropConstraint ||
|
||||
command->subtype == AT_ValidateConstraint)
|
||||
|
@ -622,6 +589,56 @@ RelayEventExtendNames(Node *parseTree, char *schemaName, uint64 shardId)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* RelayEventExtendConstraintAndIndexNames extends the names of constraints
|
||||
* and indexes in given constraint with the shardId.
|
||||
*/
|
||||
static void
|
||||
RelayEventExtendConstraintAndIndexNames(AlterTableStmt *alterTableStmt,
|
||||
Constraint *constraint,
|
||||
uint64 shardId)
|
||||
{
|
||||
char **constraintName = &(constraint->conname);
|
||||
const bool missingOk = false;
|
||||
Oid relationId = RangeVarGetRelid(alterTableStmt->relation,
|
||||
AccessShareLock,
|
||||
missingOk);
|
||||
|
||||
if (constraint->indexname)
|
||||
{
|
||||
char **indexName = &(constraint->indexname);
|
||||
AppendShardIdToName(indexName, shardId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Append shardId to constraint names if
|
||||
* - table is not partitioned or
|
||||
* - constraint is not a CHECK constraint
|
||||
*
|
||||
* We do not want to append shardId to partitioned table shards because
|
||||
* the names of constraints will be inherited, and the shardId will no
|
||||
* longer be valid for the child table.
|
||||
*
|
||||
* See MergeConstraintsIntoExisting function in Postgres that requires
|
||||
* inherited check constraints in child tables to have the same name
|
||||
* with those in parent tables.
|
||||
*/
|
||||
if (!PartitionedTable(relationId) ||
|
||||
constraint->contype != CONSTR_CHECK)
|
||||
{
|
||||
/*
|
||||
* constraint->conname could be empty in the case of
|
||||
* ADD {PRIMARY KEY, UNIQUE} USING INDEX.
|
||||
* In this case, already extended index name will be used by postgres.
|
||||
*/
|
||||
if (constraint->conname != NULL)
|
||||
{
|
||||
AppendShardIdToName(constraintName, shardId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* RelayEventExtendNamesForInterShardCommands extends relation names in the given parse
|
||||
* tree for certain utility commands. The function more specifically extends table, index
|
||||
|
|
Loading…
Reference in New Issue