mirror of https://github.com/citusdata/citus.git
Merge 2281fb97c2
into 55a0d1f730
commit
f86929eaaf
|
@ -346,12 +346,12 @@ CdcIsReferenceTableViaCatalog(Oid relationId)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
||||||
|
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
|
|
||||||
if (isNullArray[Anum_pg_dist_partition_partmethod - 1] ||
|
if (isNullArray[Anum_pg_dist_partition_partmethod - 1] ||
|
||||||
|
@ -363,6 +363,8 @@ CdcIsReferenceTableViaCatalog(Oid relationId)
|
||||||
*/
|
*/
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,6 +376,8 @@ CdcIsReferenceTableViaCatalog(Oid relationId)
|
||||||
|
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A table is a reference table when its partition method is 'none'
|
* A table is a reference table when its partition method is 'none'
|
||||||
|
|
|
@ -320,9 +320,10 @@ static void CachedRelationNamespaceLookup(const char *relationName, Oid relnames
|
||||||
static void CachedRelationNamespaceLookupExtended(const char *relationName,
|
static void CachedRelationNamespaceLookupExtended(const char *relationName,
|
||||||
Oid renamespace, Oid *cachedOid,
|
Oid renamespace, Oid *cachedOid,
|
||||||
bool missing_ok);
|
bool missing_ok);
|
||||||
static ShardPlacement * ResolveGroupShardPlacement(
|
static ShardPlacement * ResolveGroupShardPlacement(GroupShardPlacement *
|
||||||
GroupShardPlacement *groupShardPlacement, CitusTableCacheEntry *tableEntry,
|
groupShardPlacement,
|
||||||
int shardIndex);
|
CitusTableCacheEntry *tableEntry,
|
||||||
|
int shardIndex);
|
||||||
static Oid LookupEnumValueId(Oid typeId, char *valueName);
|
static Oid LookupEnumValueId(Oid typeId, char *valueName);
|
||||||
static void InvalidateCitusTableCacheEntrySlot(CitusTableCacheEntrySlot *cacheSlot);
|
static void InvalidateCitusTableCacheEntrySlot(CitusTableCacheEntrySlot *cacheSlot);
|
||||||
static void InvalidateDistTableCache(void);
|
static void InvalidateDistTableCache(void);
|
||||||
|
@ -729,12 +730,13 @@ PartitionMethodViaCatalog(Oid relationId)
|
||||||
return DISTRIBUTE_BY_INVALID;
|
return DISTRIBUTE_BY_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
||||||
|
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
|
|
||||||
if (isNullArray[Anum_pg_dist_partition_partmethod - 1])
|
if (isNullArray[Anum_pg_dist_partition_partmethod - 1])
|
||||||
|
@ -742,6 +744,8 @@ PartitionMethodViaCatalog(Oid relationId)
|
||||||
/* partition method cannot be NULL, still let's make sure */
|
/* partition method cannot be NULL, still let's make sure */
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
return DISTRIBUTE_BY_INVALID;
|
return DISTRIBUTE_BY_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,6 +754,8 @@ PartitionMethodViaCatalog(Oid relationId)
|
||||||
|
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
return partitionMethodChar;
|
return partitionMethodChar;
|
||||||
}
|
}
|
||||||
|
@ -768,12 +774,12 @@ PartitionColumnViaCatalog(Oid relationId)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
||||||
|
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
|
|
||||||
if (isNullArray[Anum_pg_dist_partition_partkey - 1])
|
if (isNullArray[Anum_pg_dist_partition_partkey - 1])
|
||||||
|
@ -781,6 +787,8 @@ PartitionColumnViaCatalog(Oid relationId)
|
||||||
/* partition key cannot be NULL, still let's make sure */
|
/* partition key cannot be NULL, still let's make sure */
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -795,6 +803,8 @@ PartitionColumnViaCatalog(Oid relationId)
|
||||||
|
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
return partitionColumn;
|
return partitionColumn;
|
||||||
}
|
}
|
||||||
|
@ -813,12 +823,13 @@ ColocationIdViaCatalog(Oid relationId)
|
||||||
return INVALID_COLOCATION_ID;
|
return INVALID_COLOCATION_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
|
||||||
|
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(partitionTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
|
|
||||||
if (isNullArray[Anum_pg_dist_partition_colocationid - 1])
|
if (isNullArray[Anum_pg_dist_partition_colocationid - 1])
|
||||||
|
@ -826,6 +837,8 @@ ColocationIdViaCatalog(Oid relationId)
|
||||||
/* colocation id cannot be NULL, still let's make sure */
|
/* colocation id cannot be NULL, still let's make sure */
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
return INVALID_COLOCATION_ID;
|
return INVALID_COLOCATION_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -834,6 +847,8 @@ ColocationIdViaCatalog(Oid relationId)
|
||||||
|
|
||||||
heap_freetuple(partitionTuple);
|
heap_freetuple(partitionTuple);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
return colocationId;
|
return colocationId;
|
||||||
}
|
}
|
||||||
|
@ -1741,10 +1756,11 @@ BuildCitusTableCacheEntry(Oid relationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryContext oldContext = NULL;
|
MemoryContext oldContext = NULL;
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
heap_deform_tuple(distPartitionTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(distPartitionTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
|
|
||||||
CitusTableCacheEntry *cacheEntry =
|
CitusTableCacheEntry *cacheEntry =
|
||||||
|
@ -1797,7 +1813,7 @@ BuildCitusTableCacheEntry(Oid relationId)
|
||||||
cacheEntry->replicationModel = DatumGetChar(replicationModelDatum);
|
cacheEntry->replicationModel = DatumGetChar(replicationModelDatum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNullArray[Anum_pg_dist_partition_autoconverted - 1])
|
if (isNullArray[GetAutoConvertedAttrIndexInPgDistPartition(tupleDescriptor)])
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We don't expect this to happen, but set it to false (the default value)
|
* We don't expect this to happen, but set it to false (the default value)
|
||||||
|
@ -1808,7 +1824,7 @@ BuildCitusTableCacheEntry(Oid relationId)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cacheEntry->autoConverted = DatumGetBool(
|
cacheEntry->autoConverted = DatumGetBool(
|
||||||
datumArray[Anum_pg_dist_partition_autoconverted - 1]);
|
datumArray[GetAutoConvertedAttrIndexInPgDistPartition(tupleDescriptor)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
heap_freetuple(distPartitionTuple);
|
heap_freetuple(distPartitionTuple);
|
||||||
|
@ -1852,6 +1868,9 @@ BuildCitusTableCacheEntry(Oid relationId)
|
||||||
|
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
cacheEntry->isValid = true;
|
cacheEntry->isValid = true;
|
||||||
|
|
||||||
return cacheEntry;
|
return cacheEntry;
|
||||||
|
@ -5011,10 +5030,12 @@ CitusTableTypeIdList(CitusTableType citusTableType)
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
|
||||||
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
while (HeapTupleIsValid(heapTuple))
|
while (HeapTupleIsValid(heapTuple))
|
||||||
{
|
{
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
memset(datumArray, 0, tupleDescriptor->natts * sizeof(Datum));
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
memset(isNullArray, 0, tupleDescriptor->natts * sizeof(bool));
|
||||||
heap_deform_tuple(heapTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(heapTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
|
|
||||||
Datum partMethodDatum = datumArray[Anum_pg_dist_partition_partmethod - 1];
|
Datum partMethodDatum = datumArray[Anum_pg_dist_partition_partmethod - 1];
|
||||||
|
@ -5037,6 +5058,8 @@ CitusTableTypeIdList(CitusTableType citusTableType)
|
||||||
|
|
||||||
heapTuple = systable_getnext(scanDescriptor);
|
heapTuple = systable_getnext(scanDescriptor);
|
||||||
}
|
}
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPartition, AccessShareLock);
|
table_close(pgDistPartition, AccessShareLock);
|
||||||
|
|
|
@ -573,13 +573,17 @@ FetchRelationIdFromPgPartitionHeapTuple(HeapTuple heapTuple, TupleDesc tupleDesc
|
||||||
{
|
{
|
||||||
Assert(heapTuple->t_tableOid == DistPartitionRelationId());
|
Assert(heapTuple->t_tableOid == DistPartitionRelationId());
|
||||||
|
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
Datum *datumArray = (Datum *) palloc0(tupleDesc->natts * sizeof(Datum));
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
bool *isNullArray = (bool *) palloc0(tupleDesc->natts * sizeof(bool));
|
||||||
|
|
||||||
heap_deform_tuple(heapTuple, tupleDesc, datumArray, isNullArray);
|
heap_deform_tuple(heapTuple, tupleDesc, datumArray, isNullArray);
|
||||||
|
|
||||||
Datum relationIdDatum = datumArray[Anum_pg_dist_partition_logicalrelid - 1];
|
Datum relationIdDatum = datumArray[Anum_pg_dist_partition_logicalrelid - 1];
|
||||||
Oid relationId = DatumGetObjectId(relationIdDatum);
|
Oid relationId = DatumGetObjectId(relationIdDatum);
|
||||||
|
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
return relationId;
|
return relationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,11 +127,11 @@ static bool SetFieldText(int attno, Datum values[], bool isnull[], bool replace[
|
||||||
static bool SetFieldNull(int attno, Datum values[], bool isnull[], bool replace[]);
|
static bool SetFieldNull(int attno, Datum values[], bool isnull[], bool replace[]);
|
||||||
|
|
||||||
#define InitFieldValue(attno, values, isnull, initValue) \
|
#define InitFieldValue(attno, values, isnull, initValue) \
|
||||||
(void) SetFieldValue((attno), (values), (isnull), NULL, (initValue))
|
(void) SetFieldValue((attno), (values), (isnull), NULL, (initValue))
|
||||||
#define InitFieldText(attno, values, isnull, initValue) \
|
#define InitFieldText(attno, values, isnull, initValue) \
|
||||||
(void) SetFieldText((attno), (values), (isnull), NULL, (initValue))
|
(void) SetFieldText((attno), (values), (isnull), NULL, (initValue))
|
||||||
#define InitFieldNull(attno, values, isnull) \
|
#define InitFieldNull(attno, values, isnull) \
|
||||||
(void) SetFieldNull((attno), (values), (isnull), NULL)
|
(void) SetFieldNull((attno), (values), (isnull), NULL)
|
||||||
|
|
||||||
/* exports for SQL callable functions */
|
/* exports for SQL callable functions */
|
||||||
PG_FUNCTION_INFO_V1(citus_local_disk_space_stats);
|
PG_FUNCTION_INFO_V1(citus_local_disk_space_stats);
|
||||||
|
@ -822,7 +822,8 @@ GenerateSizeQueryOnMultiplePlacements(List *shardIntervalList,
|
||||||
/* SELECT SUM(worker_partitioned_...) FROM VALUES (...) */
|
/* SELECT SUM(worker_partitioned_...) FROM VALUES (...) */
|
||||||
char *subqueryForPartitionedShards =
|
char *subqueryForPartitionedShards =
|
||||||
GenerateSizeQueryForRelationNameList(partitionedShardNames,
|
GenerateSizeQueryForRelationNameList(partitionedShardNames,
|
||||||
GetWorkerPartitionedSizeUDFNameBySizeQueryType(
|
GetWorkerPartitionedSizeUDFNameBySizeQueryType
|
||||||
|
(
|
||||||
sizeQueryType));
|
sizeQueryType));
|
||||||
|
|
||||||
/* SELECT SUM(pg_..._size) FROM VALUES (...) */
|
/* SELECT SUM(pg_..._size) FROM VALUES (...) */
|
||||||
|
@ -1919,23 +1920,22 @@ InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
|
||||||
{
|
{
|
||||||
char *distributionColumnString = NULL;
|
char *distributionColumnString = NULL;
|
||||||
|
|
||||||
Datum newValues[Natts_pg_dist_partition];
|
|
||||||
bool newNulls[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
/* open system catalog and insert new tuple */
|
/* open system catalog and insert new tuple */
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
||||||
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
|
||||||
|
Datum *newValues = (Datum *) palloc0(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *newNulls = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
/* form new tuple for pg_dist_partition */
|
/* form new tuple for pg_dist_partition */
|
||||||
memset(newValues, 0, sizeof(newValues));
|
|
||||||
memset(newNulls, false, sizeof(newNulls));
|
|
||||||
|
|
||||||
newValues[Anum_pg_dist_partition_logicalrelid - 1] =
|
newValues[Anum_pg_dist_partition_logicalrelid - 1] =
|
||||||
ObjectIdGetDatum(relationId);
|
ObjectIdGetDatum(relationId);
|
||||||
newValues[Anum_pg_dist_partition_partmethod - 1] =
|
newValues[Anum_pg_dist_partition_partmethod - 1] =
|
||||||
CharGetDatum(distributionMethod);
|
CharGetDatum(distributionMethod);
|
||||||
newValues[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
newValues[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
||||||
newValues[Anum_pg_dist_partition_repmodel - 1] = CharGetDatum(replicationModel);
|
newValues[Anum_pg_dist_partition_repmodel - 1] = CharGetDatum(replicationModel);
|
||||||
newValues[Anum_pg_dist_partition_autoconverted - 1] = BoolGetDatum(autoConverted);
|
newValues[GetAutoConvertedAttrIndexInPgDistPartition(tupleDescriptor)] = BoolGetDatum(
|
||||||
|
autoConverted);
|
||||||
|
|
||||||
/* set partkey column to NULL for reference tables */
|
/* set partkey column to NULL for reference tables */
|
||||||
if (distributionMethod != DISTRIBUTE_BY_NONE)
|
if (distributionMethod != DISTRIBUTE_BY_NONE)
|
||||||
|
@ -1951,7 +1951,7 @@ InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
|
||||||
newNulls[Anum_pg_dist_partition_partkey - 1] = true;
|
newNulls[Anum_pg_dist_partition_partkey - 1] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapTuple newTuple = heap_form_tuple(RelationGetDescr(pgDistPartition), newValues,
|
HeapTuple newTuple = heap_form_tuple(tupleDescriptor, newValues,
|
||||||
newNulls);
|
newNulls);
|
||||||
|
|
||||||
/* finally insert tuple, build index entries & register cache invalidation */
|
/* finally insert tuple, build index entries & register cache invalidation */
|
||||||
|
@ -1963,6 +1963,9 @@ InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
|
||||||
|
|
||||||
CommandCounterIncrement();
|
CommandCounterIncrement();
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
|
||||||
|
pfree(newValues);
|
||||||
|
pfree(newNulls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2154,13 +2157,13 @@ UpdatePlacementGroupId(uint64 placementId, int groupId)
|
||||||
ScanKeyData scanKey[1];
|
ScanKeyData scanKey[1];
|
||||||
int scanKeyCount = 1;
|
int scanKeyCount = 1;
|
||||||
bool indexOK = true;
|
bool indexOK = true;
|
||||||
Datum values[Natts_pg_dist_placement];
|
|
||||||
bool isnull[Natts_pg_dist_placement];
|
|
||||||
bool replace[Natts_pg_dist_placement];
|
|
||||||
bool colIsNull = false;
|
bool colIsNull = false;
|
||||||
|
|
||||||
Relation pgDistPlacement = table_open(DistPlacementRelationId(), RowExclusiveLock);
|
Relation pgDistPlacement = table_open(DistPlacementRelationId(), RowExclusiveLock);
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement);
|
||||||
|
Datum *values = (Datum *) palloc0(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isnull = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
bool *replace = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_placementid,
|
ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_placementid,
|
||||||
BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(placementId));
|
BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(placementId));
|
||||||
|
|
||||||
|
@ -2177,8 +2180,6 @@ UpdatePlacementGroupId(uint64 placementId, int groupId)
|
||||||
placementId)));
|
placementId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(replace, 0, sizeof(replace));
|
|
||||||
|
|
||||||
values[Anum_pg_dist_placement_groupid - 1] = Int32GetDatum(groupId);
|
values[Anum_pg_dist_placement_groupid - 1] = Int32GetDatum(groupId);
|
||||||
isnull[Anum_pg_dist_placement_groupid - 1] = false;
|
isnull[Anum_pg_dist_placement_groupid - 1] = false;
|
||||||
replace[Anum_pg_dist_placement_groupid - 1] = true;
|
replace[Anum_pg_dist_placement_groupid - 1] = true;
|
||||||
|
@ -2197,6 +2198,10 @@ UpdatePlacementGroupId(uint64 placementId, int groupId)
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPlacement, NoLock);
|
table_close(pgDistPlacement, NoLock);
|
||||||
|
|
||||||
|
pfree(values);
|
||||||
|
pfree(isnull);
|
||||||
|
pfree(replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2210,12 +2215,13 @@ UpdatePgDistPartitionAutoConverted(Oid citusTableId, bool autoConverted)
|
||||||
ScanKeyData scanKey[1];
|
ScanKeyData scanKey[1];
|
||||||
int scanKeyCount = 1;
|
int scanKeyCount = 1;
|
||||||
bool indexOK = true;
|
bool indexOK = true;
|
||||||
Datum values[Natts_pg_dist_partition];
|
|
||||||
bool isnull[Natts_pg_dist_partition];
|
|
||||||
bool replace[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
Datum *values = (Datum *) palloc0(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isnull = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
bool *replace = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(citusTableId));
|
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(citusTableId));
|
||||||
|
|
||||||
|
@ -2231,11 +2237,10 @@ UpdatePgDistPartitionAutoConverted(Oid citusTableId, bool autoConverted)
|
||||||
citusTableId)));
|
citusTableId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(replace, 0, sizeof(replace));
|
int autoconvertedindex = GetAutoConvertedAttrIndexInPgDistPartition(tupleDescriptor);
|
||||||
|
values[autoconvertedindex] = BoolGetDatum(autoConverted);
|
||||||
values[Anum_pg_dist_partition_autoconverted - 1] = BoolGetDatum(autoConverted);
|
isnull[autoconvertedindex] = false;
|
||||||
isnull[Anum_pg_dist_partition_autoconverted - 1] = false;
|
replace[autoconvertedindex] = true;
|
||||||
replace[Anum_pg_dist_partition_autoconverted - 1] = true;
|
|
||||||
|
|
||||||
heapTuple = heap_modify_tuple(heapTuple, tupleDescriptor, values, isnull, replace);
|
heapTuple = heap_modify_tuple(heapTuple, tupleDescriptor, values, isnull, replace);
|
||||||
|
|
||||||
|
@ -2247,6 +2252,10 @@ UpdatePgDistPartitionAutoConverted(Oid citusTableId, bool autoConverted)
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
|
||||||
|
pfree(values);
|
||||||
|
pfree(isnull);
|
||||||
|
pfree(replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2286,12 +2295,13 @@ UpdateDistributionColumn(Oid relationId, char distributionMethod, Var *distribut
|
||||||
ScanKeyData scanKey[1];
|
ScanKeyData scanKey[1];
|
||||||
int scanKeyCount = 1;
|
int scanKeyCount = 1;
|
||||||
bool indexOK = true;
|
bool indexOK = true;
|
||||||
Datum values[Natts_pg_dist_partition];
|
|
||||||
bool isnull[Natts_pg_dist_partition];
|
|
||||||
bool replace[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
Datum *values = (Datum *) palloc0(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isnull = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
bool *replace = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId));
|
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId));
|
||||||
|
|
||||||
|
@ -2307,8 +2317,6 @@ UpdateDistributionColumn(Oid relationId, char distributionMethod, Var *distribut
|
||||||
relationId)));
|
relationId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(replace, 0, sizeof(replace));
|
|
||||||
|
|
||||||
replace[Anum_pg_dist_partition_partmethod - 1] = true;
|
replace[Anum_pg_dist_partition_partmethod - 1] = true;
|
||||||
values[Anum_pg_dist_partition_partmethod - 1] = CharGetDatum(distributionMethod);
|
values[Anum_pg_dist_partition_partmethod - 1] = CharGetDatum(distributionMethod);
|
||||||
isnull[Anum_pg_dist_partition_partmethod - 1] = false;
|
isnull[Anum_pg_dist_partition_partmethod - 1] = false;
|
||||||
|
@ -2317,9 +2325,10 @@ UpdateDistributionColumn(Oid relationId, char distributionMethod, Var *distribut
|
||||||
values[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
values[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
||||||
isnull[Anum_pg_dist_partition_colocationid - 1] = false;
|
isnull[Anum_pg_dist_partition_colocationid - 1] = false;
|
||||||
|
|
||||||
replace[Anum_pg_dist_partition_autoconverted - 1] = true;
|
int autoconvertedindex = GetAutoConvertedAttrIndexInPgDistPartition(tupleDescriptor);
|
||||||
values[Anum_pg_dist_partition_autoconverted - 1] = BoolGetDatum(false);
|
replace[autoconvertedindex] = true;
|
||||||
isnull[Anum_pg_dist_partition_autoconverted - 1] = false;
|
values[autoconvertedindex] = BoolGetDatum(false);
|
||||||
|
isnull[autoconvertedindex] = false;
|
||||||
|
|
||||||
char *distributionColumnString = nodeToString((Node *) distributionColumn);
|
char *distributionColumnString = nodeToString((Node *) distributionColumn);
|
||||||
|
|
||||||
|
@ -2337,6 +2346,10 @@ UpdateDistributionColumn(Oid relationId, char distributionMethod, Var *distribut
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
|
||||||
|
pfree(values);
|
||||||
|
pfree(isnull);
|
||||||
|
pfree(replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2380,12 +2393,13 @@ UpdateNoneDistTableMetadata(Oid relationId, char replicationModel, uint32 coloca
|
||||||
ScanKeyData scanKey[1];
|
ScanKeyData scanKey[1];
|
||||||
int scanKeyCount = 1;
|
int scanKeyCount = 1;
|
||||||
bool indexOK = true;
|
bool indexOK = true;
|
||||||
Datum values[Natts_pg_dist_partition];
|
|
||||||
bool isnull[Natts_pg_dist_partition];
|
|
||||||
bool replace[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
Datum *values = (Datum *) palloc0(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isnull = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
bool *replace = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId));
|
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId));
|
||||||
|
|
||||||
|
@ -2401,8 +2415,6 @@ UpdateNoneDistTableMetadata(Oid relationId, char replicationModel, uint32 coloca
|
||||||
relationId)));
|
relationId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(replace, 0, sizeof(replace));
|
|
||||||
|
|
||||||
values[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
values[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
||||||
isnull[Anum_pg_dist_partition_colocationid - 1] = false;
|
isnull[Anum_pg_dist_partition_colocationid - 1] = false;
|
||||||
replace[Anum_pg_dist_partition_colocationid - 1] = true;
|
replace[Anum_pg_dist_partition_colocationid - 1] = true;
|
||||||
|
@ -2411,9 +2423,10 @@ UpdateNoneDistTableMetadata(Oid relationId, char replicationModel, uint32 coloca
|
||||||
isnull[Anum_pg_dist_partition_repmodel - 1] = false;
|
isnull[Anum_pg_dist_partition_repmodel - 1] = false;
|
||||||
replace[Anum_pg_dist_partition_repmodel - 1] = true;
|
replace[Anum_pg_dist_partition_repmodel - 1] = true;
|
||||||
|
|
||||||
values[Anum_pg_dist_partition_autoconverted - 1] = BoolGetDatum(autoConverted);
|
int autoconvertedindex = GetAutoConvertedAttrIndexInPgDistPartition(tupleDescriptor);
|
||||||
isnull[Anum_pg_dist_partition_autoconverted - 1] = false;
|
values[autoconvertedindex] = BoolGetDatum(autoConverted);
|
||||||
replace[Anum_pg_dist_partition_autoconverted - 1] = true;
|
isnull[autoconvertedindex] = false;
|
||||||
|
replace[autoconvertedindex] = true;
|
||||||
|
|
||||||
heapTuple = heap_modify_tuple(heapTuple, tupleDescriptor, values, isnull, replace);
|
heapTuple = heap_modify_tuple(heapTuple, tupleDescriptor, values, isnull, replace);
|
||||||
|
|
||||||
|
@ -2424,6 +2437,10 @@ UpdateNoneDistTableMetadata(Oid relationId, char replicationModel, uint32 coloca
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
|
||||||
|
pfree(values);
|
||||||
|
pfree(isnull);
|
||||||
|
pfree(replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3149,8 +3166,8 @@ ScheduleBackgroundTask(int64 jobId, Oid owner, char *command, int dependingTaskC
|
||||||
|
|
||||||
values[Anum_pg_dist_background_task_nodes_involved - 1] =
|
values[Anum_pg_dist_background_task_nodes_involved - 1] =
|
||||||
IntArrayToDatum(nodesInvolvedCount, nodesInvolved);
|
IntArrayToDatum(nodesInvolvedCount, nodesInvolved);
|
||||||
nulls[Anum_pg_dist_background_task_nodes_involved - 1] = (nodesInvolvedCount ==
|
nulls[Anum_pg_dist_background_task_nodes_involved - 1] = (nodesInvolvedCount == 0)
|
||||||
0);
|
;
|
||||||
|
|
||||||
HeapTuple newTuple = heap_form_tuple(RelationGetDescr(pgDistBackgroundTask),
|
HeapTuple newTuple = heap_form_tuple(RelationGetDescr(pgDistBackgroundTask),
|
||||||
values, nulls);
|
values, nulls);
|
||||||
|
@ -4226,7 +4243,8 @@ CancelTasksForJob(int64 jobid)
|
||||||
|
|
||||||
const bool indexOK = true;
|
const bool indexOK = true;
|
||||||
SysScanDesc scanDescriptor = systable_beginscan(pgDistBackgroundTasks,
|
SysScanDesc scanDescriptor = systable_beginscan(pgDistBackgroundTasks,
|
||||||
DistBackgroundTaskJobIdTaskIdIndexId(),
|
DistBackgroundTaskJobIdTaskIdIndexId()
|
||||||
|
,
|
||||||
indexOK, NULL,
|
indexOK, NULL,
|
||||||
lengthof(scanKey), scanKey);
|
lengthof(scanKey), scanKey);
|
||||||
|
|
||||||
|
@ -4420,3 +4438,23 @@ UnblockDependingBackgroundTasks(BackgroundTask *task)
|
||||||
|
|
||||||
table_close(pgDistBackgroundTasksDepend, NoLock);
|
table_close(pgDistBackgroundTasksDepend, NoLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GetAutoConvertedAttrIndexInPgDistPartition returns attrnum for autoconverted attr.
|
||||||
|
*
|
||||||
|
* autoconverted attr was added to table pg_dist_partition using alter operation after
|
||||||
|
* the version where Citus started supporting downgrades, and it's only column that we've
|
||||||
|
* introduced to pg_dist_partition since then.
|
||||||
|
*
|
||||||
|
* And in case of a downgrade + upgrade, tupleDEsc->natts becomes greater than
|
||||||
|
* Natts_pg_dist_partition and when this happens, then we know that attrnum autoconverted is
|
||||||
|
* not Anum_pg_dist_partition_autoconverted anymore but tupleDEsc->natts - 1.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
GetAutoConvertedAttrIndexInPgDistPartition(TupleDesc tupleDEsc)
|
||||||
|
{
|
||||||
|
return TupleDescSize(tupleDEsc) == Natts_pg_dist_partition
|
||||||
|
? (Anum_pg_dist_partition_autoconverted - 1)
|
||||||
|
: tupleDEsc->natts - 1;
|
||||||
|
}
|
||||||
|
|
|
@ -557,8 +557,8 @@ ColocationId(int shardCount, int replicationFactor, Oid distributionColumnType,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colocationId == INVALID_COLOCATION_ID || colocationId >
|
if (colocationId == INVALID_COLOCATION_ID || colocationId > colocationForm->
|
||||||
colocationForm->colocationid)
|
colocationid)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We assign the smallest colocation id among all the matches so that we
|
* We assign the smallest colocation id among all the matches so that we
|
||||||
|
@ -815,13 +815,14 @@ UpdateRelationColocationGroup(Oid distributedRelationId, uint32 colocationId,
|
||||||
bool indexOK = true;
|
bool indexOK = true;
|
||||||
int scanKeyCount = 1;
|
int scanKeyCount = 1;
|
||||||
ScanKeyData scanKey[1];
|
ScanKeyData scanKey[1];
|
||||||
Datum values[Natts_pg_dist_partition];
|
|
||||||
bool isNull[Natts_pg_dist_partition];
|
|
||||||
bool replace[Natts_pg_dist_partition];
|
|
||||||
|
|
||||||
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
||||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||||
|
|
||||||
|
Datum *values = (Datum *) palloc0(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNull = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
bool *replace = (bool *) palloc0(tupleDescriptor->natts * sizeof(bool));
|
||||||
|
|
||||||
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(distributedRelationId));
|
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(distributedRelationId));
|
||||||
|
|
||||||
|
@ -838,10 +839,6 @@ UpdateRelationColocationGroup(Oid distributedRelationId, uint32 colocationId,
|
||||||
distributedRelationName)));
|
distributedRelationName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(values, 0, sizeof(values));
|
|
||||||
memset(isNull, false, sizeof(isNull));
|
|
||||||
memset(replace, false, sizeof(replace));
|
|
||||||
|
|
||||||
values[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
values[Anum_pg_dist_partition_colocationid - 1] = UInt32GetDatum(colocationId);
|
||||||
isNull[Anum_pg_dist_partition_colocationid - 1] = false;
|
isNull[Anum_pg_dist_partition_colocationid - 1] = false;
|
||||||
replace[Anum_pg_dist_partition_colocationid - 1] = true;
|
replace[Anum_pg_dist_partition_colocationid - 1] = true;
|
||||||
|
@ -858,6 +855,10 @@ UpdateRelationColocationGroup(Oid distributedRelationId, uint32 colocationId,
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPartition, NoLock);
|
table_close(pgDistPartition, NoLock);
|
||||||
|
|
||||||
|
pfree(values);
|
||||||
|
pfree(isNull);
|
||||||
|
pfree(replace);
|
||||||
|
|
||||||
bool shouldSyncMetadata = ShouldSyncTableMetadata(distributedRelationId);
|
bool shouldSyncMetadata = ShouldSyncTableMetadata(distributedRelationId);
|
||||||
if (shouldSyncMetadata && !localOnly)
|
if (shouldSyncMetadata && !localOnly)
|
||||||
{
|
{
|
||||||
|
@ -998,10 +999,12 @@ ColocationGroupTableList(uint32 colocationId, uint32 count)
|
||||||
indexOK, NULL, scanKeyCount, scanKey);
|
indexOK, NULL, scanKeyCount, scanKey);
|
||||||
|
|
||||||
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
while (HeapTupleIsValid(heapTuple))
|
while (HeapTupleIsValid(heapTuple))
|
||||||
{
|
{
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
memset(datumArray, 0, tupleDescriptor->natts * sizeof(Datum));
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
memset(isNullArray, 0, tupleDescriptor->natts * sizeof(bool));
|
||||||
heap_deform_tuple(heapTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(heapTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
Oid colocatedTableId = DatumGetObjectId(
|
Oid colocatedTableId = DatumGetObjectId(
|
||||||
datumArray[Anum_pg_dist_partition_logicalrelid - 1]);
|
datumArray[Anum_pg_dist_partition_logicalrelid - 1]);
|
||||||
|
@ -1020,6 +1023,8 @@ ColocationGroupTableList(uint32 colocationId, uint32 count)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPartition, AccessShareLock);
|
table_close(pgDistPartition, AccessShareLock);
|
||||||
|
@ -1072,8 +1077,8 @@ ColocatedShardIntervalList(ShardInterval *shardInterval)
|
||||||
* Since we iterate over co-located tables, shard count of each table should be
|
* Since we iterate over co-located tables, shard count of each table should be
|
||||||
* same and greater than shardIntervalIndex.
|
* same and greater than shardIntervalIndex.
|
||||||
*/
|
*/
|
||||||
Assert(cacheEntry->shardIntervalArrayLength ==
|
Assert(cacheEntry->shardIntervalArrayLength == colocatedTableCacheEntry->
|
||||||
colocatedTableCacheEntry->shardIntervalArrayLength);
|
shardIntervalArrayLength);
|
||||||
|
|
||||||
ShardInterval *colocatedShardInterval =
|
ShardInterval *colocatedShardInterval =
|
||||||
colocatedTableCacheEntry->sortedShardIntervalArray[shardIntervalIndex];
|
colocatedTableCacheEntry->sortedShardIntervalArray[shardIntervalIndex];
|
||||||
|
@ -1143,8 +1148,8 @@ ColocatedNonPartitionShardIntervalList(ShardInterval *shardInterval)
|
||||||
* Since we iterate over co-located tables, shard count of each table should be
|
* Since we iterate over co-located tables, shard count of each table should be
|
||||||
* same and greater than shardIntervalIndex.
|
* same and greater than shardIntervalIndex.
|
||||||
*/
|
*/
|
||||||
Assert(cacheEntry->shardIntervalArrayLength ==
|
Assert(cacheEntry->shardIntervalArrayLength == colocatedTableCacheEntry->
|
||||||
colocatedTableCacheEntry->shardIntervalArrayLength);
|
shardIntervalArrayLength);
|
||||||
|
|
||||||
ShardInterval *colocatedShardInterval =
|
ShardInterval *colocatedShardInterval =
|
||||||
colocatedTableCacheEntry->sortedShardIntervalArray[shardIntervalIndex];
|
colocatedTableCacheEntry->sortedShardIntervalArray[shardIntervalIndex];
|
||||||
|
@ -1192,10 +1197,12 @@ ColocatedTableId(int32 colocationId)
|
||||||
indexOK, NULL, scanKeyCount, scanKey);
|
indexOK, NULL, scanKeyCount, scanKey);
|
||||||
|
|
||||||
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
||||||
|
Datum *datumArray = (Datum *) palloc(tupleDescriptor->natts * sizeof(Datum));
|
||||||
|
bool *isNullArray = (bool *) palloc(tupleDescriptor->natts * sizeof(bool));
|
||||||
while (HeapTupleIsValid(heapTuple))
|
while (HeapTupleIsValid(heapTuple))
|
||||||
{
|
{
|
||||||
bool isNullArray[Natts_pg_dist_partition];
|
memset(datumArray, 0, tupleDescriptor->natts * sizeof(Datum));
|
||||||
Datum datumArray[Natts_pg_dist_partition];
|
memset(isNullArray, 0, tupleDescriptor->natts * sizeof(bool));
|
||||||
heap_deform_tuple(heapTuple, tupleDescriptor, datumArray, isNullArray);
|
heap_deform_tuple(heapTuple, tupleDescriptor, datumArray, isNullArray);
|
||||||
colocatedTableId = DatumGetObjectId(
|
colocatedTableId = DatumGetObjectId(
|
||||||
datumArray[Anum_pg_dist_partition_logicalrelid - 1]);
|
datumArray[Anum_pg_dist_partition_logicalrelid - 1]);
|
||||||
|
@ -1223,6 +1230,8 @@ ColocatedTableId(int32 colocationId)
|
||||||
|
|
||||||
heapTuple = systable_getnext(scanDescriptor);
|
heapTuple = systable_getnext(scanDescriptor);
|
||||||
}
|
}
|
||||||
|
pfree(datumArray);
|
||||||
|
pfree(isNullArray);
|
||||||
|
|
||||||
systable_endscan(scanDescriptor);
|
systable_endscan(scanDescriptor);
|
||||||
table_close(pgDistPartition, AccessShareLock);
|
table_close(pgDistPartition, AccessShareLock);
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#define WORKER_PARTITIONED_TABLE_SIZE_FUNCTION "worker_partitioned_table_size(%s)"
|
#define WORKER_PARTITIONED_TABLE_SIZE_FUNCTION "worker_partitioned_table_size(%s)"
|
||||||
#define WORKER_PARTITIONED_RELATION_SIZE_FUNCTION "worker_partitioned_relation_size(%s)"
|
#define WORKER_PARTITIONED_RELATION_SIZE_FUNCTION "worker_partitioned_relation_size(%s)"
|
||||||
#define WORKER_PARTITIONED_RELATION_TOTAL_SIZE_FUNCTION \
|
#define WORKER_PARTITIONED_RELATION_TOTAL_SIZE_FUNCTION \
|
||||||
"worker_partitioned_relation_total_size(%s)"
|
"worker_partitioned_relation_total_size(%s)"
|
||||||
|
|
||||||
#define SHARD_SIZES_COLUMN_COUNT (2)
|
#define SHARD_SIZES_COLUMN_COUNT (2)
|
||||||
|
|
||||||
|
@ -302,12 +302,12 @@ typedef struct BackgroundTask
|
||||||
} BackgroundTask;
|
} BackgroundTask;
|
||||||
|
|
||||||
#define SET_NULLABLE_FIELD(ptr, field, value) \
|
#define SET_NULLABLE_FIELD(ptr, field, value) \
|
||||||
(ptr)->__nullable_storage.field = (value); \
|
(ptr)->__nullable_storage.field = (value); \
|
||||||
(ptr)->field = &((ptr)->__nullable_storage.field)
|
(ptr)->field = &((ptr)->__nullable_storage.field)
|
||||||
|
|
||||||
#define UNSET_NULLABLE_FIELD(ptr, field) \
|
#define UNSET_NULLABLE_FIELD(ptr, field) \
|
||||||
(ptr)->field = NULL; \
|
(ptr)->field = NULL; \
|
||||||
memset_struct_0((ptr)->__nullable_storage.field)
|
memset_struct_0((ptr)->__nullable_storage.field)
|
||||||
|
|
||||||
/* Size functions */
|
/* Size functions */
|
||||||
extern Datum citus_table_size(PG_FUNCTION_ARGS);
|
extern Datum citus_table_size(PG_FUNCTION_ARGS);
|
||||||
|
@ -345,7 +345,8 @@ extern bool IsDummyPlacement(ShardPlacement *taskPlacement);
|
||||||
extern StringInfo GenerateSizeQueryOnMultiplePlacements(List *shardIntervalList,
|
extern StringInfo GenerateSizeQueryOnMultiplePlacements(List *shardIntervalList,
|
||||||
Oid indexId,
|
Oid indexId,
|
||||||
SizeQueryType sizeQueryType,
|
SizeQueryType sizeQueryType,
|
||||||
bool optimizePartitionCalculations);
|
bool optimizePartitionCalculations
|
||||||
|
);
|
||||||
extern List * RemoveCoordinatorPlacementIfNotSingleNode(List *placementList);
|
extern List * RemoveCoordinatorPlacementIfNotSingleNode(List *placementList);
|
||||||
|
|
||||||
/* Function declarations to modify shard and shard placement data */
|
/* Function declarations to modify shard and shard placement data */
|
||||||
|
@ -466,4 +467,5 @@ extern bool IsBackgroundJobStatusTerminal(BackgroundJobStatus status);
|
||||||
extern bool IsBackgroundTaskStatusTerminal(BackgroundTaskStatus status);
|
extern bool IsBackgroundTaskStatusTerminal(BackgroundTaskStatus status);
|
||||||
extern Oid BackgroundJobStatusOid(BackgroundJobStatus status);
|
extern Oid BackgroundJobStatusOid(BackgroundJobStatus status);
|
||||||
extern Oid BackgroundTaskStatusOid(BackgroundTaskStatus status);
|
extern Oid BackgroundTaskStatusOid(BackgroundTaskStatus status);
|
||||||
|
extern int GetAutoConvertedAttrIndexInPgDistPartition(TupleDesc tupleDEsc);
|
||||||
#endif /* METADATA_UTILITY_H */
|
#endif /* METADATA_UTILITY_H */
|
||||||
|
|
Loading…
Reference in New Issue