Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d146305

Browse files
committed
Patches for Vadim's multikey indexing...
1 parent c3d637a commit d146305

File tree

9 files changed

+414
-248
lines changed

9 files changed

+414
-248
lines changed

src/backend/access/common/indexvalid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/common/Attic/indexvalid.c,v 1.13 1997/03/12 20:56:32 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/common/Attic/indexvalid.c,v 1.14 1997/03/18 18:38:19 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -48,7 +48,7 @@ index_keytest(IndexTuple tuple,
4848

4949
while (scanKeySize > 0) {
5050
datum = index_getattr(tuple,
51-
1,
51+
key[0].sk_attno,
5252
tupdesc,
5353
&isNull);
5454

src/backend/access/nbtree/nbtree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.15 1997/02/22 10:04:14 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.16 1997/03/18 18:38:35 scrappy Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -423,6 +423,7 @@ btrescan(IndexScanDesc scan, bool fromEnd, ScanKey scankey)
423423

424424
/* reset the scan key */
425425
so->numberOfKeys = scan->numberOfKeys;
426+
so->numberOfFirstKeys = 0;
426427
so->qual_ok = 1; /* may be changed by _bt_orderkeys */
427428
if (scan->numberOfKeys > 0) {
428429
memmove(scan->keyData,
@@ -433,7 +434,9 @@ btrescan(IndexScanDesc scan, bool fromEnd, ScanKey scankey)
433434
so->numberOfKeys * sizeof(ScanKeyData));
434435
/* order the keys in the qualification */
435436
if (so->numberOfKeys > 1)
436-
_bt_orderkeys(scan->relation, &so->numberOfKeys, so->keyData, &so->qual_ok);
437+
_bt_orderkeys(scan->relation, so);
438+
else
439+
so->numberOfFirstKeys = 1;
437440
}
438441

439442
/* finally, be sure that the scan exploits the tree order */

src/backend/access/nbtree/nbtsearch.c

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.14 1997/02/18 17:13:48 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.15 1997/03/18 18:38:41 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -562,7 +562,6 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
562562
Page page;
563563
OffsetNumber offnum;
564564
RetrieveIndexResult res;
565-
BlockNumber blkno;
566565
ItemPointer current;
567566
BTItem btitem;
568567
IndexTuple itup;
@@ -584,31 +583,35 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
584583

585584
/* we still have the buffer pinned and locked */
586585
buf = so->btso_curbuf;
587-
blkno = BufferGetBlockNumber(buf);
588586

589-
/* step one tuple in the appropriate direction */
590-
if (!_bt_step(scan, &buf, dir))
591-
return ((RetrieveIndexResult) NULL);
587+
do
588+
{
589+
/* step one tuple in the appropriate direction */
590+
if (!_bt_step(scan, &buf, dir))
591+
return ((RetrieveIndexResult) NULL);
592592

593-
/* by here, current is the tuple we want to return */
594-
offnum = ItemPointerGetOffsetNumber(current);
595-
page = BufferGetPage(buf);
596-
btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
597-
itup = &btitem->bti_itup;
593+
/* by here, current is the tuple we want to return */
594+
offnum = ItemPointerGetOffsetNumber(current);
595+
page = BufferGetPage(buf);
596+
btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
597+
itup = &btitem->bti_itup;
598598

599-
if (_bt_checkqual(scan, itup)) {
600-
res = FormRetrieveIndexResult(current, &(itup->t_tid));
599+
if (_bt_checkqual(scan, itup))
600+
{
601+
res = FormRetrieveIndexResult(current, &(itup->t_tid));
601602

602-
/* remember which buffer we have pinned and locked */
603-
so->btso_curbuf = buf;
604-
} else {
605-
ItemPointerSetInvalid(current);
606-
so->btso_curbuf = InvalidBuffer;
607-
_bt_relbuf(rel, buf, BT_READ);
608-
res = (RetrieveIndexResult) NULL;
609-
}
603+
/* remember which buffer we have pinned and locked */
604+
so->btso_curbuf = buf;
605+
return (res);
606+
}
607+
608+
} while ( _bt_checkforkeys (scan, itup, so->numberOfFirstKeys) );
609+
610+
ItemPointerSetInvalid(current);
611+
so->btso_curbuf = InvalidBuffer;
612+
_bt_relbuf(rel, buf, BT_READ);
610613

611-
return (res);
614+
return ((RetrieveIndexResult) NULL);
612615
}
613616

614617
/*
@@ -660,13 +663,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
660663
* ordered to take advantage of index ordering) to position ourselves
661664
* at the right place in the scan.
662665
*/
663-
664-
/*
665-
* XXX -- The attribute number stored in the scan key is the attno
666-
* in the heap relation. We need to transmogrify this into
667-
* the index relation attno here. For the moment, we have
668-
* hardwired attno == 1.
669-
*/
670666
proc = index_getprocid(rel, 1, BTORDER_PROC);
671667
ScanKeyEntryInitialize(&skdata, so->keyData[0].sk_flags, 1, proc,
672668
so->keyData[0].sk_argument);
@@ -802,12 +798,20 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
802798
btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
803799
itup = &btitem->bti_itup;
804800

805-
if (_bt_checkqual(scan, itup)) {
801+
if ( _bt_checkqual(scan, itup) )
802+
{
806803
res = FormRetrieveIndexResult(current, &(itup->t_tid));
807804

808805
/* remember which buffer we have pinned */
809806
so->btso_curbuf = buf;
810-
} else {
807+
}
808+
else if ( _bt_checkforkeys (scan, itup, so->numberOfFirstKeys) )
809+
{
810+
so->btso_curbuf = buf;
811+
return (_bt_next (scan, dir));
812+
}
813+
else
814+
{
811815
ItemPointerSetInvalid(current);
812816
so->btso_curbuf = InvalidBuffer;
813817
_bt_relbuf(rel, buf, BT_READ);
@@ -1224,7 +1228,14 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
12241228

12251229
/* remember which buffer we have pinned */
12261230
so->btso_curbuf = buf;
1227-
} else {
1231+
}
1232+
else if ( _bt_checkforkeys (scan, itup, so->numberOfFirstKeys) )
1233+
{
1234+
so->btso_curbuf = buf;
1235+
return (_bt_next (scan, dir));
1236+
}
1237+
else
1238+
{
12281239
_bt_relbuf(rel, buf, BT_READ);
12291240
res = (RetrieveIndexResult) NULL;
12301241
}

0 commit comments

Comments
 (0)