Merge pull request #2854 from citusdata/compare_shard_intervals_id_tie_breaker

CompareShardIntervals: if intervals are equal, compare id
pull/2859/head
Philip Dubé 2019-07-26 16:27:35 +00:00 committed by GitHub
commit dc67fa36c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 22 deletions

View File

@ -64,39 +64,40 @@ CompareShardIntervals(const void *leftElement, const void *rightElement,
{
ShardInterval *leftShardInterval = *((ShardInterval **) leftElement);
ShardInterval *rightShardInterval = *((ShardInterval **) rightElement);
Datum leftDatum = 0;
Datum rightDatum = 0;
Datum comparisonDatum = 0;
int comparisonResult = 0;
bool leftHasNull = (!leftShardInterval->minValueExists ||
!leftShardInterval->maxValueExists);
bool rightHasNull = (!rightShardInterval->minValueExists ||
!rightShardInterval->maxValueExists);
Assert(typeCompareFunction != NULL);
/*
* Left element should be treated as the greater element in case it doesn't
* have min or max values.
*/
if (!leftShardInterval->minValueExists || !leftShardInterval->maxValueExists)
if (leftHasNull && rightHasNull)
{
comparisonResult = 0;
}
else if (leftHasNull)
{
comparisonResult = 1;
return comparisonResult;
}
/*
* Right element should be treated as the greater element in case it doesn't
* have min or max values.
*/
if (!rightShardInterval->minValueExists || !rightShardInterval->maxValueExists)
else if (rightHasNull)
{
comparisonResult = -1;
return comparisonResult;
}
else
{
/* if both shard interval have min/max values, calculate comparison result */
Datum leftDatum = leftShardInterval->minValue;
Datum rightDatum = rightShardInterval->minValue;
Datum comparisonDatum = CompareCall2(typeCompareFunction, leftDatum, rightDatum);
comparisonResult = DatumGetInt32(comparisonDatum);
}
/* if both shard interval have min/max values, calculate the comparison result */
leftDatum = leftShardInterval->minValue;
rightDatum = rightShardInterval->minValue;
comparisonDatum = CompareCall2(typeCompareFunction, leftDatum, rightDatum);
comparisonResult = DatumGetInt32(comparisonDatum);
/* Two different shards should never be equal */
if (comparisonResult == 0)
{
return CompareShardIntervalsById(leftElement, rightElement);
}
return comparisonResult;
}

View File

@ -8,8 +8,10 @@
# In all tests, normalize worker ports, placement ids, and shard ids
s/localhost:[0-9]+/localhost:xxxxx/g
s/ port=[0-9]+ / port=xxxxx /g
s/placement [0-9]+/placement xxxxx/g
s/shard [0-9]+/shard xxxxx/g
s/assigned task [0-9]+ to node/assigned task to node/
# In foreign_key_to_reference_table, normalize shard table names, etc in
# the generated plan