mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
pgindent run for 8.2.
This commit is contained in:
@ -154,17 +154,17 @@ typedef struct
|
||||
#define COMPUTESIZE(size) ( HDRSIZEQT + size * sizeof(ITEM) )
|
||||
#define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT )
|
||||
|
||||
#define END 0
|
||||
#define ERR 1
|
||||
#define VAL 2
|
||||
#define OPR 3
|
||||
#define OPEN 4
|
||||
#define CLOSE 5
|
||||
#define END 0
|
||||
#define ERR 1
|
||||
#define VAL 2
|
||||
#define OPR 3
|
||||
#define OPEN 4
|
||||
#define CLOSE 5
|
||||
|
||||
bool signconsistent(QUERYTYPE * query, BITVEC sign, bool calcnot);
|
||||
bool execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot);
|
||||
bool ginconsistent(QUERYTYPE * query, bool *check);
|
||||
int4 shorterquery(ITEM * q, int4 len);
|
||||
bool ginconsistent(QUERYTYPE * query, bool *check);
|
||||
int4 shorterquery(ITEM * q, int4 len);
|
||||
|
||||
int compASC(const void *a, const void *b);
|
||||
|
||||
|
@ -232,7 +232,7 @@ typedef struct
|
||||
* is there value 'val' in array or not ?
|
||||
*/
|
||||
static bool
|
||||
checkcondition_arr(void *checkval, ITEM *item)
|
||||
checkcondition_arr(void *checkval, ITEM * item)
|
||||
{
|
||||
int4 *StopLow = ((CHKVAL *) checkval)->arrb;
|
||||
int4 *StopHigh = ((CHKVAL *) checkval)->arre;
|
||||
@ -254,7 +254,7 @@ checkcondition_arr(void *checkval, ITEM *item)
|
||||
}
|
||||
|
||||
static bool
|
||||
checkcondition_bit(void *checkval, ITEM *item)
|
||||
checkcondition_bit(void *checkval, ITEM * item)
|
||||
{
|
||||
return GETBIT(checkval, HASHVAL(item->val));
|
||||
}
|
||||
@ -263,7 +263,7 @@ checkcondition_bit(void *checkval, ITEM *item)
|
||||
* check for boolean condition
|
||||
*/
|
||||
static bool
|
||||
execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *item))
|
||||
execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM * item))
|
||||
{
|
||||
|
||||
if (curitem->type == VAL)
|
||||
@ -319,38 +319,42 @@ execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot)
|
||||
);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ITEM *first;
|
||||
bool *mapped_check;
|
||||
} GinChkVal;
|
||||
typedef struct
|
||||
{
|
||||
ITEM *first;
|
||||
bool *mapped_check;
|
||||
} GinChkVal;
|
||||
|
||||
static bool
|
||||
checkcondition_gin(void *checkval, ITEM *item) {
|
||||
GinChkVal *gcv = (GinChkVal*)checkval;
|
||||
checkcondition_gin(void *checkval, ITEM * item)
|
||||
{
|
||||
GinChkVal *gcv = (GinChkVal *) checkval;
|
||||
|
||||
return gcv->mapped_check[ item - gcv->first ];
|
||||
return gcv->mapped_check[item - gcv->first];
|
||||
}
|
||||
|
||||
bool
|
||||
ginconsistent(QUERYTYPE * query, bool *check) {
|
||||
GinChkVal gcv;
|
||||
ITEM *items = GETQUERY(query);
|
||||
int i, j=0;
|
||||
ginconsistent(QUERYTYPE * query, bool *check)
|
||||
{
|
||||
GinChkVal gcv;
|
||||
ITEM *items = GETQUERY(query);
|
||||
int i,
|
||||
j = 0;
|
||||
|
||||
if ( query->size < 0 )
|
||||
if (query->size < 0)
|
||||
return FALSE;
|
||||
|
||||
gcv.first = items;
|
||||
gcv.mapped_check = (bool*)palloc( sizeof(bool)*query->size );
|
||||
for(i=0; i<query->size; i++)
|
||||
if ( items[i].type == VAL )
|
||||
gcv.mapped_check[ i ] = check[ j++ ];
|
||||
gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
|
||||
for (i = 0; i < query->size; i++)
|
||||
if (items[i].type == VAL)
|
||||
gcv.mapped_check[i] = check[j++];
|
||||
|
||||
return execute(
|
||||
GETQUERY(query) + query->size - 1,
|
||||
(void *) &gcv, true,
|
||||
checkcondition_gin
|
||||
);
|
||||
return execute(
|
||||
GETQUERY(query) + query->size - 1,
|
||||
(void *) &gcv, true,
|
||||
checkcondition_gin
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,102 +1,118 @@
|
||||
#include "_int.h"
|
||||
|
||||
PG_FUNCTION_INFO_V1(ginint4_queryextract);
|
||||
Datum ginint4_queryextract(PG_FUNCTION_ARGS);
|
||||
Datum ginint4_queryextract(PG_FUNCTION_ARGS);
|
||||
|
||||
Datum
|
||||
ginint4_queryextract(PG_FUNCTION_ARGS) {
|
||||
uint32 *nentries = (uint32*)PG_GETARG_POINTER(1);
|
||||
StrategyNumber strategy = PG_GETARG_UINT16(2);
|
||||
Datum *res = NULL;
|
||||
|
||||
ginint4_queryextract(PG_FUNCTION_ARGS)
|
||||
{
|
||||
uint32 *nentries = (uint32 *) PG_GETARG_POINTER(1);
|
||||
StrategyNumber strategy = PG_GETARG_UINT16(2);
|
||||
Datum *res = NULL;
|
||||
|
||||
*nentries = 0;
|
||||
|
||||
if ( strategy == BooleanSearchStrategy ) {
|
||||
QUERYTYPE *query = (QUERYTYPE*)PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0));
|
||||
ITEM *items = GETQUERY(query);
|
||||
int i;
|
||||
if (strategy == BooleanSearchStrategy)
|
||||
{
|
||||
QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0));
|
||||
ITEM *items = GETQUERY(query);
|
||||
int i;
|
||||
|
||||
if (query->size == 0)
|
||||
PG_RETURN_POINTER(NULL);
|
||||
|
||||
if ( shorterquery(items, query->size) == 0 )
|
||||
elog(ERROR,"Query requires full scan, GIN doesn't support it");
|
||||
if (shorterquery(items, query->size) == 0)
|
||||
elog(ERROR, "Query requires full scan, GIN doesn't support it");
|
||||
|
||||
pfree( query );
|
||||
pfree(query);
|
||||
|
||||
query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
|
||||
query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
|
||||
items = GETQUERY(query);
|
||||
|
||||
res = (Datum*)palloc(sizeof(Datum) * query->size);
|
||||
res = (Datum *) palloc(sizeof(Datum) * query->size);
|
||||
*nentries = 0;
|
||||
|
||||
for(i=0;i<query->size;i++)
|
||||
if ( items[i].type == VAL ) {
|
||||
res[*nentries] = Int32GetDatum( items[i].val );
|
||||
for (i = 0; i < query->size; i++)
|
||||
if (items[i].type == VAL)
|
||||
{
|
||||
res[*nentries] = Int32GetDatum(items[i].val);
|
||||
(*nentries)++;
|
||||
}
|
||||
} else {
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
|
||||
int4 *arr;
|
||||
uint32 i;
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
|
||||
int4 *arr;
|
||||
uint32 i;
|
||||
|
||||
CHECKARRVALID(query);
|
||||
*nentries=ARRNELEMS(query);
|
||||
if ( *nentries > 0 ) {
|
||||
res = (Datum*)palloc(sizeof(Datum) * (*nentries));
|
||||
*nentries = ARRNELEMS(query);
|
||||
if (*nentries > 0)
|
||||
{
|
||||
res = (Datum *) palloc(sizeof(Datum) * (*nentries));
|
||||
|
||||
arr=ARRPTR(query);
|
||||
for(i=0;i<*nentries;i++)
|
||||
res[i] = Int32GetDatum( arr[i] );
|
||||
arr = ARRPTR(query);
|
||||
for (i = 0; i < *nentries; i++)
|
||||
res[i] = Int32GetDatum(arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
PG_RETURN_POINTER( res );
|
||||
PG_RETURN_POINTER(res);
|
||||
}
|
||||
|
||||
PG_FUNCTION_INFO_V1(ginint4_consistent);
|
||||
Datum ginint4_consistent(PG_FUNCTION_ARGS);
|
||||
Datum ginint4_consistent(PG_FUNCTION_ARGS);
|
||||
|
||||
Datum
|
||||
ginint4_consistent(PG_FUNCTION_ARGS) {
|
||||
bool *check = (bool*)PG_GETARG_POINTER(0);
|
||||
StrategyNumber strategy = PG_GETARG_UINT16(1);
|
||||
int res=FALSE;
|
||||
ginint4_consistent(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bool *check = (bool *) PG_GETARG_POINTER(0);
|
||||
StrategyNumber strategy = PG_GETARG_UINT16(1);
|
||||
int res = FALSE;
|
||||
|
||||
/* we can do not check array carefully, it's done by previous ginarrayextract call */
|
||||
/*
|
||||
* we can do not check array carefully, it's done by previous
|
||||
* ginarrayextract call
|
||||
*/
|
||||
|
||||
switch( strategy ) {
|
||||
case RTOverlapStrategyNumber:
|
||||
case RTContainedByStrategyNumber:
|
||||
case RTOldContainedByStrategyNumber:
|
||||
/* at least one element in check[] is true, so result = true */
|
||||
switch (strategy)
|
||||
{
|
||||
case RTOverlapStrategyNumber:
|
||||
case RTContainedByStrategyNumber:
|
||||
case RTOldContainedByStrategyNumber:
|
||||
/* at least one element in check[] is true, so result = true */
|
||||
|
||||
res = TRUE;
|
||||
break;
|
||||
case RTSameStrategyNumber:
|
||||
case RTContainsStrategyNumber:
|
||||
case RTOldContainsStrategyNumber:
|
||||
res = TRUE;
|
||||
do {
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(2);
|
||||
int i, nentries=ARRNELEMS(query);
|
||||
|
||||
for(i=0;i<nentries;i++)
|
||||
if ( !check[i] ) {
|
||||
res = FALSE;
|
||||
break;
|
||||
}
|
||||
} while(0);
|
||||
break;
|
||||
case BooleanSearchStrategy:
|
||||
do {
|
||||
QUERYTYPE *query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
|
||||
res = ginconsistent( query, check );
|
||||
} while(0);
|
||||
res = TRUE;
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "ginint4_consistent: unknown strategy number: %d", strategy);
|
||||
}
|
||||
case RTSameStrategyNumber:
|
||||
case RTContainsStrategyNumber:
|
||||
case RTOldContainsStrategyNumber:
|
||||
res = TRUE;
|
||||
do
|
||||
{
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(2);
|
||||
int i,
|
||||
nentries = ARRNELEMS(query);
|
||||
|
||||
PG_RETURN_BOOL(res);
|
||||
for (i = 0; i < nentries; i++)
|
||||
if (!check[i])
|
||||
{
|
||||
res = FALSE;
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
break;
|
||||
case BooleanSearchStrategy:
|
||||
do
|
||||
{
|
||||
QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
|
||||
|
||||
res = ginconsistent(query, check);
|
||||
} while (0);
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "ginint4_consistent: unknown strategy number: %d", strategy);
|
||||
}
|
||||
|
||||
PG_RETURN_BOOL(res);
|
||||
}
|
||||
|
@ -36,19 +36,21 @@ g_int_consistent(PG_FUNCTION_ARGS)
|
||||
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
|
||||
bool retval;
|
||||
|
||||
if (strategy == BooleanSearchStrategy) {
|
||||
if (strategy == BooleanSearchStrategy)
|
||||
{
|
||||
retval = execconsistent((QUERYTYPE *) query,
|
||||
(ArrayType *) DatumGetPointer(entry->key),
|
||||
GIST_LEAF(entry));
|
||||
(ArrayType *) DatumGetPointer(entry->key),
|
||||
GIST_LEAF(entry));
|
||||
|
||||
pfree( query );
|
||||
pfree(query);
|
||||
PG_RETURN_BOOL(retval);
|
||||
}
|
||||
|
||||
/* sort query for fast search, key is already sorted */
|
||||
CHECKARRVALID(query);
|
||||
if (ARRISVOID(query)) {
|
||||
pfree( query );
|
||||
if (ARRISVOID(query))
|
||||
{
|
||||
pfree(query);
|
||||
PG_RETURN_BOOL(false);
|
||||
}
|
||||
PREPAREARR(query);
|
||||
@ -88,7 +90,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
|
||||
default:
|
||||
retval = FALSE;
|
||||
}
|
||||
pfree( query );
|
||||
pfree(query);
|
||||
PG_RETURN_BOOL(retval);
|
||||
}
|
||||
|
||||
@ -156,7 +158,7 @@ g_int_compress(PG_FUNCTION_ARGS)
|
||||
|
||||
retval = palloc(sizeof(GISTENTRY));
|
||||
gistentryinit(*retval, PointerGetDatum(r),
|
||||
entry->rel, entry->page, entry->offset, FALSE);
|
||||
entry->rel, entry->page, entry->offset, FALSE);
|
||||
|
||||
PG_RETURN_POINTER(retval);
|
||||
}
|
||||
@ -203,7 +205,7 @@ g_int_compress(PG_FUNCTION_ARGS)
|
||||
r = resize_intArrayType(r, len);
|
||||
retval = palloc(sizeof(GISTENTRY));
|
||||
gistentryinit(*retval, PointerGetDatum(r),
|
||||
entry->rel, entry->page, entry->offset, FALSE);
|
||||
entry->rel, entry->page, entry->offset, FALSE);
|
||||
PG_RETURN_POINTER(retval);
|
||||
}
|
||||
else
|
||||
@ -240,7 +242,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
retval = palloc(sizeof(GISTENTRY));
|
||||
gistentryinit(*retval, PointerGetDatum(in),
|
||||
entry->rel, entry->page, entry->offset, FALSE);
|
||||
entry->rel, entry->page, entry->offset, FALSE);
|
||||
|
||||
PG_RETURN_POINTER(retval);
|
||||
}
|
||||
@ -331,7 +333,7 @@ typedef struct
|
||||
{
|
||||
OffsetNumber pos;
|
||||
float cost;
|
||||
} SPLITCOST;
|
||||
} SPLITCOST;
|
||||
|
||||
static int
|
||||
comparecost(const void *a, const void *b)
|
||||
|
@ -89,22 +89,27 @@ inner_int_union(ArrayType *a, ArrayType *b)
|
||||
|
||||
if (!r)
|
||||
{
|
||||
int na = ARRNELEMS(a),
|
||||
nb = ARRNELEMS(b);
|
||||
int *da = ARRPTR(a),
|
||||
*db = ARRPTR(b);
|
||||
int i,j, *dr;
|
||||
int na = ARRNELEMS(a),
|
||||
nb = ARRNELEMS(b);
|
||||
int *da = ARRPTR(a),
|
||||
*db = ARRPTR(b);
|
||||
int i,
|
||||
j,
|
||||
*dr;
|
||||
|
||||
r = new_intArrayType(na + nb);
|
||||
dr = ARRPTR(r);
|
||||
|
||||
/* union */
|
||||
i = j = 0;
|
||||
while (i < na && j < nb) {
|
||||
if (da[i] == db[j]) {
|
||||
while (i < na && j < nb)
|
||||
{
|
||||
if (da[i] == db[j])
|
||||
{
|
||||
*dr++ = da[i++];
|
||||
j++;
|
||||
} else if (da[i] < db[j])
|
||||
}
|
||||
else if (da[i] < db[j])
|
||||
*dr++ = da[i++];
|
||||
else
|
||||
*dr++ = db[j++];
|
||||
@ -115,7 +120,7 @@ inner_int_union(ArrayType *a, ArrayType *b)
|
||||
while (j < nb)
|
||||
*dr++ = db[j++];
|
||||
|
||||
r = resize_intArrayType(r, dr-ARRPTR(r));
|
||||
r = resize_intArrayType(r, dr - ARRPTR(r));
|
||||
}
|
||||
|
||||
if (ARRNELEMS(r) > 1)
|
||||
|
@ -214,7 +214,7 @@ sizebitvec(BITVECP sign)
|
||||
i;
|
||||
|
||||
LOOPBYTE(
|
||||
size += number_of_ones[(unsigned char) sign[i]];
|
||||
size += number_of_ones[(unsigned char) sign[i]];
|
||||
);
|
||||
return size;
|
||||
}
|
||||
@ -227,8 +227,8 @@ hemdistsign(BITVECP a, BITVECP b)
|
||||
dist = 0;
|
||||
|
||||
LOOPBYTE(
|
||||
diff = (unsigned char) (a[i] ^ b[i]);
|
||||
dist += number_of_ones[diff];
|
||||
diff = (unsigned char) (a[i] ^ b[i]);
|
||||
dist += number_of_ones[diff];
|
||||
);
|
||||
return dist;
|
||||
}
|
||||
@ -318,7 +318,7 @@ typedef struct
|
||||
{
|
||||
OffsetNumber pos;
|
||||
int4 cost;
|
||||
} SPLITCOST;
|
||||
} SPLITCOST;
|
||||
|
||||
static int
|
||||
comparecost(const void *a, const void *b)
|
||||
@ -506,16 +506,17 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
|
||||
|
||||
if (strategy == BooleanSearchStrategy)
|
||||
{
|
||||
retval =signconsistent((QUERYTYPE *) query,
|
||||
GETSIGN(DatumGetPointer(entry->key)),
|
||||
false);
|
||||
PG_FREE_IF_COPY( query, 1 );
|
||||
retval = signconsistent((QUERYTYPE *) query,
|
||||
GETSIGN(DatumGetPointer(entry->key)),
|
||||
false);
|
||||
PG_FREE_IF_COPY(query, 1);
|
||||
PG_RETURN_BOOL(retval);
|
||||
}
|
||||
|
||||
CHECKARRVALID(query);
|
||||
if (ARRISVOID(query)) {
|
||||
PG_FREE_IF_COPY( query, 1 );
|
||||
if (ARRISVOID(query))
|
||||
{
|
||||
PG_FREE_IF_COPY(query, 1);
|
||||
PG_RETURN_BOOL(FALSE);
|
||||
}
|
||||
|
||||
@ -602,6 +603,6 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
|
||||
default:
|
||||
retval = FALSE;
|
||||
}
|
||||
PG_FREE_IF_COPY( query, 1 );
|
||||
PG_FREE_IF_COPY(query, 1);
|
||||
PG_RETURN_BOOL(retval);
|
||||
}
|
||||
|
Reference in New Issue
Block a user