summaryrefslogtreecommitdiff
path: root/contrib/hstore/hstore_gist.c
diff options
context:
space:
mode:
authorTeodor Sigaev <teodor@sigaev.ru>2007-03-14 14:21:53 +0000
committerTeodor Sigaev <teodor@sigaev.ru>2007-03-14 14:21:53 +0000
commit754148d81f9150fd860b4d5aac0eb420e4cd6886 (patch)
tree51d7c8d18f189e071db2a3fd8d69c1595305cae9 /contrib/hstore/hstore_gist.c
parent15f91f27897542c0e154037fca503f7543241e49 (diff)
downloadpostgresql-754148d81f9150fd860b4d5aac0eb420e4cd6886.tar.gz
Add GIN support for pg_trgm. From Guillaume Smet <guillaume.smet@gmail.com>
with minor editorization by me. Hstore improvements * add operation hstore ? text - excat equivalent of exist() * remove undocumented behaviour of contains operation with NULL value * now 'key'::text=>NULL returns '"key"=>NULL' instead of NULL * Add GIN support for contains and exist operations * Add GiST support for exist operatiion * improve regression tests
Diffstat (limited to 'contrib/hstore/hstore_gist.c')
-rw-r--r--contrib/hstore/hstore_gist.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c
index c3923dacf2..fbee64be7d 100644
--- a/contrib/hstore/hstore_gist.c
+++ b/contrib/hstore/hstore_gist.c
@@ -492,37 +492,48 @@ Datum
ghstore_consistent(PG_FUNCTION_ARGS)
{
GISTTYPE *entry = (GISTTYPE *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- HStore *query = PG_GETARG_HS(1);
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool res = true;
- HEntry *qe = ARRPTR(query);
- char *qv = STRPTR(query);
BITVECP sign;
if (ISALLTRUE(entry))
- {
- PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(true);
- }
sign = GETSIGN(entry);
- while (res && qe - ARRPTR(query) < query->size)
+
+ if ( strategy == HStoreContainsStrategyNumber || strategy == 13 /* hack for old strats */ )
{
- int crc = crc32_sz((char *) (qv + qe->pos), qe->keylen);
+ HStore *query = PG_GETARG_HS(1);
+ HEntry *qe = ARRPTR(query);
+ char *qv = STRPTR(query);
- if (GETBIT(sign, HASHVAL(crc)))
+ while (res && qe - ARRPTR(query) < query->size)
{
- if (!qe->valisnull)
+ int crc = crc32_sz((char *) (qv + qe->pos), qe->keylen);
+
+ if (GETBIT(sign, HASHVAL(crc)))
{
- crc = crc32_sz((char *) (qv + qe->pos + qe->keylen), qe->vallen);
- if (!GETBIT(sign, HASHVAL(crc)))
- res = false;
+ if (!qe->valisnull)
+ {
+ crc = crc32_sz((char *) (qv + qe->pos + qe->keylen), qe->vallen);
+ if (!GETBIT(sign, HASHVAL(crc)))
+ res = false;
+ }
}
+ else
+ res = false;
+ qe++;
}
- else
- res = false;
- qe++;
}
+ else if ( strategy == HStoreExistsStrategyNumber )
+ {
+ text *query = PG_GETARG_TEXT_P(1);
+ int crc = crc32_sz( VARDATA(query), VARSIZE(query)-VARHDRSZ );
+
+ res = (GETBIT(sign, HASHVAL(crc))) ? true : false;
+ }
+ else
+ elog(ERROR, "Unsupported strategy number: %d", strategy);
- PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(res);
}