mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Massive commit to run PGINDENT on all *.c and *.h files.
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* nbtcompare.c--
|
||||
* Comparison functions for btree access method.
|
||||
* Comparison functions for btree access method.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.10 1997/06/11 05:20:05 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.11 1997/09/07 04:38:39 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* These functions are stored in pg_amproc. For each operator class
|
||||
* defined on btrees, they compute
|
||||
* NOTES
|
||||
* These functions are stored in pg_amproc. For each operator class
|
||||
* defined on btrees, they compute
|
||||
*
|
||||
* compare(a, b):
|
||||
* < 0 if a < b,
|
||||
* = 0 if a == b,
|
||||
* > 0 if a > b.
|
||||
* compare(a, b):
|
||||
* < 0 if a < b,
|
||||
* = 0 if a == b,
|
||||
* > 0 if a > b.
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -30,168 +30,171 @@
|
||||
int32
|
||||
btint2cmp(int16 a, int16 b)
|
||||
{
|
||||
return ((int32) (a - b));
|
||||
return ((int32) (a - b));
|
||||
}
|
||||
|
||||
int32
|
||||
btint4cmp(int32 a, int32 b)
|
||||
{
|
||||
return (a - b);
|
||||
return (a - b);
|
||||
}
|
||||
|
||||
int32
|
||||
btint24cmp(int16 a, int32 b)
|
||||
{
|
||||
return (((int32) a) - b);
|
||||
return (((int32) a) - b);
|
||||
}
|
||||
|
||||
int32
|
||||
btint42cmp(int32 a, int16 b)
|
||||
{
|
||||
return (a - ((int32) b));
|
||||
return (a - ((int32) b));
|
||||
}
|
||||
|
||||
int32
|
||||
btfloat4cmp(float32 a, float32 b)
|
||||
{
|
||||
if (*a > *b)
|
||||
return (1);
|
||||
else if (*a == *b)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
if (*a > *b)
|
||||
return (1);
|
||||
else if (*a == *b)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int32
|
||||
btfloat8cmp(float64 a, float64 b)
|
||||
{
|
||||
if (*a > *b)
|
||||
return (1);
|
||||
else if (*a == *b)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
if (*a > *b)
|
||||
return (1);
|
||||
else if (*a == *b)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int32
|
||||
btoidcmp(Oid a, Oid b)
|
||||
{
|
||||
if (a > b)
|
||||
return (1);
|
||||
else if (a == b)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
if (a > b)
|
||||
return (1);
|
||||
else if (a == b)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int32
|
||||
btabstimecmp(AbsoluteTime a, AbsoluteTime b)
|
||||
{
|
||||
if (AbsoluteTimeIsBefore(a, b))
|
||||
return (-1);
|
||||
else if (AbsoluteTimeIsBefore(b, a))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
if (AbsoluteTimeIsBefore(a, b))
|
||||
return (-1);
|
||||
else if (AbsoluteTimeIsBefore(b, a))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
int32
|
||||
btcharcmp(char a, char b)
|
||||
{
|
||||
return ((int32) ((uint8)a - (uint8)b));
|
||||
return ((int32) ((uint8) a - (uint8) b));
|
||||
}
|
||||
|
||||
int32
|
||||
btchar2cmp(uint16 a, uint16 b)
|
||||
{
|
||||
return (strncmp((char *) &a, (char *) &b, 2));
|
||||
return (strncmp((char *) &a, (char *) &b, 2));
|
||||
}
|
||||
|
||||
int32
|
||||
btchar4cmp(uint32 a, uint32 b)
|
||||
{
|
||||
return (strncmp((char *) &a, (char *) &b, 4));
|
||||
return (strncmp((char *) &a, (char *) &b, 4));
|
||||
}
|
||||
|
||||
int32
|
||||
btchar8cmp(char *a, char *b)
|
||||
{
|
||||
return (strncmp(a, b, 8));
|
||||
return (strncmp(a, b, 8));
|
||||
}
|
||||
|
||||
int32
|
||||
btchar16cmp(char *a, char *b)
|
||||
{
|
||||
return (strncmp(a, b, 16));
|
||||
return (strncmp(a, b, 16));
|
||||
}
|
||||
|
||||
int32
|
||||
btnamecmp(NameData *a, NameData *b)
|
||||
btnamecmp(NameData * a, NameData * b)
|
||||
{
|
||||
return (strncmp(a->data, b->data, NAMEDATALEN));
|
||||
return (strncmp(a->data, b->data, NAMEDATALEN));
|
||||
}
|
||||
|
||||
int32
|
||||
bttextcmp(struct varlena *a, struct varlena *b)
|
||||
bttextcmp(struct varlena * a, struct varlena * b)
|
||||
{
|
||||
int res;
|
||||
unsigned char *ap, *bp;
|
||||
int res;
|
||||
unsigned char *ap,
|
||||
*bp;
|
||||
|
||||
#ifdef USE_LOCALE
|
||||
int la = VARSIZE(a) - VARHDRSZ;
|
||||
int lb = VARSIZE(b) - VARHDRSZ;
|
||||
|
||||
ap = (unsigned char *) palloc (la + 1);
|
||||
bp = (unsigned char *) palloc (lb + 1);
|
||||
int la = VARSIZE(a) - VARHDRSZ;
|
||||
int lb = VARSIZE(b) - VARHDRSZ;
|
||||
|
||||
memcpy(ap, VARDATA(a), la);
|
||||
*(ap + la) = '\0';
|
||||
memcpy(bp, VARDATA(b), lb);
|
||||
*(bp + lb) = '\0';
|
||||
ap = (unsigned char *) palloc(la + 1);
|
||||
bp = (unsigned char *) palloc(lb + 1);
|
||||
|
||||
res = strcoll (ap, bp);
|
||||
|
||||
pfree (ap);
|
||||
pfree (bp);
|
||||
memcpy(ap, VARDATA(a), la);
|
||||
*(ap + la) = '\0';
|
||||
memcpy(bp, VARDATA(b), lb);
|
||||
*(bp + lb) = '\0';
|
||||
|
||||
res = strcoll(ap, bp);
|
||||
|
||||
pfree(ap);
|
||||
pfree(bp);
|
||||
|
||||
#else
|
||||
int len = VARSIZE(a);
|
||||
|
||||
/* len is the length of the shorter of the two strings */
|
||||
if ( len > VARSIZE(b) )
|
||||
len = VARSIZE(b);
|
||||
int len = VARSIZE(a);
|
||||
|
||||
len -= VARHDRSZ;
|
||||
/* len is the length of the shorter of the two strings */
|
||||
if (len > VARSIZE(b))
|
||||
len = VARSIZE(b);
|
||||
|
||||
ap = (unsigned char *) VARDATA(a);
|
||||
bp = (unsigned char *) VARDATA(b);
|
||||
|
||||
/*
|
||||
* If the two strings differ in the first len bytes, or if they're
|
||||
* the same in the first len bytes and they're both len bytes long,
|
||||
* we're done.
|
||||
*/
|
||||
|
||||
res = 0;
|
||||
if (len > 0) {
|
||||
do {
|
||||
res = (int) (*ap++ - *bp++);
|
||||
len--;
|
||||
} while (res == 0 && len != 0);
|
||||
}
|
||||
len -= VARHDRSZ;
|
||||
|
||||
ap = (unsigned char *) VARDATA(a);
|
||||
bp = (unsigned char *) VARDATA(b);
|
||||
|
||||
/*
|
||||
* If the two strings differ in the first len bytes, or if they're the
|
||||
* same in the first len bytes and they're both len bytes long, we're
|
||||
* done.
|
||||
*/
|
||||
|
||||
res = 0;
|
||||
if (len > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
res = (int) (*ap++ - *bp++);
|
||||
len--;
|
||||
} while (res == 0 && len != 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (res != 0 || VARSIZE(a) == VARSIZE(b))
|
||||
return (res);
|
||||
|
||||
/*
|
||||
* The two strings are the same in the first len bytes, and they
|
||||
* are of different lengths.
|
||||
*/
|
||||
|
||||
if (VARSIZE(a) < VARSIZE(b))
|
||||
return (-1);
|
||||
else
|
||||
return (1);
|
||||
|
||||
if (res != 0 || VARSIZE(a) == VARSIZE(b))
|
||||
return (res);
|
||||
|
||||
/*
|
||||
* The two strings are the same in the first len bytes, and they are
|
||||
* of different lengths.
|
||||
*/
|
||||
|
||||
if (VARSIZE(a) < VARSIZE(b))
|
||||
return (-1);
|
||||
else
|
||||
return (1);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,28 +1,28 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* btscan.c--
|
||||
* manage scans on btrees.
|
||||
* manage scans on btrees.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/Attic/nbtscan.c,v 1.7 1997/02/18 17:13:45 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/Attic/nbtscan.c,v 1.8 1997/09/07 04:38:57 momjian Exp $
|
||||
*
|
||||
*
|
||||
* NOTES
|
||||
* Because we can be doing an index scan on a relation while we update
|
||||
* it, we need to avoid missing data that moves around in the index.
|
||||
* The routines and global variables in this file guarantee that all
|
||||
* scans in the local address space stay correctly positioned. This
|
||||
* is all we need to worry about, since write locking guarantees that
|
||||
* no one else will be on the same page at the same time as we are.
|
||||
* Because we can be doing an index scan on a relation while we update
|
||||
* it, we need to avoid missing data that moves around in the index.
|
||||
* The routines and global variables in this file guarantee that all
|
||||
* scans in the local address space stay correctly positioned. This
|
||||
* is all we need to worry about, since write locking guarantees that
|
||||
* no one else will be on the same page at the same time as we are.
|
||||
*
|
||||
* The scheme is to manage a list of active scans in the current backend.
|
||||
* Whenever we add or remove records from an index, or whenever we
|
||||
* split a leaf page, we check the list of active scans to see if any
|
||||
* has been affected. A scan is affected only if it is on the same
|
||||
* relation, and the same page, as the update.
|
||||
* The scheme is to manage a list of active scans in the current backend.
|
||||
* Whenever we add or remove records from an index, or whenever we
|
||||
* split a leaf page, we check the list of active scans to see if any
|
||||
* has been affected. A scan is affected only if it is on the same
|
||||
* relation, and the same page, as the update.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -32,83 +32,87 @@
|
||||
#include <storage/bufpage.h>
|
||||
#include <access/nbtree.h>
|
||||
|
||||
typedef struct BTScanListData {
|
||||
IndexScanDesc btsl_scan;
|
||||
struct BTScanListData *btsl_next;
|
||||
} BTScanListData;
|
||||
typedef struct BTScanListData
|
||||
{
|
||||
IndexScanDesc btsl_scan;
|
||||
struct BTScanListData *btsl_next;
|
||||
} BTScanListData;
|
||||
|
||||
typedef BTScanListData *BTScanList;
|
||||
typedef BTScanListData *BTScanList;
|
||||
|
||||
static BTScanList BTScans = (BTScanList) NULL;
|
||||
static BTScanList BTScans = (BTScanList) NULL;
|
||||
|
||||
static void _bt_scandel(IndexScanDesc scan, int op, BlockNumber blkno, OffsetNumber offno);
|
||||
static bool _bt_scantouched(IndexScanDesc scan, BlockNumber blkno, OffsetNumber offno);
|
||||
static void _bt_scandel(IndexScanDesc scan, int op, BlockNumber blkno, OffsetNumber offno);
|
||||
static bool _bt_scantouched(IndexScanDesc scan, BlockNumber blkno, OffsetNumber offno);
|
||||
|
||||
/*
|
||||
* _bt_regscan() -- register a new scan.
|
||||
* _bt_regscan() -- register a new scan.
|
||||
*/
|
||||
void
|
||||
_bt_regscan(IndexScanDesc scan)
|
||||
{
|
||||
BTScanList new_el;
|
||||
|
||||
new_el = (BTScanList) palloc(sizeof(BTScanListData));
|
||||
new_el->btsl_scan = scan;
|
||||
new_el->btsl_next = BTScans;
|
||||
BTScans = new_el;
|
||||
BTScanList new_el;
|
||||
|
||||
new_el = (BTScanList) palloc(sizeof(BTScanListData));
|
||||
new_el->btsl_scan = scan;
|
||||
new_el->btsl_next = BTScans;
|
||||
BTScans = new_el;
|
||||
}
|
||||
|
||||
/*
|
||||
* _bt_dropscan() -- drop a scan from the scan list
|
||||
* _bt_dropscan() -- drop a scan from the scan list
|
||||
*/
|
||||
void
|
||||
_bt_dropscan(IndexScanDesc scan)
|
||||
{
|
||||
BTScanList chk, last;
|
||||
|
||||
last = (BTScanList) NULL;
|
||||
for (chk = BTScans;
|
||||
chk != (BTScanList) NULL && chk->btsl_scan != scan;
|
||||
chk = chk->btsl_next) {
|
||||
last = chk;
|
||||
}
|
||||
|
||||
if (chk == (BTScanList) NULL)
|
||||
elog(WARN, "btree scan list trashed; can't find 0x%lx", scan);
|
||||
|
||||
if (last == (BTScanList) NULL)
|
||||
BTScans = chk->btsl_next;
|
||||
else
|
||||
last->btsl_next = chk->btsl_next;
|
||||
|
||||
pfree (chk);
|
||||
BTScanList chk,
|
||||
last;
|
||||
|
||||
last = (BTScanList) NULL;
|
||||
for (chk = BTScans;
|
||||
chk != (BTScanList) NULL && chk->btsl_scan != scan;
|
||||
chk = chk->btsl_next)
|
||||
{
|
||||
last = chk;
|
||||
}
|
||||
|
||||
if (chk == (BTScanList) NULL)
|
||||
elog(WARN, "btree scan list trashed; can't find 0x%lx", scan);
|
||||
|
||||
if (last == (BTScanList) NULL)
|
||||
BTScans = chk->btsl_next;
|
||||
else
|
||||
last->btsl_next = chk->btsl_next;
|
||||
|
||||
pfree(chk);
|
||||
}
|
||||
|
||||
/*
|
||||
* _bt_adjscans() -- adjust all scans in the scan list to compensate
|
||||
* for a given deletion or insertion
|
||||
* _bt_adjscans() -- adjust all scans in the scan list to compensate
|
||||
* for a given deletion or insertion
|
||||
*/
|
||||
void
|
||||
_bt_adjscans(Relation rel, ItemPointer tid, int op)
|
||||
{
|
||||
BTScanList l;
|
||||
Oid relid;
|
||||
|
||||
relid = rel->rd_id;
|
||||
for (l = BTScans; l != (BTScanList) NULL; l = l->btsl_next) {
|
||||
if (relid == l->btsl_scan->relation->rd_id)
|
||||
_bt_scandel(l->btsl_scan, op,
|
||||
ItemPointerGetBlockNumber(tid),
|
||||
ItemPointerGetOffsetNumber(tid));
|
||||
}
|
||||
BTScanList l;
|
||||
Oid relid;
|
||||
|
||||
relid = rel->rd_id;
|
||||
for (l = BTScans; l != (BTScanList) NULL; l = l->btsl_next)
|
||||
{
|
||||
if (relid == l->btsl_scan->relation->rd_id)
|
||||
_bt_scandel(l->btsl_scan, op,
|
||||
ItemPointerGetBlockNumber(tid),
|
||||
ItemPointerGetOffsetNumber(tid));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* _bt_scandel() -- adjust a single scan
|
||||
* _bt_scandel() -- adjust a single scan
|
||||
*
|
||||
* because each index page is always maintained as an ordered array of
|
||||
* index tuples, the index tuples on a given page shift beneath any
|
||||
* given scan. an index modification "behind" a scan position (i.e.,
|
||||
* given scan. an index modification "behind" a scan position (i.e.,
|
||||
* same page, lower or equal offset number) will therefore force us to
|
||||
* adjust the scan in the following ways:
|
||||
*
|
||||
@@ -126,80 +130,85 @@ _bt_adjscans(Relation rel, ItemPointer tid, int op)
|
||||
static void
|
||||
_bt_scandel(IndexScanDesc scan, int op, BlockNumber blkno, OffsetNumber offno)
|
||||
{
|
||||
ItemPointer current;
|
||||
Buffer buf;
|
||||
BTScanOpaque so;
|
||||
|
||||
if (!_bt_scantouched(scan, blkno, offno))
|
||||
return;
|
||||
|
||||
so = (BTScanOpaque) scan->opaque;
|
||||
buf = so->btso_curbuf;
|
||||
|
||||
current = &(scan->currentItemData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno) {
|
||||
switch (op) {
|
||||
case BT_INSERT:
|
||||
_bt_step(scan, &buf, ForwardScanDirection);
|
||||
break;
|
||||
case BT_DELETE:
|
||||
_bt_step(scan, &buf, BackwardScanDirection);
|
||||
break;
|
||||
default:
|
||||
elog(WARN, "_bt_scandel: bad operation '%d'", op);
|
||||
/*NOTREACHED*/
|
||||
ItemPointer current;
|
||||
Buffer buf;
|
||||
BTScanOpaque so;
|
||||
|
||||
if (!_bt_scantouched(scan, blkno, offno))
|
||||
return;
|
||||
|
||||
so = (BTScanOpaque) scan->opaque;
|
||||
buf = so->btso_curbuf;
|
||||
|
||||
current = &(scan->currentItemData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case BT_INSERT:
|
||||
_bt_step(scan, &buf, ForwardScanDirection);
|
||||
break;
|
||||
case BT_DELETE:
|
||||
_bt_step(scan, &buf, BackwardScanDirection);
|
||||
break;
|
||||
default:
|
||||
elog(WARN, "_bt_scandel: bad operation '%d'", op);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
so->btso_curbuf = buf;
|
||||
}
|
||||
so->btso_curbuf = buf;
|
||||
}
|
||||
|
||||
current = &(scan->currentMarkData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno) {
|
||||
ItemPointerData tmp;
|
||||
tmp = *current;
|
||||
*current = scan->currentItemData;
|
||||
scan->currentItemData = tmp;
|
||||
switch (op) {
|
||||
case BT_INSERT:
|
||||
_bt_step(scan, &buf, ForwardScanDirection);
|
||||
break;
|
||||
case BT_DELETE:
|
||||
_bt_step(scan, &buf, BackwardScanDirection);
|
||||
break;
|
||||
default:
|
||||
elog(WARN, "_bt_scandel: bad operation '%d'", op);
|
||||
/*NOTREACHED*/
|
||||
|
||||
current = &(scan->currentMarkData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno)
|
||||
{
|
||||
ItemPointerData tmp;
|
||||
|
||||
tmp = *current;
|
||||
*current = scan->currentItemData;
|
||||
scan->currentItemData = tmp;
|
||||
switch (op)
|
||||
{
|
||||
case BT_INSERT:
|
||||
_bt_step(scan, &buf, ForwardScanDirection);
|
||||
break;
|
||||
case BT_DELETE:
|
||||
_bt_step(scan, &buf, BackwardScanDirection);
|
||||
break;
|
||||
default:
|
||||
elog(WARN, "_bt_scandel: bad operation '%d'", op);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
so->btso_mrkbuf = buf;
|
||||
tmp = *current;
|
||||
*current = scan->currentItemData;
|
||||
scan->currentItemData = tmp;
|
||||
}
|
||||
so->btso_mrkbuf = buf;
|
||||
tmp = *current;
|
||||
*current = scan->currentItemData;
|
||||
scan->currentItemData = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* _bt_scantouched() -- check to see if a scan is affected by a given
|
||||
* change to the index
|
||||
* _bt_scantouched() -- check to see if a scan is affected by a given
|
||||
* change to the index
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
_bt_scantouched(IndexScanDesc scan, BlockNumber blkno, OffsetNumber offno)
|
||||
{
|
||||
ItemPointer current;
|
||||
|
||||
current = &(scan->currentItemData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno)
|
||||
return (true);
|
||||
|
||||
current = &(scan->currentMarkData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno)
|
||||
return (true);
|
||||
|
||||
return (false);
|
||||
ItemPointer current;
|
||||
|
||||
current = &(scan->currentItemData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno)
|
||||
return (true);
|
||||
|
||||
current = &(scan->currentMarkData);
|
||||
if (ItemPointerIsValid(current)
|
||||
&& ItemPointerGetBlockNumber(current) == blkno
|
||||
&& ItemPointerGetOffsetNumber(current) >= offno)
|
||||
return (true);
|
||||
|
||||
return (false);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* btstrat.c--
|
||||
* Srategy map entries for the btree indexed access method
|
||||
* Srategy map entries for the btree indexed access method
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/Attic/nbtstrat.c,v 1.4 1996/11/05 10:35:37 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/Attic/nbtstrat.c,v 1.5 1997/09/07 04:39:04 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -20,111 +20,111 @@
|
||||
|
||||
/*
|
||||
* Note:
|
||||
* StrategyNegate, StrategyCommute, and StrategyNegateCommute
|
||||
* assume <, <=, ==, >=, > ordering.
|
||||
* StrategyNegate, StrategyCommute, and StrategyNegateCommute
|
||||
* assume <, <=, ==, >=, > ordering.
|
||||
*/
|
||||
static StrategyNumber BTNegate[5] = {
|
||||
BTGreaterEqualStrategyNumber,
|
||||
BTGreaterStrategyNumber,
|
||||
InvalidStrategy,
|
||||
BTLessStrategyNumber,
|
||||
BTLessEqualStrategyNumber
|
||||
static StrategyNumber BTNegate[5] = {
|
||||
BTGreaterEqualStrategyNumber,
|
||||
BTGreaterStrategyNumber,
|
||||
InvalidStrategy,
|
||||
BTLessStrategyNumber,
|
||||
BTLessEqualStrategyNumber
|
||||
};
|
||||
|
||||
static StrategyNumber BTCommute[5] = {
|
||||
BTGreaterStrategyNumber,
|
||||
BTGreaterEqualStrategyNumber,
|
||||
InvalidStrategy,
|
||||
BTLessEqualStrategyNumber,
|
||||
BTLessStrategyNumber
|
||||
static StrategyNumber BTCommute[5] = {
|
||||
BTGreaterStrategyNumber,
|
||||
BTGreaterEqualStrategyNumber,
|
||||
InvalidStrategy,
|
||||
BTLessEqualStrategyNumber,
|
||||
BTLessStrategyNumber
|
||||
};
|
||||
|
||||
static StrategyNumber BTNegateCommute[5] = {
|
||||
BTLessEqualStrategyNumber,
|
||||
BTLessStrategyNumber,
|
||||
InvalidStrategy,
|
||||
BTGreaterStrategyNumber,
|
||||
BTGreaterEqualStrategyNumber
|
||||
static StrategyNumber BTNegateCommute[5] = {
|
||||
BTLessEqualStrategyNumber,
|
||||
BTLessStrategyNumber,
|
||||
InvalidStrategy,
|
||||
BTGreaterStrategyNumber,
|
||||
BTGreaterEqualStrategyNumber
|
||||
};
|
||||
|
||||
static uint16 BTLessTermData[] = { /* XXX type clash */
|
||||
2,
|
||||
BTLessStrategyNumber,
|
||||
SK_NEGATE,
|
||||
BTLessStrategyNumber,
|
||||
SK_NEGATE | SK_COMMUTE
|
||||
static uint16 BTLessTermData[] = { /* XXX type clash */
|
||||
2,
|
||||
BTLessStrategyNumber,
|
||||
SK_NEGATE,
|
||||
BTLessStrategyNumber,
|
||||
SK_NEGATE | SK_COMMUTE
|
||||
};
|
||||
|
||||
static uint16 BTLessEqualTermData[] = { /* XXX type clash */
|
||||
2,
|
||||
BTLessEqualStrategyNumber,
|
||||
0x0,
|
||||
BTLessEqualStrategyNumber,
|
||||
SK_COMMUTE
|
||||
static uint16 BTLessEqualTermData[] = { /* XXX type clash */
|
||||
2,
|
||||
BTLessEqualStrategyNumber,
|
||||
0x0,
|
||||
BTLessEqualStrategyNumber,
|
||||
SK_COMMUTE
|
||||
};
|
||||
|
||||
static uint16 BTGreaterEqualTermData[] = { /* XXX type clash */
|
||||
2,
|
||||
BTGreaterEqualStrategyNumber,
|
||||
0x0,
|
||||
BTGreaterEqualStrategyNumber,
|
||||
SK_COMMUTE
|
||||
};
|
||||
|
||||
static uint16 BTGreaterTermData[] = { /* XXX type clash */
|
||||
2,
|
||||
BTGreaterStrategyNumber,
|
||||
SK_NEGATE,
|
||||
BTGreaterStrategyNumber,
|
||||
SK_NEGATE | SK_COMMUTE
|
||||
2,
|
||||
BTGreaterEqualStrategyNumber,
|
||||
0x0,
|
||||
BTGreaterEqualStrategyNumber,
|
||||
SK_COMMUTE
|
||||
};
|
||||
|
||||
static StrategyTerm BTEqualExpressionData[] = {
|
||||
(StrategyTerm)BTLessTermData, /* XXX */
|
||||
(StrategyTerm)BTLessEqualTermData, /* XXX */
|
||||
(StrategyTerm)BTGreaterEqualTermData, /* XXX */
|
||||
(StrategyTerm)BTGreaterTermData, /* XXX */
|
||||
NULL
|
||||
static uint16 BTGreaterTermData[] = { /* XXX type clash */
|
||||
2,
|
||||
BTGreaterStrategyNumber,
|
||||
SK_NEGATE,
|
||||
BTGreaterStrategyNumber,
|
||||
SK_NEGATE | SK_COMMUTE
|
||||
};
|
||||
|
||||
static StrategyEvaluationData BTEvaluationData = {
|
||||
/* XXX static for simplicity */
|
||||
|
||||
BTMaxStrategyNumber,
|
||||
(StrategyTransformMap)BTNegate, /* XXX */
|
||||
(StrategyTransformMap)BTCommute, /* XXX */
|
||||
(StrategyTransformMap)BTNegateCommute, /* XXX */
|
||||
static StrategyTerm BTEqualExpressionData[] = {
|
||||
(StrategyTerm) BTLessTermData, /* XXX */
|
||||
(StrategyTerm) BTLessEqualTermData, /* XXX */
|
||||
(StrategyTerm) BTGreaterEqualTermData, /* XXX */
|
||||
(StrategyTerm) BTGreaterTermData, /* XXX */
|
||||
NULL
|
||||
};
|
||||
|
||||
{ NULL, NULL, (StrategyExpression)BTEqualExpressionData, NULL, NULL,
|
||||
NULL,NULL,NULL,NULL,NULL,NULL,NULL}
|
||||
static StrategyEvaluationData BTEvaluationData = {
|
||||
/* XXX static for simplicity */
|
||||
|
||||
BTMaxStrategyNumber,
|
||||
(StrategyTransformMap) BTNegate, /* XXX */
|
||||
(StrategyTransformMap) BTCommute, /* XXX */
|
||||
(StrategyTransformMap) BTNegateCommute, /* XXX */
|
||||
|
||||
{NULL, NULL, (StrategyExpression) BTEqualExpressionData, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* RelationGetBTStrategy
|
||||
* RelationGetBTStrategy
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
StrategyNumber
|
||||
_bt_getstrat(Relation rel,
|
||||
AttrNumber attno,
|
||||
RegProcedure proc)
|
||||
AttrNumber attno,
|
||||
RegProcedure proc)
|
||||
{
|
||||
StrategyNumber strat;
|
||||
|
||||
strat = RelationGetStrategy(rel, attno, &BTEvaluationData, proc);
|
||||
|
||||
Assert(StrategyNumberIsValid(strat));
|
||||
|
||||
return (strat);
|
||||
StrategyNumber strat;
|
||||
|
||||
strat = RelationGetStrategy(rel, attno, &BTEvaluationData, proc);
|
||||
|
||||
Assert(StrategyNumberIsValid(strat));
|
||||
|
||||
return (strat);
|
||||
}
|
||||
|
||||
bool
|
||||
_bt_invokestrat(Relation rel,
|
||||
AttrNumber attno,
|
||||
StrategyNumber strat,
|
||||
Datum left,
|
||||
Datum right)
|
||||
AttrNumber attno,
|
||||
StrategyNumber strat,
|
||||
Datum left,
|
||||
Datum right)
|
||||
{
|
||||
return (RelationInvokeStrategy(rel, &BTEvaluationData, attno, strat,
|
||||
left, right));
|
||||
return (RelationInvokeStrategy(rel, &BTEvaluationData, attno, strat,
|
||||
left, right));
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* btutils.c--
|
||||
* Utility code for Postgres btree implementation.
|
||||
* Utility code for Postgres btree implementation.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.11 1997/08/19 21:29:47 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.12 1997/09/07 04:39:05 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -23,367 +23,384 @@
|
||||
#include <catalog/pg_proc.h>
|
||||
#include <executor/execdebug.h>
|
||||
|
||||
extern int NIndexTupleProcessed;
|
||||
extern int NIndexTupleProcessed;
|
||||
|
||||
|
||||
#ifndef HAVE_MEMMOVE
|
||||
# include <regex/utils.h>
|
||||
#include <regex/utils.h>
|
||||
#else
|
||||
# include <string.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
ScanKey
|
||||
ScanKey
|
||||
_bt_mkscankey(Relation rel, IndexTuple itup)
|
||||
{
|
||||
ScanKey skey;
|
||||
TupleDesc itupdesc;
|
||||
int natts;
|
||||
int i;
|
||||
Datum arg;
|
||||
RegProcedure proc;
|
||||
bool null;
|
||||
bits16 flag;
|
||||
|
||||
natts = rel->rd_rel->relnatts;
|
||||
itupdesc = RelationGetTupleDescriptor(rel);
|
||||
|
||||
skey = (ScanKey) palloc(natts * sizeof(ScanKeyData));
|
||||
|
||||
for (i = 0; i < natts; i++) {
|
||||
arg = index_getattr(itup, i + 1, itupdesc, &null);
|
||||
if ( null )
|
||||
{
|
||||
ScanKey skey;
|
||||
TupleDesc itupdesc;
|
||||
int natts;
|
||||
int i;
|
||||
Datum arg;
|
||||
RegProcedure proc;
|
||||
bool null;
|
||||
bits16 flag;
|
||||
|
||||
natts = rel->rd_rel->relnatts;
|
||||
itupdesc = RelationGetTupleDescriptor(rel);
|
||||
|
||||
skey = (ScanKey) palloc(natts * sizeof(ScanKeyData));
|
||||
|
||||
for (i = 0; i < natts; i++)
|
||||
{
|
||||
proc = NullValueRegProcedure;
|
||||
flag = SK_ISNULL;
|
||||
arg = index_getattr(itup, i + 1, itupdesc, &null);
|
||||
if (null)
|
||||
{
|
||||
proc = NullValueRegProcedure;
|
||||
flag = SK_ISNULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
proc = index_getprocid(rel, i + 1, BTORDER_PROC);
|
||||
flag = 0x0;
|
||||
}
|
||||
ScanKeyEntryInitialize(&skey[i],
|
||||
flag, (AttrNumber) (i + 1), proc, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
proc = index_getprocid(rel, i + 1, BTORDER_PROC);
|
||||
flag = 0x0;
|
||||
}
|
||||
ScanKeyEntryInitialize(&skey[i],
|
||||
flag, (AttrNumber) (i + 1), proc, arg);
|
||||
}
|
||||
|
||||
return (skey);
|
||||
|
||||
return (skey);
|
||||
}
|
||||
|
||||
void
|
||||
_bt_freeskey(ScanKey skey)
|
||||
{
|
||||
pfree(skey);
|
||||
pfree(skey);
|
||||
}
|
||||
|
||||
void
|
||||
_bt_freestack(BTStack stack)
|
||||
{
|
||||
BTStack ostack;
|
||||
|
||||
while (stack != (BTStack) NULL) {
|
||||
ostack = stack;
|
||||
stack = stack->bts_parent;
|
||||
pfree(ostack->bts_btitem);
|
||||
pfree(ostack);
|
||||
}
|
||||
BTStack ostack;
|
||||
|
||||
while (stack != (BTStack) NULL)
|
||||
{
|
||||
ostack = stack;
|
||||
stack = stack->bts_parent;
|
||||
pfree(ostack->bts_btitem);
|
||||
pfree(ostack);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* _bt_orderkeys() -- Put keys in a sensible order for conjunctive quals.
|
||||
* _bt_orderkeys() -- Put keys in a sensible order for conjunctive quals.
|
||||
*
|
||||
* The order of the keys in the qual match the ordering imposed by
|
||||
* the index. This routine only needs to be called if there are
|
||||
* more than one qual clauses using this index.
|
||||
* The order of the keys in the qual match the ordering imposed by
|
||||
* the index. This routine only needs to be called if there are
|
||||
* more than one qual clauses using this index.
|
||||
*/
|
||||
void
|
||||
_bt_orderkeys(Relation relation, BTScanOpaque so)
|
||||
{
|
||||
ScanKey xform;
|
||||
ScanKeyData *cur;
|
||||
StrategyMap map;
|
||||
int nbytes;
|
||||
long test;
|
||||
int i, j;
|
||||
int init[BTMaxStrategyNumber+1];
|
||||
ScanKey key;
|
||||
uint16 numberOfKeys = so->numberOfKeys;
|
||||
uint16 new_numberOfKeys = 0;
|
||||
AttrNumber attno = 1;
|
||||
|
||||
if ( numberOfKeys < 1 )
|
||||
return;
|
||||
|
||||
key = so->keyData;
|
||||
|
||||
cur = &key[0];
|
||||
if ( cur->sk_attno != 1 )
|
||||
elog (WARN, "_bt_orderkeys: key(s) for attribute 1 missed");
|
||||
|
||||
if ( numberOfKeys == 1 )
|
||||
{
|
||||
/*
|
||||
* We don't use indices for 'A is null' and 'A is not null'
|
||||
* currently and 'A < = > <> NULL' is non-sense' - so
|
||||
* qual is not Ok. - vadim 03/21/97
|
||||
*/
|
||||
if ( cur->sk_flags & SK_ISNULL )
|
||||
so->qual_ok = 0;
|
||||
so->numberOfFirstKeys = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* get space for the modified array of keys */
|
||||
nbytes = BTMaxStrategyNumber * sizeof(ScanKeyData);
|
||||
xform = (ScanKey) palloc(nbytes);
|
||||
ScanKey xform;
|
||||
ScanKeyData *cur;
|
||||
StrategyMap map;
|
||||
int nbytes;
|
||||
long test;
|
||||
int i,
|
||||
j;
|
||||
int init[BTMaxStrategyNumber + 1];
|
||||
ScanKey key;
|
||||
uint16 numberOfKeys = so->numberOfKeys;
|
||||
uint16 new_numberOfKeys = 0;
|
||||
AttrNumber attno = 1;
|
||||
|
||||
memset(xform, 0, nbytes);
|
||||
map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
|
||||
BTMaxStrategyNumber,
|
||||
attno);
|
||||
for (j = 0; j <= BTMaxStrategyNumber; j++)
|
||||
init[j] = 0;
|
||||
|
||||
/* check each key passed in */
|
||||
for (i = 0; ; )
|
||||
{
|
||||
if ( i < numberOfKeys )
|
||||
cur = &key[i];
|
||||
if (numberOfKeys < 1)
|
||||
return;
|
||||
|
||||
if ( cur->sk_flags & SK_ISNULL ) /* see comments above */
|
||||
so->qual_ok = 0;
|
||||
key = so->keyData;
|
||||
|
||||
if ( i == numberOfKeys || cur->sk_attno != attno )
|
||||
cur = &key[0];
|
||||
if (cur->sk_attno != 1)
|
||||
elog(WARN, "_bt_orderkeys: key(s) for attribute 1 missed");
|
||||
|
||||
if (numberOfKeys == 1)
|
||||
{
|
||||
if ( cur->sk_attno != attno + 1 && i < numberOfKeys )
|
||||
{
|
||||
elog (WARN, "_bt_orderkeys: key(s) for attribute %d missed", attno + 1);
|
||||
}
|
||||
/*
|
||||
* If = has been specified, no other key will be used.
|
||||
* In case of key < 2 && key == 1 and so on
|
||||
* we have to set qual_ok to 0
|
||||
*/
|
||||
if (init[BTEqualStrategyNumber - 1])
|
||||
{
|
||||
ScanKeyData *eq, *chk;
|
||||
|
||||
eq = &xform[BTEqualStrategyNumber - 1];
|
||||
for (j = BTMaxStrategyNumber; --j >= 0; )
|
||||
{
|
||||
if ( j == (BTEqualStrategyNumber - 1) || init[j] == 0 )
|
||||
continue;
|
||||
chk = &xform[j];
|
||||
test = (long) fmgr(chk->sk_procedure, eq->sk_argument, chk->sk_argument);
|
||||
if (!test)
|
||||
so->qual_ok = 0;
|
||||
}
|
||||
init[BTLessStrategyNumber - 1] = 0;
|
||||
init[BTLessEqualStrategyNumber - 1] = 0;
|
||||
init[BTGreaterEqualStrategyNumber - 1] = 0;
|
||||
init[BTGreaterStrategyNumber - 1] = 0;
|
||||
}
|
||||
|
||||
/* only one of <, <= */
|
||||
if (init[BTLessStrategyNumber - 1]
|
||||
&& init[BTLessEqualStrategyNumber - 1])
|
||||
{
|
||||
ScanKeyData *lt, *le;
|
||||
|
||||
lt = &xform[BTLessStrategyNumber - 1];
|
||||
le = &xform[BTLessEqualStrategyNumber - 1];
|
||||
/*
|
||||
* DO NOT use the cached function stuff here -- this is key
|
||||
* ordering, happens only when the user expresses a hokey
|
||||
* qualification, and gets executed only once, anyway. The
|
||||
* transform maps are hard-coded, and can't be initialized
|
||||
* in the correct way.
|
||||
* We don't use indices for 'A is null' and 'A is not null'
|
||||
* currently and 'A < = > <> NULL' is non-sense' - so qual is not
|
||||
* Ok. - vadim 03/21/97
|
||||
*/
|
||||
test = (long) fmgr(le->sk_procedure, lt->sk_argument, le->sk_argument);
|
||||
if (test)
|
||||
init[BTLessEqualStrategyNumber - 1] = 0;
|
||||
else
|
||||
init[BTLessStrategyNumber - 1] = 0;
|
||||
}
|
||||
|
||||
/* only one of >, >= */
|
||||
if (init[BTGreaterStrategyNumber - 1]
|
||||
&& init[BTGreaterEqualStrategyNumber - 1])
|
||||
{
|
||||
ScanKeyData *gt, *ge;
|
||||
|
||||
gt = &xform[BTGreaterStrategyNumber - 1];
|
||||
ge = &xform[BTGreaterEqualStrategyNumber - 1];
|
||||
|
||||
/* see note above on function cache */
|
||||
test = (long) fmgr(ge->sk_procedure, gt->sk_argument, ge->sk_argument);
|
||||
if (test)
|
||||
init[BTGreaterEqualStrategyNumber - 1] = 0;
|
||||
else
|
||||
init[BTGreaterStrategyNumber - 1] = 0;
|
||||
}
|
||||
|
||||
/* okay, reorder and count */
|
||||
for (j = BTMaxStrategyNumber; --j >= 0; )
|
||||
if (init[j])
|
||||
key[new_numberOfKeys++] = xform[j];
|
||||
|
||||
if ( attno == 1 )
|
||||
so->numberOfFirstKeys = new_numberOfKeys;
|
||||
|
||||
if ( i == numberOfKeys )
|
||||
break;
|
||||
if (cur->sk_flags & SK_ISNULL)
|
||||
so->qual_ok = 0;
|
||||
so->numberOfFirstKeys = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* initialization for new attno */
|
||||
attno = cur->sk_attno;
|
||||
memset(xform, 0, nbytes);
|
||||
map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
|
||||
BTMaxStrategyNumber,
|
||||
attno);
|
||||
/* haven't looked at any strategies yet */
|
||||
for (j = 0; j <= BTMaxStrategyNumber; j++)
|
||||
/* get space for the modified array of keys */
|
||||
nbytes = BTMaxStrategyNumber * sizeof(ScanKeyData);
|
||||
xform = (ScanKey) palloc(nbytes);
|
||||
|
||||
memset(xform, 0, nbytes);
|
||||
map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
|
||||
BTMaxStrategyNumber,
|
||||
attno);
|
||||
for (j = 0; j <= BTMaxStrategyNumber; j++)
|
||||
init[j] = 0;
|
||||
|
||||
/* check each key passed in */
|
||||
for (i = 0;;)
|
||||
{
|
||||
if (i < numberOfKeys)
|
||||
cur = &key[i];
|
||||
|
||||
if (cur->sk_flags & SK_ISNULL) /* see comments above */
|
||||
so->qual_ok = 0;
|
||||
|
||||
if (i == numberOfKeys || cur->sk_attno != attno)
|
||||
{
|
||||
if (cur->sk_attno != attno + 1 && i < numberOfKeys)
|
||||
{
|
||||
elog(WARN, "_bt_orderkeys: key(s) for attribute %d missed", attno + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* If = has been specified, no other key will be used. In case
|
||||
* of key < 2 && key == 1 and so on we have to set qual_ok to
|
||||
* 0
|
||||
*/
|
||||
if (init[BTEqualStrategyNumber - 1])
|
||||
{
|
||||
ScanKeyData *eq,
|
||||
*chk;
|
||||
|
||||
eq = &xform[BTEqualStrategyNumber - 1];
|
||||
for (j = BTMaxStrategyNumber; --j >= 0;)
|
||||
{
|
||||
if (j == (BTEqualStrategyNumber - 1) || init[j] == 0)
|
||||
continue;
|
||||
chk = &xform[j];
|
||||
test = (long) fmgr(chk->sk_procedure, eq->sk_argument, chk->sk_argument);
|
||||
if (!test)
|
||||
so->qual_ok = 0;
|
||||
}
|
||||
init[BTLessStrategyNumber - 1] = 0;
|
||||
init[BTLessEqualStrategyNumber - 1] = 0;
|
||||
init[BTGreaterEqualStrategyNumber - 1] = 0;
|
||||
init[BTGreaterStrategyNumber - 1] = 0;
|
||||
}
|
||||
|
||||
/* only one of <, <= */
|
||||
if (init[BTLessStrategyNumber - 1]
|
||||
&& init[BTLessEqualStrategyNumber - 1])
|
||||
{
|
||||
ScanKeyData *lt,
|
||||
*le;
|
||||
|
||||
lt = &xform[BTLessStrategyNumber - 1];
|
||||
le = &xform[BTLessEqualStrategyNumber - 1];
|
||||
|
||||
/*
|
||||
* DO NOT use the cached function stuff here -- this is
|
||||
* key ordering, happens only when the user expresses a
|
||||
* hokey qualification, and gets executed only once,
|
||||
* anyway. The transform maps are hard-coded, and can't
|
||||
* be initialized in the correct way.
|
||||
*/
|
||||
test = (long) fmgr(le->sk_procedure, lt->sk_argument, le->sk_argument);
|
||||
if (test)
|
||||
init[BTLessEqualStrategyNumber - 1] = 0;
|
||||
else
|
||||
init[BTLessStrategyNumber - 1] = 0;
|
||||
}
|
||||
|
||||
/* only one of >, >= */
|
||||
if (init[BTGreaterStrategyNumber - 1]
|
||||
&& init[BTGreaterEqualStrategyNumber - 1])
|
||||
{
|
||||
ScanKeyData *gt,
|
||||
*ge;
|
||||
|
||||
gt = &xform[BTGreaterStrategyNumber - 1];
|
||||
ge = &xform[BTGreaterEqualStrategyNumber - 1];
|
||||
|
||||
/* see note above on function cache */
|
||||
test = (long) fmgr(ge->sk_procedure, gt->sk_argument, ge->sk_argument);
|
||||
if (test)
|
||||
init[BTGreaterEqualStrategyNumber - 1] = 0;
|
||||
else
|
||||
init[BTGreaterStrategyNumber - 1] = 0;
|
||||
}
|
||||
|
||||
/* okay, reorder and count */
|
||||
for (j = BTMaxStrategyNumber; --j >= 0;)
|
||||
if (init[j])
|
||||
key[new_numberOfKeys++] = xform[j];
|
||||
|
||||
if (attno == 1)
|
||||
so->numberOfFirstKeys = new_numberOfKeys;
|
||||
|
||||
if (i == numberOfKeys)
|
||||
break;
|
||||
|
||||
/* initialization for new attno */
|
||||
attno = cur->sk_attno;
|
||||
memset(xform, 0, nbytes);
|
||||
map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
|
||||
BTMaxStrategyNumber,
|
||||
attno);
|
||||
/* haven't looked at any strategies yet */
|
||||
for (j = 0; j <= BTMaxStrategyNumber; j++)
|
||||
init[j] = 0;
|
||||
}
|
||||
|
||||
for (j = BTMaxStrategyNumber; --j >= 0;)
|
||||
{
|
||||
if (cur->sk_procedure == map->entry[j].sk_procedure)
|
||||
break;
|
||||
}
|
||||
|
||||
/* have we seen one of these before? */
|
||||
if (init[j])
|
||||
{
|
||||
/* yup, use the appropriate value */
|
||||
test =
|
||||
(long) FMGR_PTR2(cur->sk_func, cur->sk_procedure,
|
||||
cur->sk_argument, xform[j].sk_argument);
|
||||
if (test)
|
||||
xform[j].sk_argument = cur->sk_argument;
|
||||
else if (j == (BTEqualStrategyNumber - 1))
|
||||
so->qual_ok = 0;/* key == a && key == b, but a != b */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* nope, use this value */
|
||||
memmove(&xform[j], cur, sizeof(*cur));
|
||||
init[j] = 1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
for (j = BTMaxStrategyNumber; --j >= 0; )
|
||||
{
|
||||
if (cur->sk_procedure == map->entry[j].sk_procedure)
|
||||
break;
|
||||
}
|
||||
|
||||
/* have we seen one of these before? */
|
||||
if (init[j])
|
||||
{
|
||||
/* yup, use the appropriate value */
|
||||
test =
|
||||
(long) FMGR_PTR2(cur->sk_func, cur->sk_procedure,
|
||||
cur->sk_argument, xform[j].sk_argument);
|
||||
if (test)
|
||||
xform[j].sk_argument = cur->sk_argument;
|
||||
else if ( j == (BTEqualStrategyNumber - 1) )
|
||||
so->qual_ok = 0; /* key == a && key == b, but a != b */
|
||||
} else
|
||||
{
|
||||
/* nope, use this value */
|
||||
memmove(&xform[j], cur, sizeof(*cur));
|
||||
init[j] = 1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
so->numberOfKeys = new_numberOfKeys;
|
||||
|
||||
pfree(xform);
|
||||
so->numberOfKeys = new_numberOfKeys;
|
||||
|
||||
pfree(xform);
|
||||
}
|
||||
|
||||
BTItem
|
||||
_bt_formitem(IndexTuple itup)
|
||||
{
|
||||
int nbytes_btitem;
|
||||
BTItem btitem;
|
||||
Size tuplen;
|
||||
extern Oid newoid();
|
||||
|
||||
/* see comments in btbuild
|
||||
|
||||
if (itup->t_info & INDEX_NULL_MASK)
|
||||
elog(WARN, "btree indices cannot include null keys");
|
||||
*/
|
||||
|
||||
/* make a copy of the index tuple with room for the sequence number */
|
||||
tuplen = IndexTupleSize(itup);
|
||||
nbytes_btitem = tuplen +
|
||||
(sizeof(BTItemData) - sizeof(IndexTupleData));
|
||||
|
||||
btitem = (BTItem) palloc(nbytes_btitem);
|
||||
memmove((char *) &(btitem->bti_itup), (char *) itup, tuplen);
|
||||
|
||||
int nbytes_btitem;
|
||||
BTItem btitem;
|
||||
Size tuplen;
|
||||
extern Oid newoid();
|
||||
|
||||
/*
|
||||
* see comments in btbuild
|
||||
*
|
||||
* if (itup->t_info & INDEX_NULL_MASK) elog(WARN, "btree indices cannot
|
||||
* include null keys");
|
||||
*/
|
||||
|
||||
/* make a copy of the index tuple with room for the sequence number */
|
||||
tuplen = IndexTupleSize(itup);
|
||||
nbytes_btitem = tuplen +
|
||||
(sizeof(BTItemData) - sizeof(IndexTupleData));
|
||||
|
||||
btitem = (BTItem) palloc(nbytes_btitem);
|
||||
memmove((char *) &(btitem->bti_itup), (char *) itup, tuplen);
|
||||
|
||||
#ifndef BTREE_VERSION_1
|
||||
btitem->bti_oid = newoid();
|
||||
btitem->bti_oid = newoid();
|
||||
#endif
|
||||
return (btitem);
|
||||
return (btitem);
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
bool
|
||||
_bt_checkqual(IndexScanDesc scan, IndexTuple itup)
|
||||
{
|
||||
BTScanOpaque so;
|
||||
|
||||
so = (BTScanOpaque) scan->opaque;
|
||||
if (so->numberOfKeys > 0)
|
||||
return (index_keytest(itup, RelationGetTupleDescriptor(scan->relation),
|
||||
so->numberOfKeys, so->keyData));
|
||||
else
|
||||
return (true);
|
||||
BTScanOpaque so;
|
||||
|
||||
so = (BTScanOpaque) scan->opaque;
|
||||
if (so->numberOfKeys > 0)
|
||||
return (index_keytest(itup, RelationGetTupleDescriptor(scan->relation),
|
||||
so->numberOfKeys, so->keyData));
|
||||
else
|
||||
return (true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NOT_USED
|
||||
bool
|
||||
_bt_checkforkeys(IndexScanDesc scan, IndexTuple itup, Size keysz)
|
||||
{
|
||||
BTScanOpaque so;
|
||||
|
||||
so = (BTScanOpaque) scan->opaque;
|
||||
if ( keysz > 0 && so->numberOfKeys >= keysz )
|
||||
return (index_keytest(itup, RelationGetTupleDescriptor(scan->relation),
|
||||
keysz, so->keyData));
|
||||
else
|
||||
return (true);
|
||||
BTScanOpaque so;
|
||||
|
||||
so = (BTScanOpaque) scan->opaque;
|
||||
if (keysz > 0 && so->numberOfKeys >= keysz)
|
||||
return (index_keytest(itup, RelationGetTupleDescriptor(scan->relation),
|
||||
keysz, so->keyData));
|
||||
else
|
||||
return (true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool
|
||||
_bt_checkkeys (IndexScanDesc scan, IndexTuple tuple, Size *keysok)
|
||||
_bt_checkkeys(IndexScanDesc scan, IndexTuple tuple, Size * keysok)
|
||||
{
|
||||
BTScanOpaque so = (BTScanOpaque) scan->opaque;
|
||||
Size keysz = so->numberOfKeys;
|
||||
TupleDesc tupdesc;
|
||||
ScanKey key;
|
||||
Datum datum;
|
||||
bool isNull;
|
||||
int test;
|
||||
|
||||
*keysok = 0;
|
||||
if ( keysz == 0 )
|
||||
return (true);
|
||||
|
||||
key = so->keyData;
|
||||
tupdesc = RelationGetTupleDescriptor(scan->relation);
|
||||
|
||||
IncrIndexProcessed();
|
||||
|
||||
while (keysz > 0)
|
||||
{
|
||||
datum = index_getattr(tuple,
|
||||
key[0].sk_attno,
|
||||
tupdesc,
|
||||
&isNull);
|
||||
|
||||
/* btree doesn't support 'A is null' clauses, yet */
|
||||
if ( isNull || key[0].sk_flags & SK_ISNULL )
|
||||
BTScanOpaque so = (BTScanOpaque) scan->opaque;
|
||||
Size keysz = so->numberOfKeys;
|
||||
TupleDesc tupdesc;
|
||||
ScanKey key;
|
||||
Datum datum;
|
||||
bool isNull;
|
||||
int test;
|
||||
|
||||
*keysok = 0;
|
||||
if (keysz == 0)
|
||||
return (true);
|
||||
|
||||
key = so->keyData;
|
||||
tupdesc = RelationGetTupleDescriptor(scan->relation);
|
||||
|
||||
IncrIndexProcessed();
|
||||
|
||||
while (keysz > 0)
|
||||
{
|
||||
return (false);
|
||||
datum = index_getattr(tuple,
|
||||
key[0].sk_attno,
|
||||
tupdesc,
|
||||
&isNull);
|
||||
|
||||
/* btree doesn't support 'A is null' clauses, yet */
|
||||
if (isNull || key[0].sk_flags & SK_ISNULL)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
if (key[0].sk_flags & SK_COMMUTE)
|
||||
{
|
||||
test = (int) (*(key[0].sk_func))
|
||||
(DatumGetPointer(key[0].sk_argument),
|
||||
datum);
|
||||
}
|
||||
else
|
||||
{
|
||||
test = (int) (*(key[0].sk_func))
|
||||
(datum,
|
||||
DatumGetPointer(key[0].sk_argument));
|
||||
}
|
||||
|
||||
if (!test == !(key[0].sk_flags & SK_NEGATE))
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
keysz -= 1;
|
||||
key++;
|
||||
(*keysok)++;
|
||||
}
|
||||
|
||||
if (key[0].sk_flags & SK_COMMUTE) {
|
||||
test = (int) (*(key[0].sk_func))
|
||||
(DatumGetPointer(key[0].sk_argument),
|
||||
datum);
|
||||
} else {
|
||||
test = (int) (*(key[0].sk_func))
|
||||
(datum,
|
||||
DatumGetPointer(key[0].sk_argument));
|
||||
}
|
||||
|
||||
if (!test == !(key[0].sk_flags & SK_NEGATE)) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
keysz -= 1;
|
||||
key++;
|
||||
(*keysok)++;
|
||||
}
|
||||
|
||||
return (true);
|
||||
return (true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user