Skip to content

Commit 772f63d

Browse files
committed
Fix nodeTidscan.c to not trigger an error if the block number portion of
a user-supplied TID is out of range for the relation. This is needed to preserve compatibility with our pre-8.3 behavior, and it is sensible anyway since if the query were implemented by brute force rather than optimized into a TidScan, the behavior for a non-existent TID would be zero rows out, never an error. Per gripe from Gurjeet Singh.
1 parent ca0aecf commit 772f63d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/backend/executor/nodeTidscan.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.58 2008/01/01 19:45:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.59 2008/04/30 23:28:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -54,11 +54,20 @@ TidListCreate(TidScanState *tidstate)
5454
{
5555
List *evalList = tidstate->tss_tidquals;
5656
ExprContext *econtext = tidstate->ss.ps.ps_ExprContext;
57+
BlockNumber nblocks;
5758
ItemPointerData *tidList;
5859
int numAllocTids;
5960
int numTids;
6061
ListCell *l;
6162

63+
/*
64+
* We silently discard any TIDs that are out of range at the time of
65+
* scan start. (Since we hold at least AccessShareLock on the table,
66+
* it won't be possible for someone to truncate away the blocks we
67+
* intend to visit.)
68+
*/
69+
nblocks = RelationGetNumberOfBlocks(tidstate->ss.ss_currentRelation);
70+
6271
/*
6372
* We initialize the array with enough slots for the case that all quals
6473
* are simple OpExprs or CurrentOfExprs. If there are any
@@ -97,7 +106,9 @@ TidListCreate(TidScanState *tidstate)
97106
econtext,
98107
&isNull,
99108
NULL));
100-
if (!isNull && ItemPointerIsValid(itemptr))
109+
if (!isNull &&
110+
ItemPointerIsValid(itemptr) &&
111+
ItemPointerGetBlockNumber(itemptr) < nblocks)
101112
{
102113
if (numTids >= numAllocTids)
103114
{
@@ -142,7 +153,8 @@ TidListCreate(TidScanState *tidstate)
142153
if (!ipnulls[i])
143154
{
144155
itemptr = (ItemPointer) DatumGetPointer(ipdatums[i]);
145-
if (ItemPointerIsValid(itemptr))
156+
if (ItemPointerIsValid(itemptr) &&
157+
ItemPointerGetBlockNumber(itemptr) < nblocks)
146158
tidList[numTids++] = *itemptr;
147159
}
148160
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy