Commit b3364fc8 authored by Bruce Momjian's avatar Bruce Momjian

pgindent new GIST index code, per request from Tom.

parent 08817bdb
This diff is collapsed.
This diff is collapsed.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistproc.c,v 1.1 2005/07/01 19:19:02 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistproc.c,v 1.2 2005/09/22 20:44:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -621,8 +621,8 @@ gist_poly_consistent(PG_FUNCTION_ARGS) ...@@ -621,8 +621,8 @@ gist_poly_consistent(PG_FUNCTION_ARGS)
/* /*
* Since the operators are marked lossy anyway, we can just use * Since the operators are marked lossy anyway, we can just use
* rtree_internal_consistent even at leaf nodes. (This works * rtree_internal_consistent even at leaf nodes. (This works in part
* in part because the index entries are bounding boxes not polygons.) * because the index entries are bounding boxes not polygons.)
*/ */
result = rtree_internal_consistent(DatumGetBoxP(entry->key), result = rtree_internal_consistent(DatumGetBoxP(entry->key),
&(query->boundbox), strategy); &(query->boundbox), strategy);
...@@ -693,8 +693,8 @@ gist_circle_consistent(PG_FUNCTION_ARGS) ...@@ -693,8 +693,8 @@ gist_circle_consistent(PG_FUNCTION_ARGS)
/* /*
* Since the operators are marked lossy anyway, we can just use * Since the operators are marked lossy anyway, we can just use
* rtree_internal_consistent even at leaf nodes. (This works * rtree_internal_consistent even at leaf nodes. (This works in part
* in part because the index entries are bounding boxes not circles.) * because the index entries are bounding boxes not circles.)
*/ */
bbox.high.x = query->center.x + query->radius; bbox.high.x = query->center.x + query->radius;
bbox.low.x = query->center.x - query->radius; bbox.low.x = query->center.x - query->radius;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.60 2005/09/22 18:49:45 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.61 2005/09/22 20:44:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -120,11 +120,11 @@ gistrescan(PG_FUNCTION_ARGS) ...@@ -120,11 +120,11 @@ gistrescan(PG_FUNCTION_ARGS)
scan->numberOfKeys * sizeof(ScanKeyData)); scan->numberOfKeys * sizeof(ScanKeyData));
/* /*
* Modify the scan key so that all the Consistent method is * Modify the scan key so that all the Consistent method is called for
* called for all comparisons. The original operator is passed * all comparisons. The original operator is passed to the Consistent
* to the Consistent function in the form of its strategy * function in the form of its strategy number, which is available
* number, which is available from the sk_strategy field, and * from the sk_strategy field, and its subtype from the sk_subtype
* its subtype from the sk_subtype field. * field.
*/ */
for (i = 0; i < scan->numberOfKeys; i++) for (i = 0; i < scan->numberOfKeys; i++)
scan->keyData[i].sk_func = so->giststate->consistentFn[scan->keyData[i].sk_attno - 1]; scan->keyData[i].sk_func = so->giststate->consistentFn[scan->keyData[i].sk_attno - 1];
...@@ -308,9 +308,9 @@ ReleaseResources_gist(void) ...@@ -308,9 +308,9 @@ ReleaseResources_gist(void)
GISTScanList next; GISTScanList next;
/* /*
* Note: this should be a no-op during normal query shutdown. However, * Note: this should be a no-op during normal query shutdown. However, in
* in an abort situation ExecutorEnd is not called and so there may be * an abort situation ExecutorEnd is not called and so there may be open
* open index scans to clean up. * index scans to clean up.
*/ */
prev = NULL; prev = NULL;
...@@ -338,7 +338,7 @@ gistadjscans(Relation rel, int op, BlockNumber blkno, OffsetNumber offnum, XLogR ...@@ -338,7 +338,7 @@ gistadjscans(Relation rel, int op, BlockNumber blkno, OffsetNumber offnum, XLogR
GISTScanList l; GISTScanList l;
Oid relid; Oid relid;
if ( XLogRecPtrIsInvalid(newlsn) || XLogRecPtrIsInvalid(oldlsn) ) if (XLogRecPtrIsInvalid(newlsn) || XLogRecPtrIsInvalid(oldlsn))
return; return;
relid = RelationGetRelid(rel); relid = RelationGetRelid(rel);
...@@ -365,7 +365,7 @@ gistadjone(IndexScanDesc scan, ...@@ -365,7 +365,7 @@ gistadjone(IndexScanDesc scan,
BlockNumber blkno, BlockNumber blkno,
OffsetNumber offnum, XLogRecPtr newlsn, XLogRecPtr oldlsn) OffsetNumber offnum, XLogRecPtr newlsn, XLogRecPtr oldlsn)
{ {
GISTScanOpaque so = (GISTScanOpaque) scan->opaque ; GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
adjustiptr(scan, &(scan->currentItemData), so->stack, op, blkno, offnum, newlsn, oldlsn); adjustiptr(scan, &(scan->currentItemData), so->stack, op, blkno, offnum, newlsn, oldlsn);
adjustiptr(scan, &(scan->currentMarkData), so->markstk, op, blkno, offnum, newlsn, oldlsn); adjustiptr(scan, &(scan->currentMarkData), so->markstk, op, blkno, offnum, newlsn, oldlsn);
...@@ -399,7 +399,8 @@ adjustiptr(IndexScanDesc scan, ...@@ -399,7 +399,8 @@ adjustiptr(IndexScanDesc scan,
{ {
case GISTOP_DEL: case GISTOP_DEL:
/* back up one if we need to */ /* back up one if we need to */
if (curoff >= offnum && XLByteEQ(stk->lsn, oldlsn) ) /* the same vesrion of page */ if (curoff >= offnum && XLByteEQ(stk->lsn, oldlsn)) /* the same vesrion of
* page */
{ {
if (curoff > FirstOffsetNumber) if (curoff > FirstOffsetNumber)
{ {
...@@ -409,8 +410,7 @@ adjustiptr(IndexScanDesc scan, ...@@ -409,8 +410,7 @@ adjustiptr(IndexScanDesc scan,
else else
{ {
/* /*
* remember that we're before the current * remember that we're before the current tuple
* tuple
*/ */
ItemPointerSet(iptr, blkno, FirstOffsetNumber); ItemPointerSet(iptr, blkno, FirstOffsetNumber);
if (iptr == &(scan->currentItemData)) if (iptr == &(scan->currentItemData))
...@@ -435,6 +435,7 @@ gistfreestack(GISTSearchStack *s) ...@@ -435,6 +435,7 @@ gistfreestack(GISTSearchStack *s)
while (s != NULL) while (s != NULL)
{ {
GISTSearchStack *p = s->next; GISTSearchStack *p = s->next;
pfree(s); pfree(s);
s = p; s = p;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.6 2005/09/22 18:49:45 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.7 2005/09/22 20:44:36 momjian Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -47,8 +47,7 @@ ...@@ -47,8 +47,7 @@
} while(0); } while(0);
static void static void gistpenalty(GISTSTATE *giststate, int attno,
gistpenalty(GISTSTATE *giststate, int attno,
GISTENTRY *key1, bool isNull1, GISTENTRY *key1, bool isNull1,
GISTENTRY *key2, bool isNull2, float *penalty); GISTENTRY *key2, bool isNull2, float *penalty);
...@@ -62,8 +61,8 @@ gistfillbuffer(Relation r, Page page, IndexTuple *itup, ...@@ -62,8 +61,8 @@ gistfillbuffer(Relation r, Page page, IndexTuple *itup,
OffsetNumber l = InvalidOffsetNumber; OffsetNumber l = InvalidOffsetNumber;
int i; int i;
if ( off == InvalidOffsetNumber ) if (off == InvalidOffsetNumber)
off = ( PageIsEmpty(page) ) ? FirstOffsetNumber : off = (PageIsEmpty(page)) ? FirstOffsetNumber :
OffsetNumberNext(PageGetMaxOffsetNumber(page)); OffsetNumberNext(PageGetMaxOffsetNumber(page));
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
...@@ -141,9 +140,9 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate) ...@@ -141,9 +140,9 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
evec = (GistEntryVector *) palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + GEVHDRSZ); evec = (GistEntryVector *) palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + GEVHDRSZ);
for(i = 0; i<len; i++) for (i = 0; i < len; i++)
if ( GistTupleIsInvalid( itvec[i] ) ) if (GistTupleIsInvalid(itvec[i]))
return gist_form_invalid_tuple( InvalidBlockNumber ); return gist_form_invalid_tuple(InvalidBlockNumber);
for (i = 0; i < r->rd_att->natts; i++) for (i = 0; i < r->rd_att->natts; i++)
{ {
...@@ -155,6 +154,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate) ...@@ -155,6 +154,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
for (j = 0; j < len; j++) for (j = 0; j < len; j++)
{ {
bool IsNull; bool IsNull;
datum = index_getattr(itvec[j], i + 1, giststate->tupdesc, &IsNull); datum = index_getattr(itvec[j], i + 1, giststate->tupdesc, &IsNull);
if (IsNull) if (IsNull)
continue; continue;
...@@ -202,7 +202,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate) ...@@ -202,7 +202,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
} }
res = index_form_tuple(giststate->tupdesc, attr, isnull); res = index_form_tuple(giststate->tupdesc, attr, isnull);
GistTupleSetValid( res ); GistTupleSetValid(res);
return res; return res;
} }
...@@ -227,8 +227,8 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis ...@@ -227,8 +227,8 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis
IndexTuple newtup = NULL; IndexTuple newtup = NULL;
int i; int i;
if ( GistTupleIsInvalid(oldtup) || GistTupleIsInvalid(addtup) ) if (GistTupleIsInvalid(oldtup) || GistTupleIsInvalid(addtup))
return gist_form_invalid_tuple( ItemPointerGetBlockNumber( &(oldtup->t_tid) ) ); return gist_form_invalid_tuple(ItemPointerGetBlockNumber(&(oldtup->t_tid)));
evec = palloc(2 * sizeof(GISTENTRY) + GEVHDRSZ); evec = palloc(2 * sizeof(GISTENTRY) + GEVHDRSZ);
evec->n = 2; evec->n = 2;
...@@ -402,8 +402,8 @@ gistfindgroup(GISTSTATE *giststate, GISTENTRY *valvec, GIST_SPLITVEC *spl) ...@@ -402,8 +402,8 @@ gistfindgroup(GISTSTATE *giststate, GISTENTRY *valvec, GIST_SPLITVEC *spl)
int curid = 1; int curid = 1;
/* /*
* first key is always not null (see gistinsert), so we may not check * first key is always not null (see gistinsert), so we may not check for
* for nulls * nulls
*/ */
for (i = 0; i < spl->spl_nleft; i++) for (i = 0; i < spl->spl_nleft; i++)
{ {
...@@ -555,8 +555,7 @@ gistadjsubkey(Relation r, ...@@ -555,8 +555,7 @@ gistadjsubkey(Relation r,
} }
/* /*
* add * add XXX: refactor this to avoid duplicating code
* XXX: refactor this to avoid duplicating code
*/ */
if (lpenalty < rpenalty) if (lpenalty < rpenalty)
{ {
...@@ -644,7 +643,8 @@ gistchoose(Relation r, Page p, IndexTuple it, /* it has compressed entry */ ...@@ -644,7 +643,8 @@ gistchoose(Relation r, Page p, IndexTuple it, /* it has compressed entry */
int j; int j;
IndexTuple itup = (IndexTuple) PageGetItem(p, PageGetItemId(p, i)); IndexTuple itup = (IndexTuple) PageGetItem(p, PageGetItemId(p, i));
if ( !GistPageIsLeaf(p) && GistTupleIsInvalid(itup) ) { if (!GistPageIsLeaf(p) && GistTupleIsInvalid(itup))
{
ereport(LOG, ereport(LOG,
(errmsg("index \"%s\" needs VACUUM or REINDEX to finish crash recovery", (errmsg("index \"%s\" needs VACUUM or REINDEX to finish crash recovery",
RelationGetRelationName(r)))); RelationGetRelationName(r))));
...@@ -683,7 +683,7 @@ gistchoose(Relation r, Page p, IndexTuple it, /* it has compressed entry */ ...@@ -683,7 +683,7 @@ gistchoose(Relation r, Page p, IndexTuple it, /* it has compressed entry */
} }
} }
if ( which == InvalidOffsetNumber ) if (which == InvalidOffsetNumber)
which = FirstOffsetNumber; which = FirstOffsetNumber;
return which; return which;
...@@ -776,6 +776,7 @@ gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p, ...@@ -776,6 +776,7 @@ gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p,
for (i = 0; i < r->rd_att->natts; i++) for (i = 0; i < r->rd_att->natts; i++)
{ {
Datum datum = index_getattr(tuple, i + 1, giststate->tupdesc, &isnull[i]); Datum datum = index_getattr(tuple, i + 1, giststate->tupdesc, &isnull[i]);
gistdentryinit(giststate, i, &attdata[i], gistdentryinit(giststate, i, &attdata[i],
datum, r, p, o, datum, r, p, o,
ATTSIZE(datum, giststate->tupdesc, i + 1, isnull[i]), ATTSIZE(datum, giststate->tupdesc, i + 1, isnull[i]),
...@@ -811,15 +812,16 @@ GISTInitBuffer(Buffer b, uint32 f) ...@@ -811,15 +812,16 @@ GISTInitBuffer(Buffer b, uint32 f)
opaque = GistPageGetOpaque(page); opaque = GistPageGetOpaque(page);
opaque->flags = f; opaque->flags = f;
opaque->rightlink = InvalidBlockNumber; opaque->rightlink = InvalidBlockNumber;
memset( &(opaque->nsn), 0, sizeof(GistNSN) ); memset(&(opaque->nsn), 0, sizeof(GistNSN));
} }
void void
gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v, gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v,
IndexTuple *itup, int len, GISTSTATE *giststate) { IndexTuple *itup, int len, GISTSTATE *giststate)
{
/* /*
* now let the user-defined picksplit function set up the split * now let the user-defined picksplit function set up the split vector; in
* vector; in entryvec have no null value!! * entryvec have no null value!!
*/ */
FunctionCall2(&giststate->picksplitFn[0], FunctionCall2(&giststate->picksplitFn[0],
PointerGetDatum(entryvec), PointerGetDatum(entryvec),
...@@ -837,8 +839,8 @@ gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v, ...@@ -837,8 +839,8 @@ gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v,
v->spl_risnull[0] = false; v->spl_risnull[0] = false;
/* /*
* if index is multikey, then we must to try get smaller bounding box * if index is multikey, then we must to try get smaller bounding box for
* for subkey(s) * subkey(s)
*/ */
if (r->rd_att->natts > 1) if (r->rd_att->natts > 1)
{ {
...@@ -854,8 +856,8 @@ gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v, ...@@ -854,8 +856,8 @@ gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v,
gistunionsubkey(r, giststate, itup, v, false); gistunionsubkey(r, giststate, itup, v, false);
/* /*
* if possible, we insert equivalent tuples with control by * if possible, we insert equivalent tuples with control by penalty
* penalty for a subkey(s) * for a subkey(s)
*/ */
if (MaxGrpId > 1) if (MaxGrpId > 1)
gistadjsubkey(r, itup, len, v, giststate); gistadjsubkey(r, itup, len, v, giststate);
...@@ -863,26 +865,33 @@ gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v, ...@@ -863,26 +865,33 @@ gistUserPicksplit(Relation r, GistEntryVector *entryvec, GIST_SPLITVEC *v,
} }
Buffer Buffer
gistNewBuffer(Relation r) { gistNewBuffer(Relation r)
{
Buffer buffer = InvalidBuffer; Buffer buffer = InvalidBuffer;
bool needLock; bool needLock;
while(true) { while (true)
{
BlockNumber blkno = GetFreeIndexPage(&r->rd_node); BlockNumber blkno = GetFreeIndexPage(&r->rd_node);
if (blkno == InvalidBlockNumber) if (blkno == InvalidBlockNumber)
break; break;
buffer = ReadBuffer(r, blkno); buffer = ReadBuffer(r, blkno);
if ( ConditionalLockBuffer(buffer) ) { if (ConditionalLockBuffer(buffer))
{
Page page = BufferGetPage(buffer); Page page = BufferGetPage(buffer);
if ( GistPageIsDeleted( page ) ) {
GistPageSetNonDeleted( page ); if (GistPageIsDeleted(page))
{
GistPageSetNonDeleted(page);
return buffer; return buffer;
} else }
else
LockBuffer(buffer, GIST_UNLOCK); LockBuffer(buffer, GIST_UNLOCK);
} }
ReleaseBuffer( buffer ); ReleaseBuffer(buffer);
} }
needLock = !RELATION_IS_LOCAL(r); needLock = !RELATION_IS_LOCAL(r);
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment