aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gin/ginutil.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2006-10-04 00:30:14 +0000
committerBruce Momjian <bruce@momjian.us>2006-10-04 00:30:14 +0000
commitf99a569a2ee3763b4ae174e81250c95ca0fdcbb6 (patch)
tree76e6371fe8b347c73d7020c0bc54b9fba519dc10 /src/backend/access/gin/ginutil.c
parent451e419e9852cdf9d7e7cefc09d5355abb3405e9 (diff)
downloadpostgresql-f99a569a2ee3763b4ae174e81250c95ca0fdcbb6.tar.gz
postgresql-f99a569a2ee3763b4ae174e81250c95ca0fdcbb6.zip
pgindent run for 8.2.
Diffstat (limited to 'src/backend/access/gin/ginutil.c')
-rw-r--r--src/backend/access/gin/ginutil.c160
1 files changed, 88 insertions, 72 deletions
diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c
index 17eca3d239f..e64137a1062 100644
--- a/src/backend/access/gin/ginutil.c
+++ b/src/backend/access/gin/ginutil.c
@@ -1,14 +1,14 @@
/*-------------------------------------------------------------------------
*
* ginutil.c
- * utilities routines for the postgres inverted index access method.
+ * utilities routines for the postgres inverted index access method.
*
*
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.6 2006/09/05 18:25:10 teodor Exp $
+ * $PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.7 2006/10/04 00:29:48 momjian Exp $
*-------------------------------------------------------------------------
*/
@@ -19,26 +19,27 @@
#include "access/reloptions.h"
#include "storage/freespace.h"
-void
-initGinState( GinState *state, Relation index ) {
- if ( index->rd_att->natts != 1 )
- elog(ERROR, "numberOfAttributes %d != 1",
- index->rd_att->natts);
-
+void
+initGinState(GinState *state, Relation index)
+{
+ if (index->rd_att->natts != 1)
+ elog(ERROR, "numberOfAttributes %d != 1",
+ index->rd_att->natts);
+
state->tupdesc = index->rd_att;
fmgr_info_copy(&(state->compareFn),
- index_getprocinfo(index, 1, GIN_COMPARE_PROC),
- CurrentMemoryContext);
+ index_getprocinfo(index, 1, GIN_COMPARE_PROC),
+ CurrentMemoryContext);
fmgr_info_copy(&(state->extractValueFn),
- index_getprocinfo(index, 1, GIN_EXTRACTVALUE_PROC),
- CurrentMemoryContext);
+ index_getprocinfo(index, 1, GIN_EXTRACTVALUE_PROC),
+ CurrentMemoryContext);
fmgr_info_copy(&(state->extractQueryFn),
- index_getprocinfo(index, 1, GIN_EXTRACTQUERY_PROC),
- CurrentMemoryContext);
+ index_getprocinfo(index, 1, GIN_EXTRACTQUERY_PROC),
+ CurrentMemoryContext);
fmgr_info_copy(&(state->consistentFn),
- index_getprocinfo(index, 1, GIN_CONSISTENT_PROC),
- CurrentMemoryContext);
+ index_getprocinfo(index, 1, GIN_CONSISTENT_PROC),
+ CurrentMemoryContext);
}
/*
@@ -48,13 +49,16 @@ initGinState( GinState *state, Relation index ) {
*/
Buffer
-GinNewBuffer(Relation index) {
- Buffer buffer;
- bool needLock;
+GinNewBuffer(Relation index)
+{
+ Buffer buffer;
+ bool needLock;
/* First, try to get a page from FSM */
- for(;;) {
+ for (;;)
+ {
BlockNumber blkno = GetFreeIndexPage(&index->rd_node);
+
if (blkno == InvalidBlockNumber)
break;
@@ -64,14 +68,15 @@ GinNewBuffer(Relation index) {
* We have to guard against the possibility that someone else already
* recycled this page; the buffer may be locked if so.
*/
- if (ConditionalLockBuffer(buffer)) {
- Page page = BufferGetPage(buffer);
+ if (ConditionalLockBuffer(buffer))
+ {
+ Page page = BufferGetPage(buffer);
if (PageIsNew(page))
- return buffer; /* OK to use, if never initialized */
+ return buffer; /* OK to use, if never initialized */
if (GinPageIsDeleted(page))
- return buffer; /* OK to use */
+ return buffer; /* OK to use */
LockBuffer(buffer, GIN_UNLOCK);
}
@@ -95,36 +100,39 @@ GinNewBuffer(Relation index) {
}
void
-GinInitPage(Page page, uint32 f, Size pageSize) {
+GinInitPage(Page page, uint32 f, Size pageSize)
+{
GinPageOpaque opaque;
PageInit(page, pageSize, sizeof(GinPageOpaqueData));
opaque = GinPageGetOpaque(page);
- memset( opaque, 0, sizeof(GinPageOpaqueData) );
- opaque->flags = f;
+ memset(opaque, 0, sizeof(GinPageOpaqueData));
+ opaque->flags = f;
opaque->rightlink = InvalidBlockNumber;
}
void
-GinInitBuffer(Buffer b, uint32 f) {
- GinInitPage( BufferGetPage(b), f, BufferGetPageSize(b) );
+GinInitBuffer(Buffer b, uint32 f)
+{
+ GinInitPage(BufferGetPage(b), f, BufferGetPageSize(b));
}
int
-compareEntries(GinState *ginstate, Datum a, Datum b) {
+compareEntries(GinState *ginstate, Datum a, Datum b)
+{
return DatumGetInt32(
- FunctionCall2(
- &ginstate->compareFn,
- a, b
- )
+ FunctionCall2(
+ &ginstate->compareFn,
+ a, b
+ )
);
}
-static FmgrInfo* cmpDatumPtr=NULL;
+static FmgrInfo *cmpDatumPtr = NULL;
-#if defined(__INTEL_COMPILER) && (defined(__ia64__) || defined(__ia64))
-/*
+#if defined(__INTEL_COMPILER) && (defined(__ia64__) || defined(__ia64))
+/*
* Intel Compiler on Intel Itanium with -O2 has a bug around
* change static variable by user function called from
* libc func: it doesn't change. So mark it as volatile.
@@ -132,7 +140,7 @@ static FmgrInfo* cmpDatumPtr=NULL;
* It's a pity, but it's impossible to define optimization
* level here.
*/
-#define VOLATILE volatile
+#define VOLATILE volatile
#else
#define VOLATILE
#endif
@@ -140,57 +148,64 @@ static FmgrInfo* cmpDatumPtr=NULL;
static bool VOLATILE needUnique = FALSE;
static int
-cmpEntries(const void * a, const void * b) {
- int res = DatumGetInt32(
- FunctionCall2(
- cmpDatumPtr,
- *(Datum*)a,
- *(Datum*)b
- )
+cmpEntries(const void *a, const void *b)
+{
+ int res = DatumGetInt32(
+ FunctionCall2(
+ cmpDatumPtr,
+ *(Datum *) a,
+ *(Datum *) b
+ )
);
- if ( res == 0 )
+ if (res == 0)
needUnique = TRUE;
return res;
}
-Datum*
-extractEntriesS(GinState *ginstate, Datum value, uint32 *nentries) {
- Datum *entries;
+Datum *
+extractEntriesS(GinState *ginstate, Datum value, uint32 *nentries)
+{
+ Datum *entries;
- entries = (Datum*)DatumGetPointer(
- FunctionCall2(
- &ginstate->extractValueFn,
- value,
- PointerGetDatum( nentries )
- )
- );
+ entries = (Datum *) DatumGetPointer(
+ FunctionCall2(
+ &ginstate->extractValueFn,
+ value,
+ PointerGetDatum(nentries)
+ )
+ );
- if ( entries == NULL )
+ if (entries == NULL)
*nentries = 0;
- if ( *nentries > 1 ) {
+ if (*nentries > 1)
+ {
cmpDatumPtr = &ginstate->compareFn;
needUnique = FALSE;
- qsort(entries, *nentries, sizeof(Datum), cmpEntries);
+ qsort(entries, *nentries, sizeof(Datum), cmpEntries);
}
return entries;
}
-Datum*
-extractEntriesSU(GinState *ginstate, Datum value, uint32 *nentries) {
- Datum *entries = extractEntriesS(ginstate, value, nentries);
+Datum *
+extractEntriesSU(GinState *ginstate, Datum value, uint32 *nentries)
+{
+ Datum *entries = extractEntriesS(ginstate, value, nentries);
- if ( *nentries>1 && needUnique ) {
- Datum *ptr, *res;
+ if (*nentries > 1 && needUnique)
+ {
+ Datum *ptr,
+ *res;
ptr = res = entries;
- while( ptr - entries < *nentries ) {
- if ( compareEntries(ginstate, *ptr, *res ) != 0 )
+ while (ptr - entries < *nentries)
+ {
+ if (compareEntries(ginstate, *ptr, *res) != 0)
*(++res) = *ptr++;
else
ptr++;
@@ -206,13 +221,14 @@ extractEntriesSU(GinState *ginstate, Datum value, uint32 *nentries) {
* It's analog of PageGetTempPage(), but copies whole page
*/
Page
-GinPageGetCopyPage( Page page ) {
- Size pageSize = PageGetPageSize( page );
- Page tmppage;
+GinPageGetCopyPage(Page page)
+{
+ Size pageSize = PageGetPageSize(page);
+ Page tmppage;
+
+ tmppage = (Page) palloc(pageSize);
+ memcpy(tmppage, page, pageSize);
- tmppage=(Page)palloc( pageSize );
- memcpy( tmppage, page, pageSize );
-
return tmppage;
}