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