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 *leftShardInterval = *((ShardInterval **) leftElement);
ShardInterval *rightShardInterval = *((ShardInterval **) rightElement); ShardInterval *rightShardInterval = *((ShardInterval **) rightElement);
Datum leftDatum = 0;
Datum rightDatum = 0;
Datum comparisonDatum = 0;
int comparisonResult = 0; int comparisonResult = 0;
bool leftHasNull = (!leftShardInterval->minValueExists ||
!leftShardInterval->maxValueExists);
bool rightHasNull = (!rightShardInterval->minValueExists ||
!rightShardInterval->maxValueExists);
Assert(typeCompareFunction != NULL); Assert(typeCompareFunction != NULL);
/* if (leftHasNull && rightHasNull)
* Left element should be treated as the greater element in case it doesn't {
* have min or max values. comparisonResult = 0;
*/ }
if (!leftShardInterval->minValueExists || !leftShardInterval->maxValueExists) else if (leftHasNull)
{ {
comparisonResult = 1; comparisonResult = 1;
return comparisonResult;
} }
else if (rightHasNull)
/*
* Right element should be treated as the greater element in case it doesn't
* have min or max values.
*/
if (!rightShardInterval->minValueExists || !rightShardInterval->maxValueExists)
{ {
comparisonResult = -1; 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 */ /* Two different shards should never be equal */
leftDatum = leftShardInterval->minValue; if (comparisonResult == 0)
rightDatum = rightShardInterval->minValue; {
return CompareShardIntervalsById(leftElement, rightElement);
comparisonDatum = CompareCall2(typeCompareFunction, leftDatum, rightDatum); }
comparisonResult = DatumGetInt32(comparisonDatum);
return comparisonResult; return comparisonResult;
} }

View File

@ -8,8 +8,10 @@
# In all tests, normalize worker ports, placement ids, and shard ids # In all tests, normalize worker ports, placement ids, and shard ids
s/localhost:[0-9]+/localhost:xxxxx/g s/localhost:[0-9]+/localhost:xxxxx/g
s/ port=[0-9]+ / port=xxxxx /g
s/placement [0-9]+/placement xxxxx/g s/placement [0-9]+/placement xxxxx/g
s/shard [0-9]+/shard 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 # In foreign_key_to_reference_table, normalize shard table names, etc in
# the generated plan # the generated plan