OR clause - check code

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: vadim(at)sable(dot)krasnoyarsk(dot)su (Vadim B(dot) Mikheev)
Cc: hackers(at)postgreSQL(dot)org (PostgreSQL-development)
Subject: OR clause - check code
Date: 1998-08-01 10:55:16
Message-ID: 199808011055.GAA21311@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Vadim, would you please review this code, and let me know if it is
correct. I am unsure about the calls to ExecStoreTuple(), ExecQual()
(is proper context used?), and placement of ReleaseBuffer(). Do I need
to free the tuple buffer if I decide it doesn't meet my ExecQual test?

You will see the old code, then the new for IndexNext().

---------------------------------------------------------------------------

***************
*** 120,155 ****
* appropriate heap tuple.. else return NULL.
* ----------------
*/
! while ((result = index_getnext(scandesc, direction)) != NULL)
{
! tuple = heap_fetch(heapRelation, false, &result->heap_iptr, &buffer);
! /* be tidy */
! pfree(result);
!
! if (tuple != NULL)
{
! /* ----------------
! * store the scanned tuple in the scan tuple slot of
! * the scan state. Eventually we will only do this and not
! * return a tuple. Note: we pass 'false' because tuples
! * returned by amgetnext are pointers onto disk pages and
! * were not created with palloc() and so should not be pfree()'d.
! * ----------------
! */
! ExecStoreTuple(tuple, /* tuple to store */
! slot, /* slot to store in */
! buffer, /* buffer associated with tuple */
! false); /* don't pfree */
!
! return slot;
! }
! else
! {
if (BufferIsValid(buffer))
ReleaseBuffer(buffer);
}
}
-
/* ----------------
* if we get here it means the index scan failed so we
* are at the end of the scan..
--- 119,170 ----
* appropriate heap tuple.. else return NULL.
* ----------------
*/
! while (indexstate->iss_IndexPtr < numIndices)
{
! scandesc = scanDescs[indexstate->iss_IndexPtr];
! while ((result = index_getnext(scandesc, direction)) != NULL)
{
! tuple = heap_fetch(heapRelation, false, &result->heap_iptr, &buffer);
! /* be tidy */
! pfree(result);
!
! if (tuple != NULL)
! {
! bool prev_matches = false;
! int prev_index;
!
! /* ----------------
! * store the scanned tuple in the scan tuple slot of
! * the scan state. Eventually we will only do this and not
! * return a tuple. Note: we pass 'false' because tuples
! * returned by amgetnext are pointers onto disk pages and
! * were not created with palloc() and so should not be pfree()'d.
! * ----------------
! */
! ExecStoreTuple(tuple, /* tuple to store */
! slot, /* slot to store in */
! buffer, /* buffer associated with tuple */
! false); /* don't pfree */
!
! for (prev_index = 0; prev_index < indexstate->iss_IndexPtr;
! prev_index++)
! {
! if (ExecQual(nth(prev_index, node->indxqual),
! scanstate->cstate.cs_ExprContext))
! {
! prev_matches = true;
! break;
! }
! }
! if (!prev_matches)
! return slot;
! }
if (BufferIsValid(buffer))
ReleaseBuffer(buffer);
}
+ if (indexstate->iss_IndexPtr < numIndices)
+ indexstate->iss_IndexPtr++;
}
/* ----------------
* if we get here it means the index scan failed so we
* are at the end of the scan..

--
Bruce Momjian | 830 Blythe Avenue
maillist(at)candle(dot)pha(dot)pa(dot)us | Drexel Hill, Pennsylvania 19026
+ If your life is a hard drive, | (610) 353-9879(w)
+ Christ can be your backup. | (610) 853-3000(h)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1998-08-01 11:33:20 OR with multi-key indexes
Previous Message Vadim Mikheev 1998-08-01 10:06:55 Re: [HACKERS] Dropping tables...