Skip to content

Commit 941aa6a

Browse files
committed
Check the snapshot argument of index_beginscan and family
Passing a NULL snapshot (InvalidSnapshot) is going to work but only as long as the index can't find any matching rows. This can be confusing for the extension authors, so add an explicit check for this argument. The check is implemented with Assert() in order to avoid overhead in release builds. Reported-by: Sven Klemm Discussion: https://postgr.es/m/CAJ7c6TPxitD4vbKyP-mpmC1XwyHdPPqvjLzm%2BVpB88h8LGgneQ%40mail.gmail.com Author: Aleksander Alekseev Reviewed-by: Pavel Borisov
1 parent a7885c9 commit 941aa6a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/backend/access/index/indexam.c

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ index_beginscan(Relation heapRelation,
209209
{
210210
IndexScanDesc scan;
211211

212+
Assert(snapshot != InvalidSnapshot);
213+
212214
scan = index_beginscan_internal(indexRelation, nkeys, norderbys, snapshot, NULL, false);
213215

214216
/*
@@ -237,6 +239,8 @@ index_beginscan_bitmap(Relation indexRelation,
237239
{
238240
IndexScanDesc scan;
239241

242+
Assert(snapshot != InvalidSnapshot);
243+
240244
scan = index_beginscan_internal(indexRelation, nkeys, 0, snapshot, NULL, false);
241245

242246
/*
@@ -403,6 +407,8 @@ index_parallelscan_estimate(Relation indexRelation, Snapshot snapshot)
403407
{
404408
Size nbytes;
405409

410+
Assert(snapshot != InvalidSnapshot);
411+
406412
RELATION_CHECKS;
407413

408414
nbytes = offsetof(ParallelIndexScanDescData, ps_snapshot_data);
@@ -437,6 +443,8 @@ index_parallelscan_initialize(Relation heapRelation, Relation indexRelation,
437443
{
438444
Size offset;
439445

446+
Assert(snapshot != InvalidSnapshot);
447+
440448
RELATION_CHECKS;
441449

442450
offset = add_size(offsetof(ParallelIndexScanDescData, ps_snapshot_data),

0 commit comments

Comments
 (0)