Skip to content

Commit 289992c

Browse files
committed
Don't invoke arbitrary code inside a possibly-aborted transaction.
The code here previously tried to call the partitioning operator, but really the right thing to do (and the safe thing to do) is use datumIsEqual(). Amit Langote, but I expanded the comment and fixed a compiler warning.
1 parent b1ecb9b commit 289992c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/backend/catalog/partition.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,20 @@ partition_bounds_equal(PartitionKey key,
639639
continue;
640640
}
641641

642-
/* Compare the actual values */
643-
cmpval = DatumGetInt32(FunctionCall2Coll(&key->partsupfunc[j],
644-
key->partcollation[j],
645-
b1->datums[i][j],
646-
b2->datums[i][j]));
647-
if (cmpval != 0)
642+
/*
643+
* Compare the actual values. Note that it would be both incorrect
644+
* and unsafe to invoke the comparison operator derived from the
645+
* partitioning specification here. It would be incorrect because
646+
* we want the relcache entry to be updated for ANY change to the
647+
* partition bounds, not just those that the partitioning operator
648+
* thinks are significant. It would be unsafe because we might
649+
* reach this code in the context of an aborted transaction, and
650+
* an arbitrary partitioning operator might not be safe in that
651+
* context. datumIsEqual() should be simple enough to be safe.
652+
*/
653+
if (!datumIsEqual(b1->datums[i][j], b2->datums[i][j],
654+
key->parttypbyval[j],
655+
key->parttyplen[j]))
648656
return false;
649657
}
650658

src/backend/utils/adt/datum.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ datumTransfer(Datum value, bool typByVal, int typLen)
209209
* of say the representation of zero in one's complement arithmetic).
210210
* Also, it will probably not give the answer you want if either
211211
* datum has been "toasted".
212+
*
213+
* Do not try to make this any smarter than it currently is with respect
214+
* to "toasted" datums, because some of the callers could be working in the
215+
* context of an aborted transaction.
212216
*-------------------------------------------------------------------------
213217
*/
214218
bool

0 commit comments

Comments
 (0)