*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.206 2006/01/11 08:43:11 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.207 2006/02/21 23:01:53 neilc Exp $
*
*
* INTERFACE ROUTINES
* tuple as indicated by "dir"; return the next tuple in scan->rs_ctup,
* or set scan->rs_ctup.t_data = NULL if no more tuples.
*
- * dir == 0 means "re-fetch the tuple indicated by scan->rs_ctup".
+ * dir == NoMovementScanDirection means "re-fetch the tuple indicated
+ * by scan->rs_ctup".
*
* Note: the reason nkeys/key are passed separately, even though they are
* kept in the scan descriptor, is that the caller may not want us to check
*/
static void
heapgettup(HeapScanDesc scan,
- int dir,
+ ScanDirection dir,
int nkeys,
ScanKey key)
{
HeapTuple tuple = &(scan->rs_ctup);
Snapshot snapshot = scan->rs_snapshot;
+ bool backward = ScanDirectionIsBackward(dir);
BlockNumber page;
Page dp;
int lines;
/*
* calculate next starting lineoff, given scan direction
*/
- if (dir > 0)
+ if (ScanDirectionIsForward(dir))
{
- /*
- * forward scan direction
- */
if (!scan->rs_inited)
{
/*
linesleft = lines - lineoff + 1;
}
- else if (dir < 0)
+ else if (backward)
{
- /*
- * reverse scan direction
- */
if (!scan->rs_inited)
{
/*
* otherwise move to the next item on the page
*/
--linesleft;
- if (dir < 0)
+ if (backward)
{
--lpp; /* move back in this page's ItemId array */
--lineoff;
/*
* return NULL if we've exhausted all the pages
*/
- if ((dir < 0) ? (page == 0) : (page + 1 >= scan->rs_nblocks))
+ if (backward ? (page == 0) : (page + 1 >= scan->rs_nblocks))
{
if (BufferIsValid(scan->rs_cbuf))
ReleaseBuffer(scan->rs_cbuf);
return;
}
- page = (dir < 0) ? (page - 1) : (page + 1);
+ page = backward ? (page - 1) : (page + 1);
heapgetpage(scan, page);
dp = (Page) BufferGetPage(scan->rs_cbuf);
lines = PageGetMaxOffsetNumber((Page) dp);
linesleft = lines;
- if (dir < 0)
+ if (backward)
{
lineoff = lines;
lpp = PageGetItemId(dp, lines);
*/
static void
heapgettup_pagemode(HeapScanDesc scan,
- int dir,
+ ScanDirection dir,
int nkeys,
ScanKey key)
{
HeapTuple tuple = &(scan->rs_ctup);
+ bool backward = ScanDirectionIsBackward(dir);
BlockNumber page;
Page dp;
int lines;
/*
* calculate next starting lineindex, given scan direction
*/
- if (dir > 0)
+ if (ScanDirectionIsForward(dir))
{
- /*
- * forward scan direction
- */
if (!scan->rs_inited)
{
/*
linesleft = lines - lineindex;
}
- else if (dir < 0)
+ else if (backward)
{
- /*
- * reverse scan direction
- */
if (!scan->rs_inited)
{
/*
* otherwise move to the next item on the page
*/
--linesleft;
- if (dir < 0)
- {
+ if (backward)
--lineindex;
- }
else
- {
++lineindex;
- }
}
/*
/*
* return NULL if we've exhausted all the pages
*/
- if ((dir < 0) ? (page == 0) : (page + 1 >= scan->rs_nblocks))
+ if (backward ? (page == 0) : (page + 1 >= scan->rs_nblocks))
{
if (BufferIsValid(scan->rs_cbuf))
ReleaseBuffer(scan->rs_cbuf);
return;
}
- page = (dir < 0) ? (page - 1) : (page + 1);
-
+ page = backward ? (page - 1) : (page + 1);
heapgetpage(scan, page);
dp = (Page) BufferGetPage(scan->rs_cbuf);
lines = scan->rs_ntuples;
linesleft = lines;
- if (dir < 0)
+ if (backward)
lineindex = lines - 1;
else
lineindex = 0;
HEAPDEBUG_1; /* heap_getnext( info ) */
- /*
- * Note: we depend here on the -1/0/1 encoding of ScanDirection.
- */
if (scan->rs_pageatatime)
- heapgettup_pagemode(scan, (int) direction,
+ heapgettup_pagemode(scan, direction,
scan->rs_nkeys, scan->rs_key);
else
- heapgettup(scan, (int) direction,
- scan->rs_nkeys, scan->rs_key);
+ heapgettup(scan, direction, scan->rs_nkeys, scan->rs_key);
if (scan->rs_ctup.t_data == NULL)
{
{
scan->rs_cindex = scan->rs_mindex;
heapgettup_pagemode(scan,
- 0, /* "no movement" */
+ NoMovementScanDirection,
0, /* needn't recheck scan keys */
NULL);
}
else
heapgettup(scan,
- 0, /* "no movement" */
+ NoMovementScanDirection,
0, /* needn't recheck scan keys */
NULL);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.98 2005/11/22 18:17:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.99 2006/02/21 23:01:54 neilc Exp $
*
*-------------------------------------------------------------------------
*/
nprocessed = queryDesc->estate->es_processed;
}
- if (direction != NoMovementScanDirection)
+ if (!ScanDirectionIsNoMovement(direction))
{
long oldPos;
nprocessed = queryDesc->estate->es_processed;
}
- if (direction != NoMovementScanDirection)
+ if (!ScanDirectionIsNoMovement(direction))
{
if (nprocessed > 0 && portal->atEnd)
{
(*dest->rStartup) (dest, CMD_SELECT, portal->tupDesc);
- if (direction == NoMovementScanDirection)
+ if (ScanDirectionIsNoMovement(direction))
{
/* do nothing except start/stop the destination */
}
else
{
- bool forward = (direction == ForwardScanDirection);
+ bool forward = ScanDirectionIsForward(direction);
for (;;)
{