mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
pgindent run for 9.0
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.9 2009/09/30 19:50:22 tgl Exp $
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.10 2010/02/26 02:00:32 momjian Exp $
|
||||
*/
|
||||
#ifndef __HSTORE_H__
|
||||
#define __HSTORE_H__
|
||||
@ -12,7 +12,7 @@
|
||||
* HEntry: there is one of these for each key _and_ value in an hstore
|
||||
*
|
||||
* the position offset points to the _end_ so that we can get the length
|
||||
* by subtraction from the previous entry. the ISFIRST flag lets us tell
|
||||
* by subtraction from the previous entry. the ISFIRST flag lets us tell
|
||||
* whether there is a previous entry.
|
||||
*/
|
||||
typedef struct
|
||||
@ -51,7 +51,7 @@ typedef struct
|
||||
/*
|
||||
* it's not possible to get more than 2^28 items into an hstore,
|
||||
* so we reserve the top few bits of the size field. See hstore_compat.c
|
||||
* for one reason why. Some bits are left for future use here.
|
||||
* for one reason why. Some bits are left for future use here.
|
||||
*/
|
||||
#define HS_FLAG_NEWVERSION 0x80000000
|
||||
|
||||
@ -88,7 +88,7 @@ typedef struct
|
||||
* evaluation here.
|
||||
*/
|
||||
#define HS_COPYITEM(dent_,dbuf_,dptr_,sptr_,klen_,vlen_,vnull_) \
|
||||
do { \
|
||||
do { \
|
||||
memcpy((dptr_), (sptr_), (klen_)+(vlen_)); \
|
||||
(dptr_) += (klen_)+(vlen_); \
|
||||
(dent_)++->entry = ((dptr_) - (dbuf_) - (vlen_)) & HENTRY_POSMASK; \
|
||||
@ -119,7 +119,7 @@ typedef struct
|
||||
/* finalize a newly-constructed hstore */
|
||||
#define HS_FINALIZE(hsp_,count_,buf_,ptr_) \
|
||||
do { \
|
||||
int buflen = (ptr_) - (buf_); \
|
||||
int buflen = (ptr_) - (buf_); \
|
||||
if ((count_)) \
|
||||
ARRPTR(hsp_)[0].entry |= HENTRY_ISFIRST; \
|
||||
if ((count_) != HS_COUNT((hsp_))) \
|
||||
@ -133,7 +133,7 @@ typedef struct
|
||||
/* ensure the varlena size of an existing hstore is correct */
|
||||
#define HS_FIXSIZE(hsp_,count_) \
|
||||
do { \
|
||||
int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \
|
||||
int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \
|
||||
SET_VARSIZE((hsp_), CALCDATASIZE((count_),bl)); \
|
||||
} while (0)
|
||||
|
||||
@ -172,7 +172,7 @@ extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs);
|
||||
#define HStoreExistsStrategyNumber 9
|
||||
#define HStoreExistsAnyStrategyNumber 10
|
||||
#define HStoreExistsAllStrategyNumber 11
|
||||
#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */
|
||||
#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */
|
||||
|
||||
/*
|
||||
* defining HSTORE_POLLUTE_NAMESPACE=0 will prevent use of old function names;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.1 2009/09/30 19:50:22 tgl Exp $
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.2 2010/02/26 02:00:32 momjian Exp $
|
||||
*
|
||||
* Notes on old/new hstore format disambiguation.
|
||||
*
|
||||
@ -106,24 +106,24 @@ typedef struct
|
||||
pos:31;
|
||||
} HOldEntry;
|
||||
|
||||
static int hstoreValidNewFormat(HStore *hs);
|
||||
static int hstoreValidOldFormat(HStore *hs);
|
||||
static int hstoreValidNewFormat(HStore *hs);
|
||||
static int hstoreValidOldFormat(HStore *hs);
|
||||
|
||||
|
||||
/*
|
||||
* Validity test for a new-format hstore.
|
||||
* 0 = not valid
|
||||
* 1 = valid but with "slop" in the length
|
||||
* 2 = exactly valid
|
||||
* 0 = not valid
|
||||
* 1 = valid but with "slop" in the length
|
||||
* 2 = exactly valid
|
||||
*/
|
||||
static int
|
||||
hstoreValidNewFormat(HStore *hs)
|
||||
{
|
||||
int count = HS_COUNT(hs);
|
||||
HEntry *entries = ARRPTR(hs);
|
||||
int buflen = (count) ? HSE_ENDPOS(entries[2*(count)-1]) : 0;
|
||||
int vsize = CALCDATASIZE(count,buflen);
|
||||
int i;
|
||||
int count = HS_COUNT(hs);
|
||||
HEntry *entries = ARRPTR(hs);
|
||||
int buflen = (count) ? HSE_ENDPOS(entries[2 * (count) - 1]) : 0;
|
||||
int vsize = CALCDATASIZE(count, buflen);
|
||||
int i;
|
||||
|
||||
if (hs->size_ & HS_FLAG_NEWVERSION)
|
||||
return 2;
|
||||
@ -139,10 +139,10 @@ hstoreValidNewFormat(HStore *hs)
|
||||
|
||||
/* entry position must be nondecreasing */
|
||||
|
||||
for (i = 1; i < 2*count; ++i)
|
||||
for (i = 1; i < 2 * count; ++i)
|
||||
{
|
||||
if (HSE_ISFIRST(entries[i])
|
||||
|| (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i-1])))
|
||||
|| (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i - 1])))
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -150,9 +150,9 @@ hstoreValidNewFormat(HStore *hs)
|
||||
|
||||
for (i = 1; i < count; ++i)
|
||||
{
|
||||
if (HS_KEYLEN(entries,i) < HS_KEYLEN(entries,i-1))
|
||||
if (HS_KEYLEN(entries, i) < HS_KEYLEN(entries, i - 1))
|
||||
return 0;
|
||||
if (HSE_ISNULL(entries[2*i]))
|
||||
if (HSE_ISNULL(entries[2 * i]))
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -164,18 +164,18 @@ hstoreValidNewFormat(HStore *hs)
|
||||
|
||||
/*
|
||||
* Validity test for an old-format hstore.
|
||||
* 0 = not valid
|
||||
* 1 = valid but with "slop" in the length
|
||||
* 2 = exactly valid
|
||||
* 0 = not valid
|
||||
* 1 = valid but with "slop" in the length
|
||||
* 2 = exactly valid
|
||||
*/
|
||||
static int
|
||||
hstoreValidOldFormat(HStore *hs)
|
||||
{
|
||||
int count = hs->size_;
|
||||
HOldEntry *entries = (HOldEntry *) ARRPTR(hs);
|
||||
int vsize;
|
||||
int lastpos = 0;
|
||||
int i;
|
||||
int count = hs->size_;
|
||||
HOldEntry *entries = (HOldEntry *) ARRPTR(hs);
|
||||
int vsize;
|
||||
int lastpos = 0;
|
||||
int i;
|
||||
|
||||
if (hs->size_ & HS_FLAG_NEWVERSION)
|
||||
return 0;
|
||||
@ -188,7 +188,7 @@ hstoreValidOldFormat(HStore *hs)
|
||||
if (count > 0xFFFFFFF)
|
||||
return 0;
|
||||
|
||||
if (CALCDATASIZE(count,0) > VARSIZE(hs))
|
||||
if (CALCDATASIZE(count, 0) > VARSIZE(hs))
|
||||
return 0;
|
||||
|
||||
if (entries[0].pos != 0)
|
||||
@ -198,14 +198,14 @@ hstoreValidOldFormat(HStore *hs)
|
||||
|
||||
for (i = 1; i < count; ++i)
|
||||
{
|
||||
if (entries[i].keylen < entries[i-1].keylen)
|
||||
if (entries[i].keylen < entries[i - 1].keylen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* entry position must be strictly increasing, except for the
|
||||
* first entry (which can be ""=>"" and thus zero-length); and
|
||||
* all entries must be properly contiguous
|
||||
* entry position must be strictly increasing, except for the first entry
|
||||
* (which can be ""=>"" and thus zero-length); and all entries must be
|
||||
* properly contiguous
|
||||
*/
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
@ -216,7 +216,7 @@ hstoreValidOldFormat(HStore *hs)
|
||||
+ ((entries[i].valisnull) ? 0 : entries[i].vallen));
|
||||
}
|
||||
|
||||
vsize = CALCDATASIZE(count,lastpos);
|
||||
vsize = CALCDATASIZE(count, lastpos);
|
||||
|
||||
if (vsize > VARSIZE(hs))
|
||||
return 0;
|
||||
@ -255,108 +255,100 @@ hstoreUpgrade(Datum orig)
|
||||
if (valid_new)
|
||||
{
|
||||
/*
|
||||
* force the "new version" flag and the correct varlena
|
||||
* length, but only if we have a writable copy already
|
||||
* (which we almost always will, since short new-format
|
||||
* values won't come through here)
|
||||
* force the "new version" flag and the correct varlena length,
|
||||
* but only if we have a writable copy already (which we almost
|
||||
* always will, since short new-format values won't come through
|
||||
* here)
|
||||
*/
|
||||
if (writable)
|
||||
{
|
||||
HS_SETCOUNT(hs,HS_COUNT(hs));
|
||||
HS_FIXSIZE(hs,HS_COUNT(hs));
|
||||
HS_SETCOUNT(hs, HS_COUNT(hs));
|
||||
HS_FIXSIZE(hs, HS_COUNT(hs));
|
||||
}
|
||||
return hs;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(ERROR,"invalid hstore value found");
|
||||
elog(ERROR, "invalid hstore value found");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* this is the tricky edge case. It is only possible in some
|
||||
* quite extreme cases (the hstore must have had a lot
|
||||
* of wasted padding space at the end).
|
||||
* But the only way a "new" hstore value could get here is if
|
||||
* we're upgrading in place from a pre-release version of
|
||||
* hstore-new (NOT contrib/hstore), so we work off the following
|
||||
* assumptions:
|
||||
* 1. If you're moving from old contrib/hstore to hstore-new,
|
||||
* you're required to fix up any potential conflicts first,
|
||||
* e.g. by running ALTER TABLE ... USING col::text::hstore;
|
||||
* on all hstore columns before upgrading.
|
||||
* 2. If you're moving from old contrib/hstore to new
|
||||
* contrib/hstore, then "new" values are impossible here
|
||||
* 3. If you're moving from pre-release hstore-new to hstore-new,
|
||||
* then "old" values are impossible here
|
||||
* 4. If you're moving from pre-release hstore-new to new
|
||||
* contrib/hstore, you're not doing so as an in-place upgrade,
|
||||
* so there is no issue
|
||||
* So the upshot of all this is that we can treat all the edge
|
||||
* cases as "new" if we're being built as hstore-new, and "old"
|
||||
* if we're being built as contrib/hstore.
|
||||
* this is the tricky edge case. It is only possible in some quite extreme
|
||||
* cases (the hstore must have had a lot of wasted padding space at the
|
||||
* end). But the only way a "new" hstore value could get here is if we're
|
||||
* upgrading in place from a pre-release version of hstore-new (NOT
|
||||
* contrib/hstore), so we work off the following assumptions: 1. If you're
|
||||
* moving from old contrib/hstore to hstore-new, you're required to fix up
|
||||
* any potential conflicts first, e.g. by running ALTER TABLE ... USING
|
||||
* col::text::hstore; on all hstore columns before upgrading. 2. If you're
|
||||
* moving from old contrib/hstore to new contrib/hstore, then "new" values
|
||||
* are impossible here 3. If you're moving from pre-release hstore-new to
|
||||
* hstore-new, then "old" values are impossible here 4. If you're moving
|
||||
* from pre-release hstore-new to new contrib/hstore, you're not doing so
|
||||
* as an in-place upgrade, so there is no issue So the upshot of all this
|
||||
* is that we can treat all the edge cases as "new" if we're being built
|
||||
* as hstore-new, and "old" if we're being built as contrib/hstore.
|
||||
*
|
||||
* XXX the WARNING can probably be downgraded to DEBUG1 once this
|
||||
* has been beta-tested. But for now, it would be very useful to
|
||||
* know if anyone can actually reach this case in a non-contrived
|
||||
* setting.
|
||||
* XXX the WARNING can probably be downgraded to DEBUG1 once this has been
|
||||
* beta-tested. But for now, it would be very useful to know if anyone can
|
||||
* actually reach this case in a non-contrived setting.
|
||||
*/
|
||||
|
||||
if (valid_new)
|
||||
{
|
||||
#if HSTORE_IS_HSTORE_NEW
|
||||
elog(WARNING,"ambiguous hstore value resolved as hstore-new");
|
||||
elog(WARNING, "ambiguous hstore value resolved as hstore-new");
|
||||
|
||||
/*
|
||||
* force the "new version" flag and the correct varlena
|
||||
* length, but only if we have a writable copy already
|
||||
* (which we almost always will, since short new-format
|
||||
* values won't come through here)
|
||||
* force the "new version" flag and the correct varlena length, but
|
||||
* only if we have a writable copy already (which we almost always
|
||||
* will, since short new-format values won't come through here)
|
||||
*/
|
||||
if (writable)
|
||||
{
|
||||
HS_SETCOUNT(hs,HS_COUNT(hs));
|
||||
HS_FIXSIZE(hs,HS_COUNT(hs));
|
||||
HS_SETCOUNT(hs, HS_COUNT(hs));
|
||||
HS_FIXSIZE(hs, HS_COUNT(hs));
|
||||
}
|
||||
return hs;
|
||||
#else
|
||||
elog(WARNING,"ambiguous hstore value resolved as hstore-old");
|
||||
elog(WARNING, "ambiguous hstore value resolved as hstore-old");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* must have an old-style value. Overwrite it in place as a new-style
|
||||
* one, making sure we have a writable copy first.
|
||||
* must have an old-style value. Overwrite it in place as a new-style one,
|
||||
* making sure we have a writable copy first.
|
||||
*/
|
||||
|
||||
if (!writable)
|
||||
hs = (HStore *) PG_DETOAST_DATUM_COPY(orig);
|
||||
|
||||
{
|
||||
int count = hs->size_;
|
||||
HEntry *new_entries = ARRPTR(hs);
|
||||
HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs);
|
||||
int i;
|
||||
|
||||
int count = hs->size_;
|
||||
HEntry *new_entries = ARRPTR(hs);
|
||||
HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
uint32 pos = old_entries[i].pos;
|
||||
uint32 keylen = old_entries[i].keylen;
|
||||
uint32 vallen = old_entries[i].vallen;
|
||||
bool isnull = old_entries[i].valisnull;
|
||||
uint32 pos = old_entries[i].pos;
|
||||
uint32 keylen = old_entries[i].keylen;
|
||||
uint32 vallen = old_entries[i].vallen;
|
||||
bool isnull = old_entries[i].valisnull;
|
||||
|
||||
if (isnull)
|
||||
vallen = 0;
|
||||
|
||||
new_entries[2*i].entry = (pos + keylen) & HENTRY_POSMASK;
|
||||
new_entries[2*i+1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK)
|
||||
| ((isnull) ? HENTRY_ISNULL : 0));
|
||||
new_entries[2 * i].entry = (pos + keylen) & HENTRY_POSMASK;
|
||||
new_entries[2 * i + 1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK)
|
||||
| ((isnull) ? HENTRY_ISNULL : 0));
|
||||
}
|
||||
|
||||
if (count)
|
||||
new_entries[0].entry |= HENTRY_ISFIRST;
|
||||
HS_SETCOUNT(hs,count);
|
||||
HS_FIXSIZE(hs,count);
|
||||
HS_SETCOUNT(hs, count);
|
||||
HS_FIXSIZE(hs, count);
|
||||
}
|
||||
|
||||
return hs;
|
||||
@ -368,9 +360,9 @@ Datum hstore_version_diag(PG_FUNCTION_ARGS);
|
||||
Datum
|
||||
hstore_version_diag(PG_FUNCTION_ARGS)
|
||||
{
|
||||
HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
|
||||
int valid_new = hstoreValidNewFormat(hs);
|
||||
int valid_old = hstoreValidOldFormat(hs);
|
||||
HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
|
||||
int valid_new = hstoreValidNewFormat(hs);
|
||||
int valid_old = hstoreValidOldFormat(hs);
|
||||
|
||||
PG_RETURN_INT32(valid_old*10 + valid_new);
|
||||
PG_RETURN_INT32(valid_old * 10 + valid_new);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.7 2009/09/30 19:50:22 tgl Exp $
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.8 2010/02/26 02:00:32 momjian Exp $
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
@ -36,10 +36,10 @@ gin_extract_hstore(PG_FUNCTION_ARGS)
|
||||
HStore *hs = PG_GETARG_HS(0);
|
||||
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
|
||||
Datum *entries = NULL;
|
||||
HEntry *hsent = ARRPTR(hs);
|
||||
char *ptr = STRPTR(hs);
|
||||
int count = HS_COUNT(hs);
|
||||
int i;
|
||||
HEntry *hsent = ARRPTR(hs);
|
||||
char *ptr = STRPTR(hs);
|
||||
int count = HS_COUNT(hs);
|
||||
int i;
|
||||
|
||||
*nentries = 2 * count;
|
||||
if (count)
|
||||
@ -49,21 +49,21 @@ gin_extract_hstore(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *item;
|
||||
|
||||
item = makeitem(HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i));
|
||||
item = makeitem(HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i));
|
||||
*VARDATA(item) = KEYFLAG;
|
||||
entries[2*i] = PointerGetDatum(item);
|
||||
entries[2 * i] = PointerGetDatum(item);
|
||||
|
||||
if (HS_VALISNULL(hsent,i))
|
||||
if (HS_VALISNULL(hsent, i))
|
||||
{
|
||||
item = makeitem(NULL, 0);
|
||||
*VARDATA(item) = NULLFLAG;
|
||||
}
|
||||
else
|
||||
{
|
||||
item = makeitem(HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i));
|
||||
item = makeitem(HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i));
|
||||
*VARDATA(item) = VALFLAG;
|
||||
}
|
||||
entries[2*i+1] = PointerGetDatum(item);
|
||||
entries[2 * i + 1] = PointerGetDatum(item);
|
||||
}
|
||||
|
||||
PG_RETURN_POINTER(entries);
|
||||
@ -103,14 +103,15 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS)
|
||||
else if (strategy == HStoreExistsAnyStrategyNumber ||
|
||||
strategy == HStoreExistsAllStrategyNumber)
|
||||
{
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
|
||||
Datum *key_datums;
|
||||
bool *key_nulls;
|
||||
int key_count;
|
||||
int i,j;
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
|
||||
Datum *key_datums;
|
||||
bool *key_nulls;
|
||||
int key_count;
|
||||
int i,
|
||||
j;
|
||||
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
|
||||
Datum *entries = NULL;
|
||||
text *item;
|
||||
text *item;
|
||||
|
||||
deconstruct_array(query,
|
||||
TEXTOID, -1, false, 'i',
|
||||
@ -145,8 +146,10 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bool *check = (bool *) PG_GETARG_POINTER(0);
|
||||
StrategyNumber strategy = PG_GETARG_UINT16(1);
|
||||
|
||||
/* HStore *query = PG_GETARG_HS(2); */
|
||||
int32 nkeys = PG_GETARG_INT32(3);
|
||||
|
||||
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
|
||||
bool *recheck = (bool *) PG_GETARG_POINTER(5);
|
||||
bool res = true;
|
||||
@ -178,7 +181,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
|
||||
}
|
||||
else if (strategy == HStoreExistsAllStrategyNumber)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; res && i < nkeys; ++i)
|
||||
if (!check[i])
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.11 2009/09/30 19:50:22 tgl Exp $
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.12 2010/02/26 02:00:32 momjian Exp $
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
@ -118,20 +118,20 @@ ghstore_compress(PG_FUNCTION_ARGS)
|
||||
HStore *val = DatumGetHStoreP(entry->key);
|
||||
HEntry *hsent = ARRPTR(val);
|
||||
char *ptr = STRPTR(val);
|
||||
int count = HS_COUNT(val);
|
||||
int i;
|
||||
int count = HS_COUNT(val);
|
||||
int i;
|
||||
|
||||
SET_VARSIZE(res, CALCGTSIZE(0));
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
int h;
|
||||
int h;
|
||||
|
||||
h = crc32_sz((char *) HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i));
|
||||
h = crc32_sz((char *) HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i));
|
||||
HASH(GETSIGN(res), h);
|
||||
if (!HS_VALISNULL(hsent,i))
|
||||
if (!HS_VALISNULL(hsent, i))
|
||||
{
|
||||
h = crc32_sz((char *) HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i));
|
||||
h = crc32_sz((char *) HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i));
|
||||
HASH(GETSIGN(res), h);
|
||||
}
|
||||
}
|
||||
@ -511,6 +511,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTTYPE *entry = (GISTTYPE *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
|
||||
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
|
||||
|
||||
/* Oid subtype = PG_GETARG_OID(3); */
|
||||
bool *recheck = (bool *) PG_GETARG_POINTER(4);
|
||||
bool res = true;
|
||||
@ -530,18 +531,18 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
||||
HStore *query = PG_GETARG_HS(1);
|
||||
HEntry *qe = ARRPTR(query);
|
||||
char *qv = STRPTR(query);
|
||||
int count = HS_COUNT(query);
|
||||
int i;
|
||||
int count = HS_COUNT(query);
|
||||
int i;
|
||||
|
||||
for (i = 0; res && i < count; ++i)
|
||||
{
|
||||
int crc = crc32_sz((char *) HS_KEY(qe,qv,i), HS_KEYLEN(qe,i));
|
||||
int crc = crc32_sz((char *) HS_KEY(qe, qv, i), HS_KEYLEN(qe, i));
|
||||
|
||||
if (GETBIT(sign, HASHVAL(crc)))
|
||||
{
|
||||
if (!HS_VALISNULL(qe,i))
|
||||
if (!HS_VALISNULL(qe, i))
|
||||
{
|
||||
crc = crc32_sz((char *) HS_VAL(qe,qv,i), HS_VALLEN(qe,i));
|
||||
crc = crc32_sz((char *) HS_VAL(qe, qv, i), HS_VALLEN(qe, i));
|
||||
if (!GETBIT(sign, HASHVAL(crc)))
|
||||
res = false;
|
||||
}
|
||||
@ -559,11 +560,11 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
||||
}
|
||||
else if (strategy == HStoreExistsAllStrategyNumber)
|
||||
{
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
|
||||
Datum *key_datums;
|
||||
bool *key_nulls;
|
||||
int key_count;
|
||||
int i;
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
|
||||
Datum *key_datums;
|
||||
bool *key_nulls;
|
||||
int key_count;
|
||||
int i;
|
||||
|
||||
deconstruct_array(query,
|
||||
TEXTOID, -1, false, 'i',
|
||||
@ -571,7 +572,8 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
||||
|
||||
for (i = 0; res && i < key_count; ++i)
|
||||
{
|
||||
int crc;
|
||||
int crc;
|
||||
|
||||
if (key_nulls[i])
|
||||
continue;
|
||||
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);
|
||||
@ -581,11 +583,11 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
||||
}
|
||||
else if (strategy == HStoreExistsAnyStrategyNumber)
|
||||
{
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
|
||||
Datum *key_datums;
|
||||
bool *key_nulls;
|
||||
int key_count;
|
||||
int i;
|
||||
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
|
||||
Datum *key_datums;
|
||||
bool *key_nulls;
|
||||
int key_count;
|
||||
int i;
|
||||
|
||||
deconstruct_array(query,
|
||||
TEXTOID, -1, false, 'i',
|
||||
@ -595,7 +597,8 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
||||
|
||||
for (i = 0; !res && i < key_count; ++i)
|
||||
{
|
||||
int crc;
|
||||
int crc;
|
||||
|
||||
if (key_nulls[i])
|
||||
continue;
|
||||
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.12 2009/09/30 19:50:22 tgl Exp $
|
||||
* $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.13 2010/02/26 02:00:32 momjian Exp $
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
/* old names for C functions */
|
||||
HSTORE_POLLUTE(hstore_from_text,tconvert);
|
||||
HSTORE_POLLUTE(hstore_from_text, tconvert);
|
||||
|
||||
|
||||
typedef struct
|
||||
@ -370,12 +370,12 @@ hstoreCheckValLen(size_t len)
|
||||
HStore *
|
||||
hstorePairs(Pairs *pairs, int4 pcount, int4 buflen)
|
||||
{
|
||||
HStore *out;
|
||||
HStore *out;
|
||||
HEntry *entry;
|
||||
char *ptr;
|
||||
char *buf;
|
||||
int4 len;
|
||||
int4 i;
|
||||
int4 len;
|
||||
int4 i;
|
||||
|
||||
len = CALCDATASIZE(pcount, buflen);
|
||||
out = palloc(len);
|
||||
@ -389,9 +389,9 @@ hstorePairs(Pairs *pairs, int4 pcount, int4 buflen)
|
||||
buf = ptr = STRPTR(out);
|
||||
|
||||
for (i = 0; i < pcount; i++)
|
||||
HS_ADDITEM(entry,buf,ptr,pairs[i]);
|
||||
HS_ADDITEM(entry, buf, ptr, pairs[i]);
|
||||
|
||||
HS_FINALIZE(out,pcount,buf,ptr);
|
||||
HS_FINALIZE(out, pcount, buf, ptr);
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -426,9 +426,9 @@ hstore_recv(PG_FUNCTION_ARGS)
|
||||
int4 buflen;
|
||||
HStore *out;
|
||||
Pairs *pairs;
|
||||
int4 i;
|
||||
int4 pcount;
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
int4 i;
|
||||
int4 pcount;
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
|
||||
pcount = pq_getmsgint(buf, 4);
|
||||
|
||||
@ -442,8 +442,8 @@ hstore_recv(PG_FUNCTION_ARGS)
|
||||
|
||||
for (i = 0; i < pcount; ++i)
|
||||
{
|
||||
int rawlen = pq_getmsgint(buf, 4);
|
||||
int len;
|
||||
int rawlen = pq_getmsgint(buf, 4);
|
||||
int len;
|
||||
|
||||
if (rawlen < 0)
|
||||
ereport(ERROR,
|
||||
@ -482,9 +482,9 @@ Datum hstore_from_text(PG_FUNCTION_ARGS);
|
||||
Datum
|
||||
hstore_from_text(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *key;
|
||||
text *val = NULL;
|
||||
Pairs p;
|
||||
text *key;
|
||||
text *val = NULL;
|
||||
Pairs p;
|
||||
HStore *out;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
@ -524,13 +524,13 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
|
||||
Pairs *pairs;
|
||||
Datum *key_datums;
|
||||
bool *key_nulls;
|
||||
int key_count;
|
||||
int key_count;
|
||||
Datum *value_datums;
|
||||
bool *value_nulls;
|
||||
int value_count;
|
||||
int value_count;
|
||||
ArrayType *key_array;
|
||||
ArrayType *value_array;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
PG_RETURN_NULL();
|
||||
@ -540,8 +540,8 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
|
||||
Assert(ARR_ELEMTYPE(key_array) == TEXTOID);
|
||||
|
||||
/*
|
||||
* must check >1 rather than != 1 because empty arrays have
|
||||
* 0 dimensions, not 1
|
||||
* must check >1 rather than != 1 because empty arrays have 0 dimensions,
|
||||
* not 1
|
||||
*/
|
||||
|
||||
if (ARR_NDIM(key_array) > 1)
|
||||
@ -631,15 +631,15 @@ Datum
|
||||
hstore_from_array(PG_FUNCTION_ARGS)
|
||||
{
|
||||
ArrayType *in_array = PG_GETARG_ARRAYTYPE_P(0);
|
||||
int ndims = ARR_NDIM(in_array);
|
||||
int count;
|
||||
int ndims = ARR_NDIM(in_array);
|
||||
int count;
|
||||
int4 buflen;
|
||||
HStore *out;
|
||||
Pairs *pairs;
|
||||
Datum *in_datums;
|
||||
bool *in_nulls;
|
||||
int in_count;
|
||||
int i;
|
||||
int in_count;
|
||||
int i;
|
||||
|
||||
Assert(ARR_ELEMTYPE(in_array) == TEXTOID);
|
||||
|
||||
@ -667,7 +667,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
|
||||
errmsg("wrong number of array subscripts")));
|
||||
}
|
||||
}
|
||||
|
||||
deconstruct_array(in_array,
|
||||
TEXTOID, -1, false, 'i',
|
||||
@ -679,26 +679,26 @@ hstore_from_array(PG_FUNCTION_ARGS)
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
if (in_nulls[i*2])
|
||||
if (in_nulls[i * 2])
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
|
||||
errmsg("null value not allowed for hstore key")));
|
||||
|
||||
if (in_nulls[i*2+1])
|
||||
if (in_nulls[i * 2 + 1])
|
||||
{
|
||||
pairs[i].key = VARDATA_ANY(in_datums[i*2]);
|
||||
pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
|
||||
pairs[i].val = NULL;
|
||||
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2]));
|
||||
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
|
||||
pairs[i].vallen = 4;
|
||||
pairs[i].isnull = true;
|
||||
pairs[i].needfree = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pairs[i].key = VARDATA_ANY(in_datums[i*2]);
|
||||
pairs[i].val = VARDATA_ANY(in_datums[i*2+1]);
|
||||
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2]));
|
||||
pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i*2+1]));
|
||||
pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
|
||||
pairs[i].val = VARDATA_ANY(in_datums[i * 2 + 1]);
|
||||
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
|
||||
pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i * 2 + 1]));
|
||||
pairs[i].isnull = false;
|
||||
pairs[i].needfree = false;
|
||||
}
|
||||
@ -740,25 +740,26 @@ hstore_from_record(PG_FUNCTION_ARGS)
|
||||
HeapTupleHeader rec;
|
||||
int4 buflen;
|
||||
HStore *out;
|
||||
Pairs *pairs;
|
||||
Pairs *pairs;
|
||||
Oid tupType;
|
||||
int32 tupTypmod;
|
||||
TupleDesc tupdesc;
|
||||
HeapTupleData tuple;
|
||||
RecordIOData *my_extra;
|
||||
int ncolumns;
|
||||
int i,j;
|
||||
int i,
|
||||
j;
|
||||
Datum *values;
|
||||
bool *nulls;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
{
|
||||
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0);
|
||||
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
|
||||
|
||||
/*
|
||||
* have no tuple to look at, so the only source of type info
|
||||
* is the argtype. The lookup_rowtype_tupdesc call below will
|
||||
* error out if we don't have a known composite type oid here.
|
||||
* have no tuple to look at, so the only source of type info is the
|
||||
* argtype. The lookup_rowtype_tupdesc call below will error out if we
|
||||
* don't have a known composite type oid here.
|
||||
*/
|
||||
tupType = argtype;
|
||||
tupTypmod = -1;
|
||||
@ -855,7 +856,7 @@ hstore_from_record(PG_FUNCTION_ARGS)
|
||||
*/
|
||||
if (column_info->column_type != column_type)
|
||||
{
|
||||
bool typIsVarlena;
|
||||
bool typIsVarlena;
|
||||
|
||||
getTypeOutputInfo(column_type,
|
||||
&column_info->typiofunc,
|
||||
@ -889,18 +890,18 @@ Datum hstore_populate_record(PG_FUNCTION_ARGS);
|
||||
Datum
|
||||
hstore_populate_record(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0);
|
||||
HStore *hs;
|
||||
HEntry *entries;
|
||||
char *ptr;
|
||||
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
|
||||
HStore *hs;
|
||||
HEntry *entries;
|
||||
char *ptr;
|
||||
HeapTupleHeader rec;
|
||||
Oid tupType;
|
||||
int32 tupTypmod;
|
||||
TupleDesc tupdesc;
|
||||
HeapTupleData tuple;
|
||||
HeapTuple rettuple;
|
||||
HeapTuple rettuple;
|
||||
RecordIOData *my_extra;
|
||||
int ncolumns;
|
||||
int ncolumns;
|
||||
int i;
|
||||
Datum *values;
|
||||
bool *nulls;
|
||||
@ -918,9 +919,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
|
||||
rec = NULL;
|
||||
|
||||
/*
|
||||
* have no tuple to look at, so the only source of type info
|
||||
* is the argtype. The lookup_rowtype_tupdesc call below will
|
||||
* error out if we don't have a known composite type oid here.
|
||||
* have no tuple to look at, so the only source of type info is the
|
||||
* argtype. The lookup_rowtype_tupdesc call below will error out if we
|
||||
* don't have a known composite type oid here.
|
||||
*/
|
||||
tupType = argtype;
|
||||
tupTypmod = -1;
|
||||
@ -942,9 +943,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
|
||||
ptr = STRPTR(hs);
|
||||
|
||||
/*
|
||||
* if the input hstore is empty, we can only skip the rest if
|
||||
* we were passed in a non-null record, since otherwise there
|
||||
* may be issues with domain nulls.
|
||||
* if the input hstore is empty, we can only skip the rest if we were
|
||||
* passed in a non-null record, since otherwise there may be issues with
|
||||
* domain nulls.
|
||||
*/
|
||||
|
||||
if (HS_COUNT(hs) == 0 && rec)
|
||||
@ -1012,8 +1013,8 @@ hstore_populate_record(PG_FUNCTION_ARGS)
|
||||
ColumnIOData *column_info = &my_extra->columns[i];
|
||||
Oid column_type = tupdesc->attrs[i]->atttypid;
|
||||
char *value;
|
||||
int idx;
|
||||
int vallen;
|
||||
int idx;
|
||||
int vallen;
|
||||
|
||||
/* Ignore dropped columns in datatype */
|
||||
if (tupdesc->attrs[i]->attisdropped)
|
||||
@ -1025,14 +1026,14 @@ hstore_populate_record(PG_FUNCTION_ARGS)
|
||||
idx = hstoreFindKey(hs, 0,
|
||||
NameStr(tupdesc->attrs[i]->attname),
|
||||
strlen(NameStr(tupdesc->attrs[i]->attname)));
|
||||
|
||||
/*
|
||||
* we can't just skip here if the key wasn't found since we
|
||||
* might have a domain to deal with. If we were passed in a
|
||||
* non-null record datum, we assume that the existing values
|
||||
* are valid (if they're not, then it's not our fault), but if
|
||||
* we were passed in a null, then every field which we don't
|
||||
* populate needs to be run through the input function just in
|
||||
* case it's a domain type.
|
||||
* we can't just skip here if the key wasn't found since we might have
|
||||
* a domain to deal with. If we were passed in a non-null record
|
||||
* datum, we assume that the existing values are valid (if they're
|
||||
* not, then it's not our fault), but if we were passed in a null,
|
||||
* then every field which we don't populate needs to be run through
|
||||
* the input function just in case it's a domain type.
|
||||
*/
|
||||
if (idx < 0 && rec)
|
||||
continue;
|
||||
@ -1050,11 +1051,11 @@ hstore_populate_record(PG_FUNCTION_ARGS)
|
||||
column_info->column_type = column_type;
|
||||
}
|
||||
|
||||
if (idx < 0 || HS_VALISNULL(entries,idx))
|
||||
if (idx < 0 || HS_VALISNULL(entries, idx))
|
||||
{
|
||||
/*
|
||||
* need InputFunctionCall to happen even for nulls, so
|
||||
* that domain checks are done
|
||||
* need InputFunctionCall to happen even for nulls, so that domain
|
||||
* checks are done
|
||||
*/
|
||||
values[i] = InputFunctionCall(&column_info->proc, NULL,
|
||||
column_info->typioparam,
|
||||
@ -1063,9 +1064,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
|
||||
}
|
||||
else
|
||||
{
|
||||
vallen = HS_VALLEN(entries,idx);
|
||||
vallen = HS_VALLEN(entries, idx);
|
||||
value = palloc(1 + vallen);
|
||||
memcpy(value, HS_VAL(entries,ptr,idx), vallen);
|
||||
memcpy(value, HS_VAL(entries, ptr, idx), vallen);
|
||||
value[vallen] = 0;
|
||||
|
||||
values[i] = InputFunctionCall(&column_info->proc, value,
|
||||
@ -1105,7 +1106,7 @@ hstore_out(PG_FUNCTION_ARGS)
|
||||
HStore *in = PG_GETARG_HS(0);
|
||||
int buflen,
|
||||
i;
|
||||
int count = HS_COUNT(in);
|
||||
int count = HS_COUNT(in);
|
||||
char *out,
|
||||
*ptr;
|
||||
char *base = STRPTR(in);
|
||||
@ -1121,21 +1122,21 @@ hstore_out(PG_FUNCTION_ARGS)
|
||||
buflen = 0;
|
||||
|
||||
/*
|
||||
* this loop overestimates due to pessimistic assumptions about
|
||||
* escaping, so very large hstore values can't be output. this
|
||||
* could be fixed, but many other data types probably have the
|
||||
* same issue. This replaced code that used the original varlena
|
||||
* size for calculations, which was wrong in some subtle ways.
|
||||
* this loop overestimates due to pessimistic assumptions about escaping,
|
||||
* so very large hstore values can't be output. this could be fixed, but
|
||||
* many other data types probably have the same issue. This replaced code
|
||||
* that used the original varlena size for calculations, which was wrong
|
||||
* in some subtle ways.
|
||||
*/
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
/* include "" and => and comma-space */
|
||||
buflen += 6 + 2 * HS_KEYLEN(entries,i);
|
||||
buflen += 6 + 2 * HS_KEYLEN(entries, i);
|
||||
/* include "" only if nonnull */
|
||||
buflen += 2 + (HS_VALISNULL(entries,i)
|
||||
buflen += 2 + (HS_VALISNULL(entries, i)
|
||||
? 2
|
||||
: 2 * HS_VALLEN(entries,i));
|
||||
: 2 * HS_VALLEN(entries, i));
|
||||
}
|
||||
|
||||
out = ptr = palloc(buflen);
|
||||
@ -1143,11 +1144,11 @@ hstore_out(PG_FUNCTION_ARGS)
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
*ptr++ = '"';
|
||||
ptr = cpw(ptr, HS_KEY(entries,base,i), HS_KEYLEN(entries,i));
|
||||
ptr = cpw(ptr, HS_KEY(entries, base, i), HS_KEYLEN(entries, i));
|
||||
*ptr++ = '"';
|
||||
*ptr++ = '=';
|
||||
*ptr++ = '>';
|
||||
if (HS_VALISNULL(entries,i))
|
||||
if (HS_VALISNULL(entries, i))
|
||||
{
|
||||
*ptr++ = 'N';
|
||||
*ptr++ = 'U';
|
||||
@ -1157,7 +1158,7 @@ hstore_out(PG_FUNCTION_ARGS)
|
||||
else
|
||||
{
|
||||
*ptr++ = '"';
|
||||
ptr = cpw(ptr, HS_VAL(entries,base,i), HS_VALLEN(entries,i));
|
||||
ptr = cpw(ptr, HS_VAL(entries, base, i), HS_VALLEN(entries, i));
|
||||
*ptr++ = '"';
|
||||
}
|
||||
|
||||
@ -1179,8 +1180,8 @@ Datum
|
||||
hstore_send(PG_FUNCTION_ARGS)
|
||||
{
|
||||
HStore *in = PG_GETARG_HS(0);
|
||||
int i;
|
||||
int count = HS_COUNT(in);
|
||||
int i;
|
||||
int count = HS_COUNT(in);
|
||||
char *base = STRPTR(in);
|
||||
HEntry *entries = ARRPTR(in);
|
||||
StringInfoData buf;
|
||||
@ -1191,18 +1192,20 @@ hstore_send(PG_FUNCTION_ARGS)
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int32 keylen = HS_KEYLEN(entries,i);
|
||||
int32 keylen = HS_KEYLEN(entries, i);
|
||||
|
||||
pq_sendint(&buf, keylen, 4);
|
||||
pq_sendtext(&buf, HS_KEY(entries,base,i), keylen);
|
||||
if (HS_VALISNULL(entries,i))
|
||||
pq_sendtext(&buf, HS_KEY(entries, base, i), keylen);
|
||||
if (HS_VALISNULL(entries, i))
|
||||
{
|
||||
pq_sendint(&buf, -1, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32 vallen = HS_VALLEN(entries,i);
|
||||
int32 vallen = HS_VALLEN(entries, i);
|
||||
|
||||
pq_sendint(&buf, vallen, 4);
|
||||
pq_sendtext(&buf, HS_VAL(entries,base,i), vallen);
|
||||
pq_sendtext(&buf, HS_VAL(entries, base, i), vallen);
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user