mirror of https://github.com/citusdata/citus.git
Remove pg_dist_shard.shardalias, LoadShardAlias, and all usage of these.
Draft of migration script to drop the column. Removed regression test of non-null shardalias.pull/738/head
parent
3ea352e5f9
commit
544570708b
|
@ -0,0 +1,5 @@
|
|||
/* citus--5.2-1--5.3-0.sql */
|
||||
|
||||
ALTER TABLE pg_catalog.pg_dist_shard
|
||||
DROP COLUMN IF EXISTS shardalias;
|
||||
|
|
@ -42,7 +42,6 @@ CREATE TABLE citus.pg_dist_shard(
|
|||
logicalrelid oid NOT NULL,
|
||||
shardid int8 NOT NULL,
|
||||
shardstorage "char" NOT NULL,
|
||||
shardalias text,
|
||||
shardminvalue text,
|
||||
shardmaxvalue text
|
||||
);
|
||||
|
|
|
@ -325,18 +325,9 @@ DropShards(Oid relationId, char *schemaName, char *relationName,
|
|||
|
||||
Assert(shardInterval->relationId == relationId);
|
||||
|
||||
/* if shard doesn't have an alias, extend regular table name */
|
||||
shardAlias = LoadShardAlias(relationId, shardId);
|
||||
if (shardAlias == NULL)
|
||||
{
|
||||
/* Build shard relation name. */
|
||||
appendStringInfoString(shardName, relationName);
|
||||
AppendShardIdToStringInfo(shardName, shardId);
|
||||
}
|
||||
else
|
||||
{
|
||||
appendStringInfoString(shardName, shardAlias);
|
||||
}
|
||||
|
||||
quotedShardName = quote_qualified_identifier(schemaName, shardName->data);
|
||||
|
||||
shardPlacementList = ShardPlacementList(shardId);
|
||||
|
|
|
@ -138,72 +138,6 @@ AllocateUint64(uint64 value)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* LoadShardAlias finds the row for given relation and shardId in pg_dist_shard,
|
||||
* finds the shard alias in this row if any, and then deep copies this alias.
|
||||
*/
|
||||
char *
|
||||
LoadShardAlias(Oid relationId, uint64 shardId)
|
||||
{
|
||||
SysScanDesc scanDescriptor = NULL;
|
||||
ScanKeyData scanKey[1];
|
||||
int scanKeyCount = 1;
|
||||
HeapTuple heapTuple = NULL;
|
||||
Datum shardAliasDatum = 0;
|
||||
bool shardAliasNull = false;
|
||||
char *shardAlias = NULL;
|
||||
|
||||
Relation pgDistShard = heap_open(DistShardRelationId(), AccessShareLock);
|
||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistShard);
|
||||
|
||||
ScanKeyInit(&scanKey[0], Anum_pg_dist_shard_shardid,
|
||||
BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(shardId));
|
||||
|
||||
scanDescriptor = systable_beginscan(pgDistShard,
|
||||
DistShardShardidIndexId(), true,
|
||||
NULL, scanKeyCount, scanKey);
|
||||
|
||||
/*
|
||||
* Normally, we should have at most one tuple here as we have a unique index
|
||||
* on shardId. However, if users want to drop this uniqueness constraint,
|
||||
* and look up the shardalias based on the relation and shardId pair, we
|
||||
* still allow that. We don't have any users relaying on this feature. Thus,
|
||||
* we may consider to remove this check.
|
||||
*/
|
||||
heapTuple = systable_getnext(scanDescriptor);
|
||||
while (HeapTupleIsValid(heapTuple))
|
||||
{
|
||||
Form_pg_dist_shard pgDistShardForm = (Form_pg_dist_shard) GETSTRUCT(heapTuple);
|
||||
if (pgDistShardForm->logicalrelid == relationId)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
heapTuple = systable_getnext(scanDescriptor);
|
||||
}
|
||||
|
||||
/* if no tuple found, error out */
|
||||
if (!HeapTupleIsValid(heapTuple))
|
||||
{
|
||||
ereport(ERROR, (errmsg("could not find valid entry for relationId: %u "
|
||||
"and shard " UINT64_FORMAT, relationId, shardId)));
|
||||
}
|
||||
|
||||
/* if shard alias exists, deep copy cstring */
|
||||
shardAliasDatum = heap_getattr(heapTuple, Anum_pg_dist_shard_shardalias,
|
||||
tupleDescriptor, &shardAliasNull);
|
||||
if (!shardAliasNull)
|
||||
{
|
||||
shardAlias = TextDatumGetCString(shardAliasDatum);
|
||||
}
|
||||
|
||||
systable_endscan(scanDescriptor);
|
||||
heap_close(pgDistShard, AccessShareLock);
|
||||
|
||||
return shardAlias;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* CopyShardInterval copies fields from the specified source ShardInterval
|
||||
* into the fields of the provided destination ShardInterval.
|
||||
|
@ -405,15 +339,11 @@ InsertShardRow(Oid relationId, uint64 shardId, char storageType,
|
|||
{
|
||||
values[Anum_pg_dist_shard_shardminvalue - 1] = PointerGetDatum(shardMinValue);
|
||||
values[Anum_pg_dist_shard_shardmaxvalue - 1] = PointerGetDatum(shardMaxValue);
|
||||
|
||||
/* we always set shard alias to null */
|
||||
isNulls[Anum_pg_dist_shard_shardalias - 1] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isNulls[Anum_pg_dist_shard_shardminvalue - 1] = true;
|
||||
isNulls[Anum_pg_dist_shard_shardmaxvalue - 1] = true;
|
||||
isNulls[Anum_pg_dist_shard_shardalias - 1] = true;
|
||||
}
|
||||
|
||||
/* open shard relation and insert new tuple */
|
||||
|
|
|
@ -238,13 +238,9 @@ master_append_table_to_shard(PG_FUNCTION_ARGS)
|
|||
shardSchemaOid = get_rel_namespace(relationId);
|
||||
shardSchemaName = get_namespace_name(shardSchemaOid);
|
||||
|
||||
/* if shard doesn't have an alias, extend regular table name */
|
||||
shardTableName = LoadShardAlias(relationId, shardId);
|
||||
if (shardTableName == NULL)
|
||||
{
|
||||
/* Build shard table name. */
|
||||
shardTableName = get_rel_name(relationId);
|
||||
AppendShardIdToName(&shardTableName, shardId);
|
||||
}
|
||||
|
||||
shardQualifiedName = quote_qualified_identifier(shardSchemaName, shardTableName);
|
||||
|
||||
|
@ -493,10 +489,7 @@ UpdateShardStatistics(int64 shardId)
|
|||
text *minValue = NULL;
|
||||
text *maxValue = NULL;
|
||||
|
||||
/* if shard doesn't have an alias, extend regular table name */
|
||||
shardQualifiedName = LoadShardAlias(relationId, shardId);
|
||||
if (shardQualifiedName == NULL)
|
||||
{
|
||||
/* Build shard qualified name. */
|
||||
char *shardName = get_rel_name(relationId);
|
||||
|
||||
Oid schemaId = get_rel_namespace(relationId);
|
||||
|
@ -505,7 +498,6 @@ UpdateShardStatistics(int64 shardId)
|
|||
AppendShardIdToName(&shardName, shardId);
|
||||
|
||||
shardQualifiedName = quote_qualified_identifier(schemaName, shardName);
|
||||
}
|
||||
|
||||
shardPlacementList = FinalizedShardPlacementList(shardId);
|
||||
|
||||
|
|
|
@ -3753,19 +3753,6 @@ ShardFetchQueryString(uint64 shardId)
|
|||
char *shardSchemaName = NULL;
|
||||
char *shardTableName = NULL;
|
||||
|
||||
/*
|
||||
* If user specified a shard alias in pg_dist_shard, error out and display a
|
||||
* message explaining the limitation.
|
||||
*/
|
||||
char *shardAliasName = LoadShardAlias(shardInterval->relationId, shardId);
|
||||
if (shardAliasName != NULL)
|
||||
{
|
||||
ereport(ERROR, (errmsg("cannot fetch shard " UINT64_FORMAT, shardId),
|
||||
errdetail("Fetching shards with aliases is currently "
|
||||
"unsupported")));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* construct the shard name */
|
||||
Oid shardSchemaId = get_rel_namespace(shardInterval->relationId);
|
||||
char *tableName = get_rel_name(shardInterval->relationId);
|
||||
|
@ -3773,7 +3760,6 @@ ShardFetchQueryString(uint64 shardId)
|
|||
shardSchemaName = get_namespace_name(shardSchemaId);
|
||||
shardTableName = pstrdup(tableName);
|
||||
AppendShardIdToName(&shardTableName, shardId);
|
||||
}
|
||||
|
||||
shardFetchQuery = makeStringInfo();
|
||||
if (storageType == SHARD_STORAGE_TABLE || storageType == SHARD_STORAGE_RELAY ||
|
||||
|
@ -3986,22 +3972,12 @@ FragmentAlias(RangeTblEntry *rangeTableEntry, RangeTableFragment *fragment)
|
|||
aliasName = relationName;
|
||||
|
||||
/*
|
||||
* If user specified a shard name in pg_dist_shard, use that name in alias.
|
||||
* Otherwise, set shard name in alias to <relation_name>_<shard_id>.
|
||||
* Set shard name in alias to <relation_name>_<shard_id>.
|
||||
*/
|
||||
shardAliasName = LoadShardAlias(relationId, shardId);
|
||||
if (shardAliasName != NULL)
|
||||
{
|
||||
fragmentName = shardAliasName;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *shardName = pstrdup(relationName);
|
||||
AppendShardIdToName(&shardName, shardId);
|
||||
|
||||
fragmentName = shardName;
|
||||
}
|
||||
}
|
||||
else if (fragmentType == CITUS_RTE_REMOTE_QUERY)
|
||||
{
|
||||
Task *mergeTask = (Task *) fragment->fragmentReference;
|
||||
|
|
|
@ -59,7 +59,6 @@ typedef struct ShardPlacement
|
|||
extern List * LoadShardIntervalList(Oid relationId);
|
||||
extern int ShardIntervalCount(Oid relationId);
|
||||
extern List * LoadShardList(Oid relationId);
|
||||
extern char * LoadShardAlias(Oid relationId, uint64 shardId);
|
||||
extern void CopyShardInterval(ShardInterval *srcInterval, ShardInterval *destInterval);
|
||||
extern uint64 ShardLength(uint64 shardId);
|
||||
extern List * FinalizedShardPlacementList(uint64 shardId);
|
||||
|
|
|
@ -26,7 +26,6 @@ typedef struct FormData_pg_dist_shard
|
|||
int64 shardid; /* global shardId representing remote partition */
|
||||
char shardstorage; /* shard storage type; see codes below */
|
||||
#ifdef CATALOG_VARLEN /* variable-length fields start here */
|
||||
text shardalias; /* user specified table name for shard, if any */
|
||||
text shardminvalue; /* partition key's minimum value in shard */
|
||||
text shardmaxvalue; /* partition key's maximum value in shard */
|
||||
#endif
|
||||
|
@ -43,13 +42,12 @@ typedef FormData_pg_dist_shard *Form_pg_dist_shard;
|
|||
* compiler constants for pg_dist_shards
|
||||
* ----------------
|
||||
*/
|
||||
#define Natts_pg_dist_shard 6
|
||||
#define Natts_pg_dist_shard 5
|
||||
#define Anum_pg_dist_shard_logicalrelid 1
|
||||
#define Anum_pg_dist_shard_shardid 2
|
||||
#define Anum_pg_dist_shard_shardstorage 3
|
||||
#define Anum_pg_dist_shard_shardalias 4
|
||||
#define Anum_pg_dist_shard_shardminvalue 5
|
||||
#define Anum_pg_dist_shard_shardmaxvalue 6
|
||||
#define Anum_pg_dist_shard_shardminvalue 4
|
||||
#define Anum_pg_dist_shard_shardmaxvalue 5
|
||||
|
||||
/*
|
||||
* Valid values for shard storage types include relay file, foreign table,
|
||||
|
|
|
@ -5,3 +5,5 @@
|
|||
/tmp_check/
|
||||
/results/
|
||||
/log/
|
||||
/regression.out
|
||||
/regression.diffs
|
||||
|
|
|
@ -53,8 +53,8 @@ SELECT * FROM pg_dist_partition;
|
|||
(0 rows)
|
||||
|
||||
SELECT * FROM pg_dist_shard;
|
||||
logicalrelid | shardid | shardstorage | shardalias | shardminvalue | shardmaxvalue
|
||||
--------------+---------+--------------+------------+---------------+---------------
|
||||
logicalrelid | shardid | shardstorage | shardminvalue | shardmaxvalue
|
||||
--------------+---------+--------------+---------------+---------------
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM pg_dist_shard_placement;
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
--
|
||||
-- MULTI_VERIFY_NO_JOIN_WITH_ALIAS
|
||||
--
|
||||
-- This test checks that we simply emit an error message instead of trying to
|
||||
-- fetch and join a shard which has an alias set.
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1020000;
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1020000;
|
||||
-- Show that the join works without an alias
|
||||
SELECT COUNT(*) FROM lineitem, part WHERE l_partkey = p_partkey;
|
||||
count
|
||||
-------
|
||||
61
|
||||
(1 row)
|
||||
|
||||
-- Assign an alias to the parts shard
|
||||
UPDATE pg_dist_shard SET shardalias = 'my_alias' WHERE shardid = 290000;
|
||||
-- Attempt a join which uses this shard
|
||||
SELECT COUNT(*) FROM lineitem, part WHERE l_partkey = p_partkey;
|
||||
ERROR: cannot fetch shard 290000
|
||||
DETAIL: Fetching shards with aliases is currently unsupported
|
||||
-- Remove the alias from the parts shard
|
||||
UPDATE pg_dist_shard SET shardalias = NULL WHERE shardid = 290000;
|
|
@ -44,7 +44,6 @@ test: multi_query_directory_cleanup
|
|||
test: multi_task_assignment_policy
|
||||
test: multi_utility_statements
|
||||
test: multi_dropped_column_aliases
|
||||
test: multi_verify_no_join_with_alias
|
||||
test: multi_binary_master_copy_format
|
||||
test: multi_prepare_sql multi_prepare_plsql
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ test: multi_query_directory_cleanup
|
|||
test: multi_task_assignment_policy
|
||||
test: multi_utility_statements
|
||||
test: multi_dropped_column_aliases
|
||||
test: multi_verify_no_join_with_alias
|
||||
|
||||
# ----------
|
||||
# Parallel TPC-H tests to check our distributed execution behavior
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
--
|
||||
-- MULTI_VERIFY_NO_JOIN_WITH_ALIAS
|
||||
--
|
||||
|
||||
-- This test checks that we simply emit an error message instead of trying to
|
||||
-- fetch and join a shard which has an alias set.
|
||||
|
||||
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1020000;
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1020000;
|
||||
|
||||
|
||||
-- Show that the join works without an alias
|
||||
|
||||
SELECT COUNT(*) FROM lineitem, part WHERE l_partkey = p_partkey;
|
||||
|
||||
-- Assign an alias to the parts shard
|
||||
|
||||
UPDATE pg_dist_shard SET shardalias = 'my_alias' WHERE shardid = 290000;
|
||||
|
||||
-- Attempt a join which uses this shard
|
||||
|
||||
SELECT COUNT(*) FROM lineitem, part WHERE l_partkey = p_partkey;
|
||||
|
||||
-- Remove the alias from the parts shard
|
||||
|
||||
UPDATE pg_dist_shard SET shardalias = NULL WHERE shardid = 290000;
|
Loading…
Reference in New Issue