aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-04-30 23:28:37 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-04-30 23:28:37 +0000
commit90cdbe43e074b13cae9c84a51ee4040af90a9421 (patch)
treea073a2eeb11ad80b4e56b817d64a18e63d3e7442
parent6750c7a7517f293524299d23d4285a0070e165d5 (diff)
downloadpostgresql-90cdbe43e074b13cae9c84a51ee4040af90a9421.tar.gz
postgresql-90cdbe43e074b13cae9c84a51ee4040af90a9421.zip
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.
-rw-r--r--src/backend/executor/nodeTidscan.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c
index 1a126afc92f..84da56ab984 100644
--- a/src/backend/executor/nodeTidscan.c
+++ b/src/backend/executor/nodeTidscan.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.58 2008/01/01 19:45:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.58.2.1 2008/04/30 23:28:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -54,12 +54,21 @@ TidListCreate(TidScanState *tidstate)
{
List *evalList = tidstate->tss_tidquals;
ExprContext *econtext = tidstate->ss.ps.ps_ExprContext;
+ BlockNumber nblocks;
ItemPointerData *tidList;
int numAllocTids;
int numTids;
ListCell *l;
/*
+ * We silently discard any TIDs that are out of range at the time of
+ * scan start. (Since we hold at least AccessShareLock on the table,
+ * it won't be possible for someone to truncate away the blocks we
+ * intend to visit.)
+ */
+ nblocks = RelationGetNumberOfBlocks(tidstate->ss.ss_currentRelation);
+
+ /*
* We initialize the array with enough slots for the case that all quals
* are simple OpExprs or CurrentOfExprs. If there are any
* ScalarArrayOpExprs, we may have to enlarge the array.
@@ -97,7 +106,9 @@ TidListCreate(TidScanState *tidstate)
econtext,
&isNull,
NULL));
- if (!isNull && ItemPointerIsValid(itemptr))
+ if (!isNull &&
+ ItemPointerIsValid(itemptr) &&
+ ItemPointerGetBlockNumber(itemptr) < nblocks)
{
if (numTids >= numAllocTids)
{
@@ -142,7 +153,8 @@ TidListCreate(TidScanState *tidstate)
if (!ipnulls[i])
{
itemptr = (ItemPointer) DatumGetPointer(ipdatums[i]);
- if (ItemPointerIsValid(itemptr))
+ if (ItemPointerIsValid(itemptr) &&
+ ItemPointerGetBlockNumber(itemptr) < nblocks)
tidList[numTids++] = *itemptr;
}
}