diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 4ba8e8fc6d..35911039f7 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8,7 +8,7 @@ * * * 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 @@ -172,7 +172,8 @@ heapgetpage(HeapScanDesc scan, BlockNumber page) * 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 @@ -189,12 +190,13 @@ heapgetpage(HeapScanDesc scan, BlockNumber page) */ 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; @@ -205,11 +207,8 @@ heapgettup(HeapScanDesc scan, /* * calculate next starting lineoff, given scan direction */ - if (dir > 0) + if (ScanDirectionIsForward(dir)) { - /* - * forward scan direction - */ if (!scan->rs_inited) { /* @@ -242,11 +241,8 @@ heapgettup(HeapScanDesc scan, linesleft = lines - lineoff + 1; } - else if (dir < 0) + else if (backward) { - /* - * reverse scan direction - */ if (!scan->rs_inited) { /* @@ -352,7 +348,7 @@ heapgettup(HeapScanDesc scan, * 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; @@ -373,7 +369,7 @@ heapgettup(HeapScanDesc scan, /* * 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); @@ -384,7 +380,7 @@ heapgettup(HeapScanDesc scan, return; } - page = (dir < 0) ? (page - 1) : (page + 1); + page = backward ? (page - 1) : (page + 1); heapgetpage(scan, page); @@ -393,7 +389,7 @@ heapgettup(HeapScanDesc scan, dp = (Page) BufferGetPage(scan->rs_cbuf); lines = PageGetMaxOffsetNumber((Page) dp); linesleft = lines; - if (dir < 0) + if (backward) { lineoff = lines; lpp = PageGetItemId(dp, lines); @@ -421,11 +417,12 @@ heapgettup(HeapScanDesc scan, */ 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; @@ -437,11 +434,8 @@ heapgettup_pagemode(HeapScanDesc scan, /* * calculate next starting lineindex, given scan direction */ - if (dir > 0) + if (ScanDirectionIsForward(dir)) { - /* - * forward scan direction - */ if (!scan->rs_inited) { /* @@ -471,11 +465,8 @@ heapgettup_pagemode(HeapScanDesc scan, linesleft = lines - lineindex; } - else if (dir < 0) + else if (backward) { - /* - * reverse scan direction - */ if (!scan->rs_inited) { /* @@ -584,14 +575,10 @@ heapgettup_pagemode(HeapScanDesc scan, * otherwise move to the next item on the page */ --linesleft; - if (dir < 0) - { + if (backward) --lineindex; - } else - { ++lineindex; - } } /* @@ -602,7 +589,7 @@ heapgettup_pagemode(HeapScanDesc scan, /* * 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); @@ -613,14 +600,13 @@ heapgettup_pagemode(HeapScanDesc scan, 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; @@ -1008,15 +994,11 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction) 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) { @@ -2745,13 +2727,13 @@ heap_restrpos(HeapScanDesc scan) { 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); } diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 99c3bca0a9..57570a5cc0 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.266 2006/02/19 00:04:26 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.267 2006/02/21 23:01:54 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -218,7 +218,7 @@ ExecutorRun(QueryDesc *queryDesc, /* * run plan */ - if (direction == NoMovementScanDirection) + if (ScanDirectionIsNoMovement(direction)) result = NULL; else result = ExecutePlan(estate, diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index 09919dbbc5..001be06521 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -8,7 +8,7 @@ * * * 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 $ * *------------------------------------------------------------------------- */ @@ -795,7 +795,7 @@ PortalRunSelect(Portal portal, nprocessed = queryDesc->estate->es_processed; } - if (direction != NoMovementScanDirection) + if (!ScanDirectionIsNoMovement(direction)) { long oldPos; @@ -837,7 +837,7 @@ PortalRunSelect(Portal portal, nprocessed = queryDesc->estate->es_processed; } - if (direction != NoMovementScanDirection) + if (!ScanDirectionIsNoMovement(direction)) { if (nprocessed > 0 && portal->atEnd) { @@ -890,13 +890,13 @@ RunFromStore(Portal portal, ScanDirection direction, long count, (*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 (;;) {