mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
pgindent run. Make it all clean.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.40 2001/01/24 19:42:48 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.41 2001/03/22 03:59:14 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -150,8 +150,8 @@ btoidvectorcmp(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
btabstimecmp(PG_FUNCTION_ARGS)
|
||||
{
|
||||
AbsoluteTime a = PG_GETARG_ABSOLUTETIME(0);
|
||||
AbsoluteTime b = PG_GETARG_ABSOLUTETIME(1);
|
||||
AbsoluteTime a = PG_GETARG_ABSOLUTETIME(0);
|
||||
AbsoluteTime b = PG_GETARG_ABSOLUTETIME(1);
|
||||
|
||||
if (AbsoluteTimeIsBefore(a, b))
|
||||
PG_RETURN_INT32(-1);
|
||||
@@ -236,9 +236,10 @@ bttextcmp(PG_FUNCTION_ARGS)
|
||||
|
||||
if (res == 0 && VARSIZE(a) != VARSIZE(b))
|
||||
{
|
||||
|
||||
/*
|
||||
* The two strings are the same in the first len bytes,
|
||||
* and they are of different lengths.
|
||||
* The two strings are the same in the first len bytes, and they
|
||||
* are of different lengths.
|
||||
*/
|
||||
if (VARSIZE(a) < VARSIZE(b))
|
||||
res = -1;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.50 2001/02/07 23:35:33 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.51 2001/03/22 03:59:14 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Postgres btree pages look like ordinary relation pages. The opaque
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "storage/lmgr.h"
|
||||
|
||||
extern bool FixBTree; /* comments in nbtree.c */
|
||||
extern bool FixBTree; /* comments in nbtree.c */
|
||||
extern Buffer _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release);
|
||||
|
||||
/*
|
||||
@@ -100,7 +100,7 @@ _bt_metapinit(Relation rel)
|
||||
*
|
||||
* The access type parameter (BT_READ or BT_WRITE) controls whether
|
||||
* a new root page will be created or not. If access = BT_READ,
|
||||
* and no root page exists, we just return InvalidBuffer. For
|
||||
* and no root page exists, we just return InvalidBuffer. For
|
||||
* BT_WRITE, we try to create the root page if it doesn't exist.
|
||||
* NOTE that the returned root page will have only a read lock set
|
||||
* on it even if access = BT_WRITE!
|
||||
@@ -178,20 +178,20 @@ _bt_getroot(Relation rel, int access)
|
||||
|
||||
/* XLOG stuff */
|
||||
{
|
||||
xl_btree_newroot xlrec;
|
||||
XLogRecPtr recptr;
|
||||
XLogRecData rdata;
|
||||
xl_btree_newroot xlrec;
|
||||
XLogRecPtr recptr;
|
||||
XLogRecData rdata;
|
||||
|
||||
xlrec.node = rel->rd_node;
|
||||
xlrec.level = 1;
|
||||
BlockIdSet(&(xlrec.rootblk), rootblkno);
|
||||
rdata.buffer = InvalidBuffer;
|
||||
rdata.data = (char*)&xlrec;
|
||||
rdata.data = (char *) &xlrec;
|
||||
rdata.len = SizeOfBtreeNewroot;
|
||||
rdata.next = NULL;
|
||||
|
||||
recptr = XLogInsert(RM_BTREE_ID,
|
||||
XLOG_BTREE_NEWROOT|XLOG_BTREE_LEAF, &rdata);
|
||||
XLOG_BTREE_NEWROOT | XLOG_BTREE_LEAF, &rdata);
|
||||
|
||||
PageSetLSN(rootpage, recptr);
|
||||
PageSetSUI(rootpage, ThisStartUpID);
|
||||
@@ -212,6 +212,7 @@ _bt_getroot(Relation rel, int access)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* Metadata initialized by someone else. In order to
|
||||
* guarantee no deadlocks, we have to release the metadata
|
||||
@@ -232,30 +233,31 @@ _bt_getroot(Relation rel, int access)
|
||||
/*
|
||||
* Race condition: If the root page split between the time we looked
|
||||
* at the metadata page and got the root buffer, then we got the wrong
|
||||
* buffer. Release it and try again.
|
||||
* buffer. Release it and try again.
|
||||
*/
|
||||
rootpage = BufferGetPage(rootbuf);
|
||||
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
|
||||
|
||||
if (! P_ISROOT(rootopaque))
|
||||
if (!P_ISROOT(rootopaque))
|
||||
{
|
||||
|
||||
/*
|
||||
* It happened, but if root page splitter failed to create
|
||||
* new root page then we'll go in loop trying to call
|
||||
* _bt_getroot again and again.
|
||||
* It happened, but if root page splitter failed to create new
|
||||
* root page then we'll go in loop trying to call _bt_getroot
|
||||
* again and again.
|
||||
*/
|
||||
if (FixBTree)
|
||||
{
|
||||
Buffer newrootbuf;
|
||||
Buffer newrootbuf;
|
||||
|
||||
check_parent:;
|
||||
if (BTreeInvalidParent(rootopaque)) /* unupdated! */
|
||||
check_parent:;
|
||||
if (BTreeInvalidParent(rootopaque)) /* unupdated! */
|
||||
{
|
||||
LockBuffer(rootbuf, BUFFER_LOCK_UNLOCK);
|
||||
LockBuffer(rootbuf, BT_WRITE);
|
||||
|
||||
/* handle concurrent fix of root page */
|
||||
if (BTreeInvalidParent(rootopaque)) /* unupdated! */
|
||||
if (BTreeInvalidParent(rootopaque)) /* unupdated! */
|
||||
{
|
||||
elog(NOTICE, "bt_getroot[%s]: fixing root page", RelationGetRelationName(rel));
|
||||
newrootbuf = _bt_fixroot(rel, rootbuf, true);
|
||||
@@ -266,20 +268,22 @@ check_parent:;
|
||||
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
|
||||
/* New root might be splitted while changing lock */
|
||||
if (P_ISROOT(rootopaque))
|
||||
return(rootbuf);
|
||||
return (rootbuf);
|
||||
/* rootbuf is read locked */
|
||||
goto check_parent;
|
||||
}
|
||||
else /* someone else already fixed root */
|
||||
else
|
||||
/* someone else already fixed root */
|
||||
{
|
||||
LockBuffer(rootbuf, BUFFER_LOCK_UNLOCK);
|
||||
LockBuffer(rootbuf, BT_READ);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Ok, here we have old root page with btpo_parent pointing
|
||||
* to upper level - check parent page because of there is
|
||||
* good chance that parent is root page.
|
||||
* Ok, here we have old root page with btpo_parent pointing to
|
||||
* upper level - check parent page because of there is good
|
||||
* chance that parent is root page.
|
||||
*/
|
||||
newrootbuf = _bt_getbuf(rel, rootopaque->btpo_parent, BT_READ);
|
||||
_bt_relbuf(rel, rootbuf, BT_READ);
|
||||
@@ -287,7 +291,7 @@ check_parent:;
|
||||
rootpage = BufferGetPage(rootbuf);
|
||||
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
|
||||
if (P_ISROOT(rootopaque))
|
||||
return(rootbuf);
|
||||
return (rootbuf);
|
||||
/* no luck -:( */
|
||||
}
|
||||
|
||||
@@ -366,7 +370,7 @@ _bt_relbuf(Relation rel, Buffer buf, int access)
|
||||
* and a pin on the buffer.
|
||||
*
|
||||
* NOTE: actually, the buffer manager just marks the shared buffer page
|
||||
* dirty here, the real I/O happens later. Since we can't persuade the
|
||||
* dirty here, the real I/O happens later. Since we can't persuade the
|
||||
* Unix kernel to schedule disk writes in a particular order, there's not
|
||||
* much point in worrying about this. The most we can say is that all the
|
||||
* writes will occur before commit.
|
||||
@@ -468,14 +472,14 @@ _bt_pagedel(Relation rel, ItemPointer tid)
|
||||
PageIndexTupleDelete(page, offno);
|
||||
/* XLOG stuff */
|
||||
{
|
||||
xl_btree_delete xlrec;
|
||||
XLogRecPtr recptr;
|
||||
XLogRecData rdata[2];
|
||||
xl_btree_delete xlrec;
|
||||
XLogRecPtr recptr;
|
||||
XLogRecData rdata[2];
|
||||
|
||||
xlrec.target.node = rel->rd_node;
|
||||
xlrec.target.tid = *tid;
|
||||
rdata[0].buffer = InvalidBuffer;
|
||||
rdata[0].data = (char*)&xlrec;
|
||||
rdata[0].data = (char *) &xlrec;
|
||||
rdata[0].len = SizeOfBtreeDelete;
|
||||
rdata[0].next = &(rdata[1]);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.78 2001/02/07 23:35:33 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.79 2001/03/22 03:59:15 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -30,7 +30,8 @@
|
||||
|
||||
bool BuildingBtree = false; /* see comment in btbuild() */
|
||||
bool FastBuild = true; /* use sort/build instead */
|
||||
/* of insertion build */
|
||||
|
||||
/* of insertion build */
|
||||
|
||||
|
||||
/*
|
||||
@@ -52,12 +53,14 @@ static void _bt_restscan(IndexScanDesc scan);
|
||||
Datum
|
||||
btbuild(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Relation heap = (Relation) PG_GETARG_POINTER(0);
|
||||
Relation index = (Relation) PG_GETARG_POINTER(1);
|
||||
IndexInfo *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
|
||||
Node *oldPred = (Node *) PG_GETARG_POINTER(3);
|
||||
Relation heap = (Relation) PG_GETARG_POINTER(0);
|
||||
Relation index = (Relation) PG_GETARG_POINTER(1);
|
||||
IndexInfo *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
|
||||
Node *oldPred = (Node *) PG_GETARG_POINTER(3);
|
||||
|
||||
#ifdef NOT_USED
|
||||
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
|
||||
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
|
||||
|
||||
#endif
|
||||
HeapScanDesc hscan;
|
||||
HeapTuple htup;
|
||||
@@ -69,9 +72,11 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
int nhtups,
|
||||
nitups;
|
||||
Node *pred = indexInfo->ii_Predicate;
|
||||
|
||||
#ifndef OMIT_PARTIAL_INDEX
|
||||
TupleTable tupleTable;
|
||||
TupleTableSlot *slot;
|
||||
|
||||
#endif
|
||||
ExprContext *econtext;
|
||||
InsertIndexResult res = NULL;
|
||||
@@ -79,15 +84,16 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
BTItem btitem;
|
||||
bool usefast;
|
||||
Snapshot snapshot;
|
||||
TransactionId XmaxRecent;
|
||||
TransactionId XmaxRecent;
|
||||
|
||||
/*
|
||||
* spool2 is needed only when the index is an unique index.
|
||||
* Dead tuples are put into spool2 instead of spool in
|
||||
* order to avoid uniqueness check.
|
||||
* spool2 is needed only when the index is an unique index. Dead
|
||||
* tuples are put into spool2 instead of spool in order to avoid
|
||||
* uniqueness check.
|
||||
*/
|
||||
BTSpool *spool2 = NULL;
|
||||
BTSpool *spool2 = NULL;
|
||||
bool tupleIsAlive;
|
||||
int dead_count;
|
||||
int dead_count;
|
||||
|
||||
/* note that this is a new btree */
|
||||
BuildingBtree = true;
|
||||
@@ -103,7 +109,7 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
#ifdef BTREE_BUILD_STATS
|
||||
if (Show_btree_build_stats)
|
||||
ResetUsage();
|
||||
#endif /* BTREE_BUILD_STATS */
|
||||
#endif /* BTREE_BUILD_STATS */
|
||||
|
||||
/* initialize the btree index metadata page (if this is a new index) */
|
||||
if (oldPred == NULL)
|
||||
@@ -155,10 +161,10 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
if (usefast)
|
||||
{
|
||||
spool = _bt_spoolinit(index, indexInfo->ii_Unique);
|
||||
|
||||
/*
|
||||
* Different from spool,the uniqueness isn't checked
|
||||
* for spool2.
|
||||
*/
|
||||
* Different from spool,the uniqueness isn't checked for spool2.
|
||||
*/
|
||||
if (indexInfo->ii_Unique)
|
||||
spool2 = _bt_spoolinit(index, false);
|
||||
}
|
||||
@@ -187,12 +193,13 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
}
|
||||
else
|
||||
tupleIsAlive = true;
|
||||
|
||||
|
||||
MemoryContextReset(econtext->ecxt_per_tuple_memory);
|
||||
|
||||
nhtups++;
|
||||
|
||||
#ifndef OMIT_PARTIAL_INDEX
|
||||
|
||||
/*
|
||||
* If oldPred != NULL, this is an EXTEND INDEX command, so skip
|
||||
* this tuple if it was already in the existing partial index
|
||||
@@ -253,8 +260,7 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
* btree pages - NULLs greater NOT_NULLs and NULL = NULL is TRUE.
|
||||
* Sure, it's just rule for placing/finding items and no more -
|
||||
* keytest'll return FALSE for a = 5 for items having 'a' isNULL.
|
||||
* Look at _bt_compare for how it works.
|
||||
* - vadim 03/23/97
|
||||
* Look at _bt_compare for how it works. - vadim 03/23/97
|
||||
*
|
||||
* if (itup->t_info & INDEX_NULL_MASK) { pfree(itup); continue; }
|
||||
*/
|
||||
@@ -271,7 +277,8 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (tupleIsAlive || !spool2)
|
||||
_bt_spool(btitem, spool);
|
||||
else /* dead tuples are put into spool2 */
|
||||
else
|
||||
/* dead tuples are put into spool2 */
|
||||
{
|
||||
dead_count++;
|
||||
_bt_spool(btitem, spool2);
|
||||
@@ -288,7 +295,7 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
|
||||
/* okay, all heap tuples are indexed */
|
||||
heap_endscan(hscan);
|
||||
if (spool2 && !dead_count) /* spool2 was found to be unnecessary */
|
||||
if (spool2 && !dead_count) /* spool2 was found to be unnecessary */
|
||||
{
|
||||
_bt_spooldestroy(spool2);
|
||||
spool2 = NULL;
|
||||
@@ -296,9 +303,7 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
|
||||
#ifndef OMIT_PARTIAL_INDEX
|
||||
if (pred != NULL || oldPred != NULL)
|
||||
{
|
||||
ExecDropTupleTable(tupleTable, true);
|
||||
}
|
||||
#endif /* OMIT_PARTIAL_INDEX */
|
||||
FreeExprContext(econtext);
|
||||
|
||||
@@ -322,7 +327,7 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
ShowUsage();
|
||||
ResetUsage();
|
||||
}
|
||||
#endif /* BTREE_BUILD_STATS */
|
||||
#endif /* BTREE_BUILD_STATS */
|
||||
|
||||
/*
|
||||
* Since we just counted the tuples in the heap, we update its stats
|
||||
@@ -368,11 +373,11 @@ btbuild(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
btinsert(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Relation rel = (Relation) PG_GETARG_POINTER(0);
|
||||
Datum *datum = (Datum *) PG_GETARG_POINTER(1);
|
||||
char *nulls = (char *) PG_GETARG_POINTER(2);
|
||||
ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
|
||||
Relation heapRel = (Relation) PG_GETARG_POINTER(4);
|
||||
Relation rel = (Relation) PG_GETARG_POINTER(0);
|
||||
Datum *datum = (Datum *) PG_GETARG_POINTER(1);
|
||||
char *nulls = (char *) PG_GETARG_POINTER(2);
|
||||
ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
|
||||
Relation heapRel = (Relation) PG_GETARG_POINTER(4);
|
||||
InsertIndexResult res;
|
||||
BTItem btitem;
|
||||
IndexTuple itup;
|
||||
@@ -396,8 +401,8 @@ btinsert(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
btgettuple(PG_FUNCTION_ARGS)
|
||||
{
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1);
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1);
|
||||
RetrieveIndexResult res;
|
||||
|
||||
/*
|
||||
@@ -408,10 +413,11 @@ btgettuple(PG_FUNCTION_ARGS)
|
||||
|
||||
if (ItemPointerIsValid(&(scan->currentItemData)))
|
||||
{
|
||||
|
||||
/*
|
||||
* Restore scan position using heap TID returned by previous call
|
||||
* to btgettuple(). _bt_restscan() re-grabs the read lock on
|
||||
* the buffer, too.
|
||||
* to btgettuple(). _bt_restscan() re-grabs the read lock on the
|
||||
* buffer, too.
|
||||
*/
|
||||
_bt_restscan(scan);
|
||||
res = _bt_next(scan, dir);
|
||||
@@ -421,8 +427,8 @@ btgettuple(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* Save heap TID to use it in _bt_restscan. Then release the read
|
||||
* lock on the buffer so that we aren't blocking other backends.
|
||||
* NOTE: we do keep the pin on the buffer!
|
||||
* lock on the buffer so that we aren't blocking other backends. NOTE:
|
||||
* we do keep the pin on the buffer!
|
||||
*/
|
||||
if (res)
|
||||
{
|
||||
@@ -461,11 +467,13 @@ btbeginscan(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
btrescan(PG_FUNCTION_ARGS)
|
||||
{
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
|
||||
#ifdef NOT_USED /* XXX surely it's wrong to ignore this? */
|
||||
bool fromEnd = PG_GETARG_BOOL(1);
|
||||
bool fromEnd = PG_GETARG_BOOL(1);
|
||||
|
||||
#endif
|
||||
ScanKey scankey = (ScanKey) PG_GETARG_POINTER(2);
|
||||
ScanKey scankey = (ScanKey) PG_GETARG_POINTER(2);
|
||||
ItemPointer iptr;
|
||||
BTScanOpaque so;
|
||||
|
||||
@@ -540,7 +548,7 @@ btmovescan(IndexScanDesc scan, Datum v)
|
||||
Datum
|
||||
btendscan(PG_FUNCTION_ARGS)
|
||||
{
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
ItemPointer iptr;
|
||||
BTScanOpaque so;
|
||||
|
||||
@@ -578,7 +586,7 @@ btendscan(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
btmarkpos(PG_FUNCTION_ARGS)
|
||||
{
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
ItemPointer iptr;
|
||||
BTScanOpaque so;
|
||||
|
||||
@@ -610,7 +618,7 @@ btmarkpos(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
btrestrpos(PG_FUNCTION_ARGS)
|
||||
{
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
|
||||
ItemPointer iptr;
|
||||
BTScanOpaque so;
|
||||
|
||||
@@ -640,8 +648,8 @@ btrestrpos(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
btdelete(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Relation rel = (Relation) PG_GETARG_POINTER(0);
|
||||
ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
|
||||
Relation rel = (Relation) PG_GETARG_POINTER(0);
|
||||
ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
|
||||
|
||||
/* adjust any active scans that will be affected by this deletion */
|
||||
_bt_adjscans(rel, tid);
|
||||
@@ -671,8 +679,8 @@ _bt_restscan(IndexScanDesc scan)
|
||||
BlockNumber blkno;
|
||||
|
||||
/*
|
||||
* Get back the read lock we were holding on the buffer.
|
||||
* (We still have a reference-count pin on it, though.)
|
||||
* Get back the read lock we were holding on the buffer. (We still
|
||||
* have a reference-count pin on it, though.)
|
||||
*/
|
||||
LockBuffer(buf, BT_READ);
|
||||
|
||||
@@ -689,13 +697,13 @@ _bt_restscan(IndexScanDesc scan)
|
||||
if (!ItemPointerIsValid(&target))
|
||||
{
|
||||
ItemPointerSetOffsetNumber(current,
|
||||
OffsetNumberPrev(P_FIRSTDATAKEY(opaque)));
|
||||
OffsetNumberPrev(P_FIRSTDATAKEY(opaque)));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* The item we were on may have moved right due to insertions.
|
||||
* Find it again.
|
||||
* The item we were on may have moved right due to insertions. Find it
|
||||
* again.
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
@@ -717,7 +725,8 @@ _bt_restscan(IndexScanDesc scan)
|
||||
}
|
||||
|
||||
/*
|
||||
* By here, the item we're looking for moved right at least one page
|
||||
* By here, the item we're looking for moved right at least one
|
||||
* page
|
||||
*/
|
||||
if (P_RIGHTMOST(opaque))
|
||||
elog(FATAL, "_bt_restscan: my bits moved right off the end of the world!"
|
||||
@@ -742,14 +751,14 @@ _bt_restore_page(Page page, char *from, int len)
|
||||
Size itemsz;
|
||||
char *end = from + len;
|
||||
|
||||
for ( ; from < end; )
|
||||
for (; from < end;)
|
||||
{
|
||||
memcpy(&btdata, from, sizeof(BTItemData));
|
||||
itemsz = IndexTupleDSize(btdata.bti_itup) +
|
||||
(sizeof(BTItemData) - sizeof(IndexTupleData));
|
||||
(sizeof(BTItemData) - sizeof(IndexTupleData));
|
||||
itemsz = MAXALIGN(itemsz);
|
||||
if (PageAddItem(page, (Item) from, itemsz,
|
||||
FirstOffsetNumber, LP_USED) == InvalidOffsetNumber)
|
||||
FirstOffsetNumber, LP_USED) == InvalidOffsetNumber)
|
||||
elog(STOP, "_bt_restore_page: can't add item to page");
|
||||
from += itemsz;
|
||||
}
|
||||
@@ -758,20 +767,20 @@ _bt_restore_page(Page page, char *from, int len)
|
||||
static void
|
||||
btree_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
xl_btree_delete *xlrec;
|
||||
Relation reln;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
xl_btree_delete *xlrec;
|
||||
Relation reln;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
|
||||
if (!redo || (record->xl_info & XLR_BKP_BLOCK_1))
|
||||
return;
|
||||
|
||||
xlrec = (xl_btree_delete*) XLogRecGetData(record);
|
||||
xlrec = (xl_btree_delete *) XLogRecGetData(record);
|
||||
reln = XLogOpenRelation(redo, RM_BTREE_ID, xlrec->target.node);
|
||||
if (!RelationIsValid(reln))
|
||||
return;
|
||||
buffer = XLogReadBuffer(false, reln,
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid)));
|
||||
buffer = XLogReadBuffer(false, reln,
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid)));
|
||||
if (!BufferIsValid(buffer))
|
||||
elog(STOP, "btree_delete_redo: block unfound");
|
||||
page = (Page) BufferGetPage(buffer);
|
||||
@@ -796,21 +805,21 @@ btree_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
static void
|
||||
btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
xl_btree_insert *xlrec;
|
||||
Relation reln;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
BTPageOpaque pageop;
|
||||
xl_btree_insert *xlrec;
|
||||
Relation reln;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
BTPageOpaque pageop;
|
||||
|
||||
if (redo && (record->xl_info & XLR_BKP_BLOCK_1))
|
||||
return;
|
||||
|
||||
xlrec = (xl_btree_insert*) XLogRecGetData(record);
|
||||
xlrec = (xl_btree_insert *) XLogRecGetData(record);
|
||||
reln = XLogOpenRelation(redo, RM_BTREE_ID, xlrec->target.node);
|
||||
if (!RelationIsValid(reln))
|
||||
return;
|
||||
buffer = XLogReadBuffer(false, reln,
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid)));
|
||||
buffer = XLogReadBuffer(false, reln,
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid)));
|
||||
if (!BufferIsValid(buffer))
|
||||
elog(STOP, "btree_insert_%sdo: block unfound", (redo) ? "re" : "un");
|
||||
page = (Page) BufferGetPage(buffer);
|
||||
@@ -825,11 +834,11 @@ btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
UnlockAndReleaseBuffer(buffer);
|
||||
return;
|
||||
}
|
||||
if (PageAddItem(page, (Item)((char*)xlrec + SizeOfBtreeInsert),
|
||||
record->xl_len - SizeOfBtreeInsert,
|
||||
ItemPointerGetOffsetNumber(&(xlrec->target.tid)),
|
||||
LP_USED) == InvalidOffsetNumber)
|
||||
elog(STOP, "btree_insert_redo: failed to add item");
|
||||
if (PageAddItem(page, (Item) ((char *) xlrec + SizeOfBtreeInsert),
|
||||
record->xl_len - SizeOfBtreeInsert,
|
||||
ItemPointerGetOffsetNumber(&(xlrec->target.tid)),
|
||||
LP_USED) == InvalidOffsetNumber)
|
||||
elog(STOP, "btree_insert_redo: failed to add item");
|
||||
|
||||
PageSetLSN(page, lsn);
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
@@ -840,7 +849,7 @@ btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
if (XLByteLT(PageGetLSN(page), lsn))
|
||||
elog(STOP, "btree_insert_undo: bad page LSN");
|
||||
|
||||
if (! P_ISLEAF(pageop))
|
||||
if (!P_ISLEAF(pageop))
|
||||
{
|
||||
UnlockAndReleaseBuffer(buffer);
|
||||
return;
|
||||
@@ -855,14 +864,14 @@ btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
static void
|
||||
btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
xl_btree_split *xlrec = (xl_btree_split*) XLogRecGetData(record);
|
||||
Relation reln;
|
||||
BlockNumber blkno;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
BTPageOpaque pageop;
|
||||
char *op = (redo) ? "redo" : "undo";
|
||||
bool isleaf = (record->xl_info & XLOG_BTREE_LEAF);
|
||||
xl_btree_split *xlrec = (xl_btree_split *) XLogRecGetData(record);
|
||||
Relation reln;
|
||||
BlockNumber blkno;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
BTPageOpaque pageop;
|
||||
char *op = (redo) ? "redo" : "undo";
|
||||
bool isleaf = (record->xl_info & XLOG_BTREE_LEAF);
|
||||
|
||||
reln = XLogOpenRelation(redo, RM_BTREE_ID, xlrec->target.node);
|
||||
if (!RelationIsValid(reln))
|
||||
@@ -870,7 +879,7 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
|
||||
|
||||
/* Left (original) sibling */
|
||||
blkno = (onleft) ? ItemPointerGetBlockNumber(&(xlrec->target.tid)) :
|
||||
BlockIdGetBlockNumber(&(xlrec->otherblk));
|
||||
BlockIdGetBlockNumber(&(xlrec->otherblk));
|
||||
buffer = XLogReadBuffer(false, reln, blkno);
|
||||
if (!BufferIsValid(buffer))
|
||||
elog(STOP, "btree_split_%s: lost left sibling", op);
|
||||
@@ -892,13 +901,14 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
|
||||
pageop->btpo_next = ItemPointerGetBlockNumber(&(xlrec->target.tid));
|
||||
pageop->btpo_flags = (isleaf) ? BTP_LEAF : 0;
|
||||
|
||||
_bt_restore_page(page, (char*)xlrec + SizeOfBtreeSplit, xlrec->leftlen);
|
||||
_bt_restore_page(page, (char *) xlrec + SizeOfBtreeSplit, xlrec->leftlen);
|
||||
|
||||
PageSetLSN(page, lsn);
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
UnlockAndWriteBuffer(buffer);
|
||||
}
|
||||
else /* undo */
|
||||
else
|
||||
/* undo */
|
||||
{
|
||||
if (XLByteLT(PageGetLSN(page), lsn))
|
||||
elog(STOP, "btree_split_undo: bad left sibling LSN");
|
||||
@@ -906,8 +916,8 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
|
||||
}
|
||||
|
||||
/* Right (new) sibling */
|
||||
blkno = (onleft) ? BlockIdGetBlockNumber(&(xlrec->otherblk)) :
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid));
|
||||
blkno = (onleft) ? BlockIdGetBlockNumber(&(xlrec->otherblk)) :
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid));
|
||||
buffer = XLogReadBuffer((redo) ? true : false, reln, blkno);
|
||||
if (!BufferIsValid(buffer))
|
||||
elog(STOP, "btree_split_%s: lost right sibling", op);
|
||||
@@ -922,21 +932,22 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
|
||||
if (redo)
|
||||
{
|
||||
pageop->btpo_parent = BlockIdGetBlockNumber(&(xlrec->parentblk));
|
||||
pageop->btpo_prev = (onleft) ?
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid)) :
|
||||
BlockIdGetBlockNumber(&(xlrec->otherblk));
|
||||
pageop->btpo_prev = (onleft) ?
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid)) :
|
||||
BlockIdGetBlockNumber(&(xlrec->otherblk));
|
||||
pageop->btpo_next = BlockIdGetBlockNumber(&(xlrec->rightblk));
|
||||
pageop->btpo_flags = (isleaf) ? BTP_LEAF : 0;
|
||||
|
||||
_bt_restore_page(page,
|
||||
(char*)xlrec + SizeOfBtreeSplit + xlrec->leftlen,
|
||||
record->xl_len - SizeOfBtreeSplit - xlrec->leftlen);
|
||||
(char *) xlrec + SizeOfBtreeSplit + xlrec->leftlen,
|
||||
record->xl_len - SizeOfBtreeSplit - xlrec->leftlen);
|
||||
|
||||
PageSetLSN(page, lsn);
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
UnlockAndWriteBuffer(buffer);
|
||||
}
|
||||
else /* undo */
|
||||
else
|
||||
/* undo */
|
||||
{
|
||||
if (XLByteLT(PageGetLSN(page), lsn))
|
||||
elog(STOP, "btree_split_undo: bad right sibling LSN");
|
||||
@@ -965,9 +976,9 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
|
||||
return;
|
||||
}
|
||||
pageop = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||
pageop->btpo_prev = (onleft) ?
|
||||
BlockIdGetBlockNumber(&(xlrec->otherblk)) :
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid));
|
||||
pageop->btpo_prev = (onleft) ?
|
||||
BlockIdGetBlockNumber(&(xlrec->otherblk)) :
|
||||
ItemPointerGetBlockNumber(&(xlrec->target.tid));
|
||||
|
||||
PageSetLSN(page, lsn);
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
@@ -977,14 +988,14 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
|
||||
static void
|
||||
btree_xlog_newroot(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
xl_btree_newroot *xlrec = (xl_btree_newroot*) XLogRecGetData(record);
|
||||
Relation reln;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
BTPageOpaque pageop;
|
||||
Buffer metabuf;
|
||||
Page metapg;
|
||||
BTMetaPageData md;
|
||||
xl_btree_newroot *xlrec = (xl_btree_newroot *) XLogRecGetData(record);
|
||||
Relation reln;
|
||||
Buffer buffer;
|
||||
Page page;
|
||||
BTPageOpaque pageop;
|
||||
Buffer metabuf;
|
||||
Page metapg;
|
||||
BTMetaPageData md;
|
||||
|
||||
if (!redo)
|
||||
return;
|
||||
@@ -1011,8 +1022,8 @@ btree_xlog_newroot(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
|
||||
if (record->xl_len > SizeOfBtreeNewroot)
|
||||
_bt_restore_page(page,
|
||||
(char*)xlrec + SizeOfBtreeNewroot,
|
||||
record->xl_len - SizeOfBtreeNewroot);
|
||||
(char *) xlrec + SizeOfBtreeNewroot,
|
||||
record->xl_len - SizeOfBtreeNewroot);
|
||||
|
||||
PageSetLSN(page, lsn);
|
||||
PageSetSUI(page, ThisStartUpID);
|
||||
@@ -1037,7 +1048,7 @@ btree_xlog_newroot(bool redo, XLogRecPtr lsn, XLogRecord *record)
|
||||
void
|
||||
btree_redo(XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
uint8 info = record->xl_info & ~XLR_INFO_MASK;
|
||||
uint8 info = record->xl_info & ~XLR_INFO_MASK;
|
||||
|
||||
info &= ~XLOG_BTREE_LEAF;
|
||||
if (info == XLOG_BTREE_DELETE)
|
||||
@@ -1045,9 +1056,9 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
|
||||
else if (info == XLOG_BTREE_INSERT)
|
||||
btree_xlog_insert(true, lsn, record);
|
||||
else if (info == XLOG_BTREE_SPLIT)
|
||||
btree_xlog_split(true, false, lsn, record); /* new item on the right */
|
||||
btree_xlog_split(true, false, lsn, record); /* new item on the right */
|
||||
else if (info == XLOG_BTREE_SPLEFT)
|
||||
btree_xlog_split(true, true, lsn, record); /* new item on the left */
|
||||
btree_xlog_split(true, true, lsn, record); /* new item on the left */
|
||||
else if (info == XLOG_BTREE_NEWROOT)
|
||||
btree_xlog_newroot(true, lsn, record);
|
||||
else
|
||||
@@ -1057,7 +1068,7 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
|
||||
void
|
||||
btree_undo(XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
uint8 info = record->xl_info & ~XLR_INFO_MASK;
|
||||
uint8 info = record->xl_info & ~XLR_INFO_MASK;
|
||||
|
||||
info &= ~XLOG_BTREE_LEAF;
|
||||
if (info == XLOG_BTREE_DELETE)
|
||||
@@ -1065,9 +1076,9 @@ btree_undo(XLogRecPtr lsn, XLogRecord *record)
|
||||
else if (info == XLOG_BTREE_INSERT)
|
||||
btree_xlog_insert(false, lsn, record);
|
||||
else if (info == XLOG_BTREE_SPLIT)
|
||||
btree_xlog_split(false, false, lsn, record);/* new item on the right */
|
||||
btree_xlog_split(false, false, lsn, record); /* new item on the right */
|
||||
else if (info == XLOG_BTREE_SPLEFT)
|
||||
btree_xlog_split(false, true, lsn, record); /* new item on the left */
|
||||
btree_xlog_split(false, true, lsn, record); /* new item on the left */
|
||||
else if (info == XLOG_BTREE_NEWROOT)
|
||||
btree_xlog_newroot(false, lsn, record);
|
||||
else
|
||||
@@ -1078,45 +1089,49 @@ static void
|
||||
out_target(char *buf, xl_btreetid *target)
|
||||
{
|
||||
sprintf(buf + strlen(buf), "node %u/%u; tid %u/%u",
|
||||
target->node.tblNode, target->node.relNode,
|
||||
ItemPointerGetBlockNumber(&(target->tid)),
|
||||
ItemPointerGetOffsetNumber(&(target->tid)));
|
||||
target->node.tblNode, target->node.relNode,
|
||||
ItemPointerGetBlockNumber(&(target->tid)),
|
||||
ItemPointerGetOffsetNumber(&(target->tid)));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
btree_desc(char *buf, uint8 xl_info, char* rec)
|
||||
btree_desc(char *buf, uint8 xl_info, char *rec)
|
||||
{
|
||||
uint8 info = xl_info & ~XLR_INFO_MASK;
|
||||
uint8 info = xl_info & ~XLR_INFO_MASK;
|
||||
|
||||
info &= ~XLOG_BTREE_LEAF;
|
||||
if (info == XLOG_BTREE_INSERT)
|
||||
{
|
||||
xl_btree_insert *xlrec = (xl_btree_insert*) rec;
|
||||
xl_btree_insert *xlrec = (xl_btree_insert *) rec;
|
||||
|
||||
strcat(buf, "insert: ");
|
||||
out_target(buf, &(xlrec->target));
|
||||
}
|
||||
else if (info == XLOG_BTREE_DELETE)
|
||||
{
|
||||
xl_btree_delete *xlrec = (xl_btree_delete*) rec;
|
||||
xl_btree_delete *xlrec = (xl_btree_delete *) rec;
|
||||
|
||||
strcat(buf, "delete: ");
|
||||
out_target(buf, &(xlrec->target));
|
||||
}
|
||||
else if (info == XLOG_BTREE_SPLIT || info == XLOG_BTREE_SPLEFT)
|
||||
{
|
||||
xl_btree_split *xlrec = (xl_btree_split*) rec;
|
||||
sprintf(buf + strlen(buf), "split(%s): ",
|
||||
(info == XLOG_BTREE_SPLIT) ? "right" : "left");
|
||||
xl_btree_split *xlrec = (xl_btree_split *) rec;
|
||||
|
||||
sprintf(buf + strlen(buf), "split(%s): ",
|
||||
(info == XLOG_BTREE_SPLIT) ? "right" : "left");
|
||||
out_target(buf, &(xlrec->target));
|
||||
sprintf(buf + strlen(buf), "; oth %u; rgh %u",
|
||||
BlockIdGetBlockNumber(&xlrec->otherblk),
|
||||
BlockIdGetBlockNumber(&xlrec->rightblk));
|
||||
BlockIdGetBlockNumber(&xlrec->otherblk),
|
||||
BlockIdGetBlockNumber(&xlrec->rightblk));
|
||||
}
|
||||
else if (info == XLOG_BTREE_NEWROOT)
|
||||
{
|
||||
xl_btree_newroot *xlrec = (xl_btree_newroot*) rec;
|
||||
xl_btree_newroot *xlrec = (xl_btree_newroot *) rec;
|
||||
|
||||
sprintf(buf + strlen(buf), "root: node %u/%u; blk %u",
|
||||
xlrec->node.tblNode, xlrec->node.relNode,
|
||||
BlockIdGetBlockNumber(&xlrec->rootblk));
|
||||
xlrec->node.tblNode, xlrec->node.relNode,
|
||||
BlockIdGetBlockNumber(&xlrec->rootblk));
|
||||
}
|
||||
else
|
||||
strcat(buf, "UNKNOWN");
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.63 2001/01/24 19:42:49 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.64 2001/03/22 03:59:15 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -32,20 +32,20 @@ static RetrieveIndexResult _bt_endpoint(IndexScanDesc scan, ScanDirection dir);
|
||||
*
|
||||
* NOTE that the returned buffer is read-locked regardless of the access
|
||||
* parameter. However, access = BT_WRITE will allow an empty root page
|
||||
* to be created and returned. When access = BT_READ, an empty index
|
||||
* to be created and returned. When access = BT_READ, an empty index
|
||||
* will result in *bufP being set to InvalidBuffer.
|
||||
*/
|
||||
BTStack
|
||||
_bt_search(Relation rel, int keysz, ScanKey scankey,
|
||||
Buffer *bufP, int access)
|
||||
{
|
||||
BTStack stack_in = NULL;
|
||||
BTStack stack_in = NULL;
|
||||
|
||||
/* Get the root page to start with */
|
||||
*bufP = _bt_getroot(rel, access);
|
||||
|
||||
/* If index is empty and access = BT_READ, no root page is created. */
|
||||
if (! BufferIsValid(*bufP))
|
||||
if (!BufferIsValid(*bufP))
|
||||
return (BTStack) NULL;
|
||||
|
||||
/* Loop iterates once per level descended in the tree */
|
||||
@@ -79,13 +79,13 @@ _bt_search(Relation rel, int keysz, ScanKey scankey,
|
||||
par_blkno = BufferGetBlockNumber(*bufP);
|
||||
|
||||
/*
|
||||
* We need to save the bit image of the index entry we chose in the
|
||||
* parent page on a stack. In case we split the tree, we'll use this
|
||||
* bit image to figure out what our real parent page is, in case the
|
||||
* parent splits while we're working lower in the tree. See the paper
|
||||
* by Lehman and Yao for how this is detected and handled. (We use the
|
||||
* child link to disambiguate duplicate keys in the index -- Lehman
|
||||
* and Yao disallow duplicate keys.)
|
||||
* We need to save the bit image of the index entry we chose in
|
||||
* the parent page on a stack. In case we split the tree, we'll
|
||||
* use this bit image to figure out what our real parent page is,
|
||||
* in case the parent splits while we're working lower in the
|
||||
* tree. See the paper by Lehman and Yao for how this is detected
|
||||
* and handled. (We use the child link to disambiguate duplicate
|
||||
* keys in the index -- Lehman and Yao disallow duplicate keys.)
|
||||
*/
|
||||
new_stack = (BTStack) palloc(sizeof(BTStackData));
|
||||
new_stack->bts_blkno = par_blkno;
|
||||
@@ -98,9 +98,9 @@ _bt_search(Relation rel, int keysz, ScanKey scankey,
|
||||
*bufP = _bt_getbuf(rel, blkno, BT_READ);
|
||||
|
||||
/*
|
||||
* Race -- the page we just grabbed may have split since we read its
|
||||
* pointer in the parent. If it has, we may need to move right to its
|
||||
* new sibling. Do that.
|
||||
* Race -- the page we just grabbed may have split since we read
|
||||
* its pointer in the parent. If it has, we may need to move
|
||||
* right to its new sibling. Do that.
|
||||
*/
|
||||
*bufP = _bt_moveright(rel, *bufP, keysz, scankey, BT_READ);
|
||||
|
||||
@@ -127,7 +127,7 @@ _bt_search(Relation rel, int keysz, ScanKey scankey,
|
||||
*
|
||||
* On entry, we have the buffer pinned and a lock of the proper type.
|
||||
* If we move right, we release the buffer and lock and acquire the
|
||||
* same on the right sibling. Return value is the buffer we stop at.
|
||||
* same on the right sibling. Return value is the buffer we stop at.
|
||||
*/
|
||||
Buffer
|
||||
_bt_moveright(Relation rel,
|
||||
@@ -153,7 +153,7 @@ _bt_moveright(Relation rel,
|
||||
_bt_compare(rel, keysz, scankey, page, P_HIKEY) > 0)
|
||||
{
|
||||
/* step right one page */
|
||||
BlockNumber rblkno = opaque->btpo_next;
|
||||
BlockNumber rblkno = opaque->btpo_next;
|
||||
|
||||
_bt_relbuf(rel, buf, access);
|
||||
buf = _bt_getbuf(rel, rblkno, access);
|
||||
@@ -184,7 +184,7 @@ _bt_moveright(Relation rel,
|
||||
* find all leaf keys >= given scankey.
|
||||
*
|
||||
* This procedure is not responsible for walking right, it just examines
|
||||
* the given page. _bt_binsrch() has no lock or refcount side effects
|
||||
* the given page. _bt_binsrch() has no lock or refcount side effects
|
||||
* on the buffer.
|
||||
*/
|
||||
OffsetNumber
|
||||
@@ -299,7 +299,7 @@ _bt_compare(Relation rel,
|
||||
* Force result ">" if target item is first data item on an internal
|
||||
* page --- see NOTE above.
|
||||
*/
|
||||
if (! P_ISLEAF(opaque) && offnum == P_FIRSTDATAKEY(opaque))
|
||||
if (!P_ISLEAF(opaque) && offnum == P_FIRSTDATAKEY(opaque))
|
||||
return 1;
|
||||
|
||||
btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
|
||||
@@ -327,7 +327,7 @@ _bt_compare(Relation rel,
|
||||
datum = index_getattr(itup, entry->sk_attno, itupdesc, &isNull);
|
||||
|
||||
/* see comments about NULLs handling in btbuild */
|
||||
if (entry->sk_flags & SK_ISNULL) /* key is NULL */
|
||||
if (entry->sk_flags & SK_ISNULL) /* key is NULL */
|
||||
{
|
||||
if (isNull)
|
||||
result = 0; /* NULL "=" NULL */
|
||||
@@ -458,10 +458,10 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
_bt_orderkeys(rel, so);
|
||||
|
||||
/*
|
||||
* Quit now if _bt_orderkeys() discovered that the scan keys can
|
||||
* never be satisfied (eg, x == 1 AND x > 2).
|
||||
* Quit now if _bt_orderkeys() discovered that the scan keys can never
|
||||
* be satisfied (eg, x == 1 AND x > 2).
|
||||
*/
|
||||
if (! so->qual_ok)
|
||||
if (!so->qual_ok)
|
||||
return (RetrieveIndexResult) NULL;
|
||||
|
||||
/*
|
||||
@@ -484,17 +484,16 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
break;
|
||||
strat = _bt_getstrat(rel, attno,
|
||||
so->keyData[i].sk_procedure);
|
||||
|
||||
/*
|
||||
* Can we use this key as a starting boundary for this attr?
|
||||
*
|
||||
* We can use multiple keys if they look like, say, = >= =
|
||||
* but we have to stop after accepting a > or < boundary.
|
||||
* We can use multiple keys if they look like, say, = >= = but we
|
||||
* have to stop after accepting a > or < boundary.
|
||||
*/
|
||||
if (strat == strat_total ||
|
||||
strat == BTEqualStrategyNumber)
|
||||
{
|
||||
nKeyIs[keysCount++] = i;
|
||||
}
|
||||
else if (ScanDirectionIsBackward(dir) &&
|
||||
(strat == BTLessStrategyNumber ||
|
||||
strat == BTLessEqualStrategyNumber))
|
||||
@@ -536,7 +535,11 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
for (i = 0; i < keysCount; i++)
|
||||
{
|
||||
j = nKeyIs[i];
|
||||
/* _bt_orderkeys disallows it, but it's place to add some code later */
|
||||
|
||||
/*
|
||||
* _bt_orderkeys disallows it, but it's place to add some code
|
||||
* later
|
||||
*/
|
||||
if (so->keyData[j].sk_flags & SK_ISNULL)
|
||||
{
|
||||
pfree(nKeyIs);
|
||||
@@ -562,7 +565,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
/* don't need to keep the stack around... */
|
||||
_bt_freestack(stack);
|
||||
|
||||
if (! BufferIsValid(buf))
|
||||
if (!BufferIsValid(buf))
|
||||
{
|
||||
/* Only get here if index is completely empty */
|
||||
ItemPointerSetInvalid(current);
|
||||
@@ -601,6 +604,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
switch (strat_total)
|
||||
{
|
||||
case BTLessStrategyNumber:
|
||||
|
||||
/*
|
||||
* Back up one to arrive at last item < scankey
|
||||
*/
|
||||
@@ -612,6 +616,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
break;
|
||||
|
||||
case BTLessEqualStrategyNumber:
|
||||
|
||||
/*
|
||||
* We need to find the last item <= scankey, so step forward
|
||||
* till we find one > scankey, then step back one.
|
||||
@@ -645,9 +650,10 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
break;
|
||||
|
||||
case BTEqualStrategyNumber:
|
||||
|
||||
/*
|
||||
* Make sure we are on the first equal item; might have to step
|
||||
* forward if currently at end of page.
|
||||
* Make sure we are on the first equal item; might have to
|
||||
* step forward if currently at end of page.
|
||||
*/
|
||||
if (offnum > PageGetMaxOffsetNumber(page))
|
||||
{
|
||||
@@ -661,7 +667,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
}
|
||||
result = _bt_compare(rel, keysCount, scankeys, page, offnum);
|
||||
if (result != 0)
|
||||
goto nomatches; /* no equal items! */
|
||||
goto nomatches; /* no equal items! */
|
||||
|
||||
/*
|
||||
* If a backward scan was specified, need to start with last
|
||||
* equal item not first one.
|
||||
@@ -685,6 +692,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
break;
|
||||
|
||||
case BTGreaterEqualStrategyNumber:
|
||||
|
||||
/*
|
||||
* We want the first item >= scankey, which is where we are...
|
||||
* unless we're not anywhere at all...
|
||||
@@ -700,9 +708,10 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
break;
|
||||
|
||||
case BTGreaterStrategyNumber:
|
||||
|
||||
/*
|
||||
* We want the first item > scankey, so make sure we are on
|
||||
* an item and then step over any equal items.
|
||||
* We want the first item > scankey, so make sure we are on an
|
||||
* item and then step over any equal items.
|
||||
*/
|
||||
if (offnum > PageGetMaxOffsetNumber(page))
|
||||
{
|
||||
@@ -850,11 +859,12 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
|
||||
*bufP = _bt_getbuf(rel, blkno, BT_READ);
|
||||
page = BufferGetPage(*bufP);
|
||||
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||
|
||||
/*
|
||||
* If the adjacent page just split, then we have to walk
|
||||
* right to find the block that's now adjacent to where
|
||||
* we were. Because pages only split right, we don't have
|
||||
* to worry about this failing to terminate.
|
||||
* right to find the block that's now adjacent to where we
|
||||
* were. Because pages only split right, we don't have to
|
||||
* worry about this failing to terminate.
|
||||
*/
|
||||
while (opaque->btpo_next != obknum)
|
||||
{
|
||||
@@ -912,12 +922,12 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
|
||||
|
||||
/*
|
||||
* Scan down to the leftmost or rightmost leaf page. This is a
|
||||
* simplified version of _bt_search(). We don't maintain a stack
|
||||
* simplified version of _bt_search(). We don't maintain a stack
|
||||
* since we know we won't need it.
|
||||
*/
|
||||
buf = _bt_getroot(rel, BT_READ);
|
||||
|
||||
if (! BufferIsValid(buf))
|
||||
if (!BufferIsValid(buf))
|
||||
{
|
||||
/* empty index... */
|
||||
ItemPointerSetInvalid(current);
|
||||
@@ -981,7 +991,8 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
|
||||
Assert(P_RIGHTMOST(opaque));
|
||||
|
||||
start = PageGetMaxOffsetNumber(page);
|
||||
if (start < P_FIRSTDATAKEY(opaque)) /* watch out for empty page */
|
||||
if (start < P_FIRSTDATAKEY(opaque)) /* watch out for empty
|
||||
* page */
|
||||
start = P_FIRSTDATAKEY(opaque);
|
||||
}
|
||||
else
|
||||
@@ -995,8 +1006,8 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
|
||||
so->btso_curbuf = buf;
|
||||
|
||||
/*
|
||||
* Left/rightmost page could be empty due to deletions,
|
||||
* if so step till we find a nonempty page.
|
||||
* Left/rightmost page could be empty due to deletions, if so step
|
||||
* till we find a nonempty page.
|
||||
*/
|
||||
if (start > maxoff)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* We use tuplesort.c to sort the given index tuples into order.
|
||||
* Then we scan the index tuples in order and build the btree pages
|
||||
* for each level. We load source tuples into leaf-level pages.
|
||||
* for each level. We load source tuples into leaf-level pages.
|
||||
* Whenever we fill a page at one level, we add a link to it to its
|
||||
* parent level (starting a new parent level if necessary). When
|
||||
* done, we write out each final page on each level, adding it to
|
||||
@@ -35,7 +35,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.59 2001/01/24 19:42:49 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.60 2001/03/22 03:59:15 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ struct BTSpool
|
||||
};
|
||||
|
||||
/*
|
||||
* Status record for a btree page being built. We have one of these
|
||||
* Status record for a btree page being built. We have one of these
|
||||
* for each active tree level.
|
||||
*
|
||||
* The reason we need to store a copy of the minimum key is that we'll
|
||||
@@ -73,11 +73,13 @@ typedef struct BTPageState
|
||||
{
|
||||
Buffer btps_buf; /* current buffer & page */
|
||||
Page btps_page;
|
||||
BTItem btps_minkey; /* copy of minimum key (first item) on page */
|
||||
BTItem btps_minkey; /* copy of minimum key (first item) on
|
||||
* page */
|
||||
OffsetNumber btps_lastoff; /* last item offset loaded */
|
||||
int btps_level; /* tree level (0 = leaf) */
|
||||
Size btps_full; /* "full" if less than this much free space */
|
||||
struct BTPageState *btps_next; /* link to parent level, if any */
|
||||
Size btps_full; /* "full" if less than this much free
|
||||
* space */
|
||||
struct BTPageState *btps_next; /* link to parent level, if any */
|
||||
} BTPageState;
|
||||
|
||||
|
||||
@@ -92,7 +94,7 @@ static void _bt_blnewpage(Relation index, Buffer *buf, Page *page, int flags);
|
||||
static BTPageState *_bt_pagestate(Relation index, int flags, int level);
|
||||
static void _bt_slideleft(Relation index, Buffer buf, Page page);
|
||||
static void _bt_sortaddtup(Page page, Size itemsize,
|
||||
BTItem btitem, OffsetNumber itup_off);
|
||||
BTItem btitem, OffsetNumber itup_off);
|
||||
static void _bt_buildadd(Relation index, BTPageState *state, BTItem bti);
|
||||
static void _bt_uppershutdown(Relation index, BTPageState *state);
|
||||
static void _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2);
|
||||
@@ -162,7 +164,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
|
||||
ShowUsage();
|
||||
ResetUsage();
|
||||
}
|
||||
#endif /* BTREE_BUILD_STATS */
|
||||
#endif /* BTREE_BUILD_STATS */
|
||||
tuplesort_performsort(btspool->sortstate);
|
||||
|
||||
if (btspool2)
|
||||
@@ -269,9 +271,9 @@ _bt_sortaddtup(Page page,
|
||||
OffsetNumber itup_off)
|
||||
{
|
||||
BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||
BTItemData truncitem;
|
||||
BTItemData truncitem;
|
||||
|
||||
if (! P_ISLEAF(opaque) && itup_off == P_FIRSTKEY)
|
||||
if (!P_ISLEAF(opaque) && itup_off == P_FIRSTKEY)
|
||||
{
|
||||
memcpy(&truncitem, btitem, sizeof(BTItemData));
|
||||
truncitem.bti_itup.t_info = sizeof(BTItemData);
|
||||
@@ -290,7 +292,7 @@ _bt_sortaddtup(Page page,
|
||||
* We must be careful to observe the page layout conventions of nbtsearch.c:
|
||||
* - rightmost pages start data items at P_HIKEY instead of at P_FIRSTKEY.
|
||||
* - on non-leaf pages, the key portion of the first item need not be
|
||||
* stored, we should store only the link.
|
||||
* stored, we should store only the link.
|
||||
*
|
||||
* A leaf page being built looks like:
|
||||
*
|
||||
@@ -347,11 +349,12 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
|
||||
*/
|
||||
if (btisz > (PageGetPageSize(npage) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) / 3 - sizeof(ItemIdData))
|
||||
elog(ERROR, "btree: index item size %lu exceeds maximum %ld",
|
||||
(unsigned long)btisz,
|
||||
(PageGetPageSize(npage) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) /3 - sizeof(ItemIdData));
|
||||
(unsigned long) btisz,
|
||||
(PageGetPageSize(npage) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) / 3 - sizeof(ItemIdData));
|
||||
|
||||
if (pgspc < btisz || pgspc < state->btps_full)
|
||||
{
|
||||
|
||||
/*
|
||||
* Item won't fit on this page, or we feel the page is full enough
|
||||
* already. Finish off the page and write it out.
|
||||
@@ -388,9 +391,9 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
|
||||
((PageHeader) opage)->pd_lower -= sizeof(ItemIdData);
|
||||
|
||||
/*
|
||||
* Link the old buffer into its parent, using its minimum key.
|
||||
* If we don't have a parent, we have to create one;
|
||||
* this adds a new btree level.
|
||||
* Link the old buffer into its parent, using its minimum key. If
|
||||
* we don't have a parent, we have to create one; this adds a new
|
||||
* btree level.
|
||||
*/
|
||||
if (state->btps_next == (BTPageState *) NULL)
|
||||
{
|
||||
@@ -405,8 +408,8 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
|
||||
|
||||
/*
|
||||
* Save a copy of the minimum key for the new page. We have to
|
||||
* copy it off the old page, not the new one, in case we are
|
||||
* not at leaf level.
|
||||
* copy it off the old page, not the new one, in case we are not
|
||||
* at leaf level.
|
||||
*/
|
||||
state->btps_minkey = _bt_formitem(&(obti->bti_itup));
|
||||
|
||||
@@ -414,13 +417,13 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
|
||||
* Set the sibling links for both pages, and parent links too.
|
||||
*
|
||||
* It's not necessary to set the parent link at all, because it's
|
||||
* only used for handling concurrent root splits, but we may as well
|
||||
* do it as a debugging aid. Note we set new page's link as well
|
||||
* as old's, because if the new page turns out to be the last of
|
||||
* the level, _bt_uppershutdown won't change it. The links may be
|
||||
* out of date by the time the build finishes, but that's OK; they
|
||||
* need only point to a left-sibling of the true parent. See the
|
||||
* README file for more info.
|
||||
* only used for handling concurrent root splits, but we may as
|
||||
* well do it as a debugging aid. Note we set new page's link as
|
||||
* well as old's, because if the new page turns out to be the last
|
||||
* of the level, _bt_uppershutdown won't change it. The links may
|
||||
* be out of date by the time the build finishes, but that's OK;
|
||||
* they need only point to a left-sibling of the true parent. See
|
||||
* the README file for more info.
|
||||
*/
|
||||
{
|
||||
BTPageOpaque oopaque = (BTPageOpaque) PageGetSpecialPointer(opage);
|
||||
@@ -434,7 +437,7 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
|
||||
}
|
||||
|
||||
/*
|
||||
* Write out the old page. We never want to see it again, so we
|
||||
* Write out the old page. We never want to see it again, so we
|
||||
* can give up our lock (if we had one; most likely BuildingBtree
|
||||
* is set, so we aren't locking).
|
||||
*/
|
||||
@@ -449,8 +452,8 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
|
||||
/*
|
||||
* If the new item is the first for its page, stash a copy for later.
|
||||
* Note this will only happen for the first item on a level; on later
|
||||
* pages, the first item for a page is copied from the prior page
|
||||
* in the code above.
|
||||
* pages, the first item for a page is copied from the prior page in
|
||||
* the code above.
|
||||
*/
|
||||
if (last_off == P_HIKEY)
|
||||
{
|
||||
@@ -493,8 +496,8 @@ _bt_uppershutdown(Relation index, BTPageState *state)
|
||||
*
|
||||
* If we're at the top, it's the root, so attach it to the metapage.
|
||||
* Otherwise, add an entry for it to its parent using its minimum
|
||||
* key. This may cause the last page of the parent level to split,
|
||||
* but that's not a problem -- we haven't gotten to it yet.
|
||||
* key. This may cause the last page of the parent level to
|
||||
* split, but that's not a problem -- we haven't gotten to it yet.
|
||||
*/
|
||||
if (s->btps_next == (BTPageState *) NULL)
|
||||
{
|
||||
@@ -513,7 +516,7 @@ _bt_uppershutdown(Relation index, BTPageState *state)
|
||||
|
||||
/*
|
||||
* This is the rightmost page, so the ItemId array needs to be
|
||||
* slid back one slot. Then we can dump out the page.
|
||||
* slid back one slot. Then we can dump out the page.
|
||||
*/
|
||||
_bt_slideleft(index, s->btps_buf, s->btps_page);
|
||||
_bt_wrtbuf(index, s->btps_buf);
|
||||
@@ -529,22 +532,29 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
|
||||
{
|
||||
BTPageState *state = NULL;
|
||||
bool merge = (btspool2 != NULL);
|
||||
BTItem bti, bti2 = NULL;
|
||||
bool should_free, should_free2, load1;
|
||||
BTItem bti,
|
||||
bti2 = NULL;
|
||||
bool should_free,
|
||||
should_free2,
|
||||
load1;
|
||||
TupleDesc tupdes = RelationGetDescr(index);
|
||||
int i, keysz = RelationGetNumberOfAttributes(index);
|
||||
int i,
|
||||
keysz = RelationGetNumberOfAttributes(index);
|
||||
ScanKey indexScanKey = NULL;
|
||||
|
||||
if (merge)
|
||||
{
|
||||
|
||||
/*
|
||||
* Another BTSpool for dead tuples exists.
|
||||
* Now we have to merge btspool and btspool2.
|
||||
*/
|
||||
ScanKey entry;
|
||||
Datum attrDatum1, attrDatum2;
|
||||
bool isFirstNull, isSecondNull;
|
||||
int32 compare;
|
||||
* Another BTSpool for dead tuples exists. Now we have to merge
|
||||
* btspool and btspool2.
|
||||
*/
|
||||
ScanKey entry;
|
||||
Datum attrDatum1,
|
||||
attrDatum2;
|
||||
bool isFirstNull,
|
||||
isSecondNull;
|
||||
int32 compare;
|
||||
|
||||
/* the preparation of merge */
|
||||
bti = (BTItem) tuplesort_getindextuple(btspool->sortstate, true, &should_free);
|
||||
@@ -552,7 +562,7 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
|
||||
indexScanKey = _bt_mkscankey_nodata(index);
|
||||
for (;;)
|
||||
{
|
||||
load1 = true; /* load BTSpool next ? */
|
||||
load1 = true; /* load BTSpool next ? */
|
||||
if (NULL == bti2)
|
||||
{
|
||||
if (NULL == bti)
|
||||
@@ -564,8 +574,8 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
|
||||
for (i = 1; i <= keysz; i++)
|
||||
{
|
||||
entry = indexScanKey + i - 1;
|
||||
attrDatum1 = index_getattr((IndexTuple)bti, i, tupdes, &isFirstNull);
|
||||
attrDatum2 = index_getattr((IndexTuple)bti2, i, tupdes, &isSecondNull);
|
||||
attrDatum1 = index_getattr((IndexTuple) bti, i, tupdes, &isFirstNull);
|
||||
attrDatum2 = index_getattr((IndexTuple) bti2, i, tupdes, &isSecondNull);
|
||||
if (isFirstNull)
|
||||
{
|
||||
if (!isSecondNull)
|
||||
@@ -586,7 +596,7 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
|
||||
}
|
||||
else if (compare < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -613,7 +623,8 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
|
||||
}
|
||||
_bt_freeskey(indexScanKey);
|
||||
}
|
||||
else /* merge is unnecessary */
|
||||
else
|
||||
/* merge is unnecessary */
|
||||
{
|
||||
while (bti = (BTItem) tuplesort_getindextuple(btspool->sortstate, true, &should_free), bti != (BTItem) NULL)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.42 2001/01/24 19:42:49 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.43 2001/03/22 03:59:15 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -124,7 +124,7 @@ _bt_freestack(BTStack stack)
|
||||
* Construct a BTItem from a plain IndexTuple.
|
||||
*
|
||||
* This is now useless code, since a BTItem *is* an index tuple with
|
||||
* no extra stuff. We hang onto it for the moment to preserve the
|
||||
* no extra stuff. We hang onto it for the moment to preserve the
|
||||
* notational distinction, in case we want to add some extra stuff
|
||||
* again someday.
|
||||
*/
|
||||
@@ -165,7 +165,7 @@ _bt_formitem(IndexTuple itup)
|
||||
* are "x = 1 AND y < 4 AND z < 5", then _bt_checkkeys will reject a tuple
|
||||
* (1,2,7), but we must continue the scan in case there are tuples (1,3,z).
|
||||
* But once we reach tuples like (1,4,z) we can stop scanning because no
|
||||
* later tuples could match. This is reflected by setting
|
||||
* later tuples could match. This is reflected by setting
|
||||
* so->numberOfRequiredKeys to the number of leading keys that must be
|
||||
* matched to continue the scan. numberOfRequiredKeys is equal to the
|
||||
* number of leading "=" keys plus the key(s) for the first non "="
|
||||
@@ -178,7 +178,7 @@ _bt_formitem(IndexTuple itup)
|
||||
*
|
||||
* XXX this routine is one of many places that fail to handle SK_COMMUTE
|
||||
* scankeys properly. Currently, the planner is careful never to generate
|
||||
* any indexquals that would require SK_COMMUTE to be set. Someday we ought
|
||||
* any indexquals that would require SK_COMMUTE to be set. Someday we ought
|
||||
* to try to fix this, though it's not real critical as long as indexable
|
||||
* operators all have commutators...
|
||||
*
|
||||
@@ -191,7 +191,7 @@ _bt_formitem(IndexTuple itup)
|
||||
void
|
||||
_bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
{
|
||||
ScanKeyData xform[BTMaxStrategyNumber];
|
||||
ScanKeyData xform[BTMaxStrategyNumber];
|
||||
bool init[BTMaxStrategyNumber];
|
||||
uint16 numberOfKeys = so->numberOfKeys;
|
||||
ScanKey key;
|
||||
@@ -240,14 +240,14 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
/*
|
||||
* Initialize for processing of keys for attr 1.
|
||||
*
|
||||
* xform[i] holds a copy of the current scan key of strategy type i+1,
|
||||
* if any; init[i] is TRUE if we have found such a key for this attr.
|
||||
* xform[i] holds a copy of the current scan key of strategy type i+1, if
|
||||
* any; init[i] is TRUE if we have found such a key for this attr.
|
||||
*/
|
||||
attno = 1;
|
||||
map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
|
||||
BTMaxStrategyNumber,
|
||||
attno);
|
||||
MemSet(xform, 0, sizeof(xform)); /* not really necessary */
|
||||
MemSet(xform, 0, sizeof(xform)); /* not really necessary */
|
||||
MemSet(init, 0, sizeof(init));
|
||||
|
||||
/*
|
||||
@@ -255,7 +255,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
* pass to handle after-last-key processing. Actual exit from the
|
||||
* loop is at the "break" statement below.
|
||||
*/
|
||||
for (i = 0; ; cur++, i++)
|
||||
for (i = 0;; cur++, i++)
|
||||
{
|
||||
if (i < numberOfKeys)
|
||||
{
|
||||
@@ -263,7 +263,9 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
if (cur->sk_flags & SK_ISNULL)
|
||||
{
|
||||
so->qual_ok = false;
|
||||
/* Quit processing so we don't try to invoke comparison
|
||||
|
||||
/*
|
||||
* Quit processing so we don't try to invoke comparison
|
||||
* routines on NULLs.
|
||||
*/
|
||||
return;
|
||||
@@ -271,8 +273,8 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
}
|
||||
|
||||
/*
|
||||
* If we are at the end of the keys for a particular attr,
|
||||
* finish up processing and emit the cleaned-up keys.
|
||||
* If we are at the end of the keys for a particular attr, finish
|
||||
* up processing and emit the cleaned-up keys.
|
||||
*/
|
||||
if (i == numberOfKeys || cur->sk_attno != attno)
|
||||
{
|
||||
@@ -296,7 +298,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
eq = &xform[BTEqualStrategyNumber - 1];
|
||||
for (j = BTMaxStrategyNumber; --j >= 0;)
|
||||
{
|
||||
if (! init[j] ||
|
||||
if (!init[j] ||
|
||||
j == (BTEqualStrategyNumber - 1))
|
||||
continue;
|
||||
chk = &xform[j];
|
||||
@@ -313,6 +315,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* No "=" for this key, so we're done with required keys
|
||||
*/
|
||||
@@ -355,8 +358,8 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
* Emit the cleaned-up keys back into the key[] array in the
|
||||
* correct order. Note we are overwriting our input here!
|
||||
* It's OK because (a) xform[] is a physical copy of the keys
|
||||
* we want, (b) we cannot emit more keys than we input, so
|
||||
* we won't overwrite as-yet-unprocessed keys.
|
||||
* we want, (b) we cannot emit more keys than we input, so we
|
||||
* won't overwrite as-yet-unprocessed keys.
|
||||
*/
|
||||
for (j = BTMaxStrategyNumber; --j >= 0;)
|
||||
{
|
||||
@@ -383,7 +386,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
|
||||
BTMaxStrategyNumber,
|
||||
attno);
|
||||
MemSet(xform, 0, sizeof(xform)); /* not really necessary */
|
||||
MemSet(xform, 0, sizeof(xform)); /* not really necessary */
|
||||
MemSet(init, 0, sizeof(init));
|
||||
}
|
||||
|
||||
@@ -409,7 +412,8 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
if (DatumGetBool(test))
|
||||
xform[j].sk_argument = cur->sk_argument;
|
||||
else if (j == (BTEqualStrategyNumber - 1))
|
||||
so->qual_ok = false; /* key == a && key == b, but a != b */
|
||||
so->qual_ok = false; /* key == a && key == b, but a !=
|
||||
* b */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -473,16 +477,18 @@ _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple,
|
||||
|
||||
if (isNull)
|
||||
{
|
||||
|
||||
/*
|
||||
* Since NULLs are sorted after non-NULLs, we know we have
|
||||
* reached the upper limit of the range of values for this
|
||||
* index attr. On a forward scan, we can stop if this qual
|
||||
* is one of the "must match" subset. On a backward scan,
|
||||
* index attr. On a forward scan, we can stop if this qual is
|
||||
* one of the "must match" subset. On a backward scan,
|
||||
* however, we should keep going.
|
||||
*/
|
||||
if (keysok < so->numberOfRequiredKeys &&
|
||||
ScanDirectionIsForward(dir))
|
||||
*continuescan = false;
|
||||
|
||||
/*
|
||||
* In any case, this indextuple doesn't match the qual.
|
||||
*/
|
||||
@@ -498,9 +504,10 @@ _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple,
|
||||
|
||||
if (DatumGetBool(test) == !!(key->sk_flags & SK_NEGATE))
|
||||
{
|
||||
|
||||
/*
|
||||
* Tuple fails this qual. If it's a required qual, then
|
||||
* we can conclude no further tuples will pass, either.
|
||||
* Tuple fails this qual. If it's a required qual, then we
|
||||
* can conclude no further tuples will pass, either.
|
||||
*/
|
||||
if (keysok < so->numberOfRequiredKeys)
|
||||
*continuescan = false;
|
||||
|
||||
Reference in New Issue
Block a user