2002-07-31 00:40:34 +08:00
|
|
|
/*
|
2002-09-05 04:31:48 +08:00
|
|
|
* GiST support for ltree
|
2002-07-31 00:40:34 +08:00
|
|
|
* Teodor Sigaev <teodor@stack.net>
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/ltree/ltree_gist.c
|
2002-07-31 00:40:34 +08:00
|
|
|
*/
|
2008-05-12 08:00:54 +08:00
|
|
|
#include "postgres.h"
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
#include "access/gist.h"
|
2015-05-16 04:03:16 +08:00
|
|
|
#include "access/stratnum.h"
|
2002-07-31 00:40:34 +08:00
|
|
|
#include "crc32.h"
|
2008-05-12 08:00:54 +08:00
|
|
|
#include "ltree.h"
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2003-02-19 11:50:09 +08:00
|
|
|
#define NEXTVAL(x) ( (lquery*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
PG_FUNCTION_INFO_V1(ltree_gist_in);
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_gist_out);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
Datum
|
2002-09-05 04:31:48 +08:00
|
|
|
ltree_gist_in(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-25 01:52:50 +08:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("ltree_gist_in() not implemented")));
|
2002-07-31 00:40:34 +08:00
|
|
|
PG_RETURN_DATUM(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
2002-09-05 04:31:48 +08:00
|
|
|
ltree_gist_out(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2003-07-25 01:52:50 +08:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("ltree_gist_out() not implemented")));
|
2002-07-31 00:40:34 +08:00
|
|
|
PG_RETURN_DATUM(0);
|
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
PG_FUNCTION_INFO_V1(ltree_compress);
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_decompress);
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_same);
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_union);
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_penalty);
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_picksplit);
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_consistent);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
#define ISEQ(a,b) ( (a)->numlevel == (b)->numlevel && ltree_compare(a,b)==0 )
|
2004-03-30 23:45:33 +08:00
|
|
|
#define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer((vec)->vector[(pos)].key))
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
Datum
|
|
|
|
ltree_compress(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
2002-07-31 00:40:34 +08:00
|
|
|
GISTENTRY *retval = entry;
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
if (entry->leafkey)
|
|
|
|
{ /* ltree */
|
|
|
|
ltree_gist *key;
|
2017-09-19 03:21:23 +08:00
|
|
|
ltree *val = DatumGetLtreeP(entry->key);
|
2012-06-25 06:51:46 +08:00
|
|
|
int32 len = LTG_HDRSIZE + VARSIZE(val);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2016-03-09 06:59:29 +08:00
|
|
|
key = (ltree_gist *) palloc0(len);
|
2007-03-01 06:44:38 +08:00
|
|
|
SET_VARSIZE(key, len);
|
2002-07-31 00:40:34 +08:00
|
|
|
key->flag = LTG_ONENODE;
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy((void *) LTG_NODE(key), (void *) val, VARSIZE(val));
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
|
2002-07-31 00:40:34 +08:00
|
|
|
gistentryinit(*retval, PointerGetDatum(key),
|
2002-09-05 04:31:48 +08:00
|
|
|
entry->rel, entry->page,
|
2017-08-16 12:22:32 +08:00
|
|
|
entry->offset, false);
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
PG_RETURN_POINTER(retval);
|
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
Datum
|
|
|
|
ltree_decompress(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
2017-09-19 03:21:23 +08:00
|
|
|
ltree_gist *key = (ltree_gist *) PG_DETOAST_DATUM(entry->key);
|
2002-09-05 04:31:48 +08:00
|
|
|
|
|
|
|
if (PointerGetDatum(key) != entry->key)
|
|
|
|
{
|
|
|
|
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
gistentryinit(*retval, PointerGetDatum(key),
|
2002-09-05 04:31:48 +08:00
|
|
|
entry->rel, entry->page,
|
2017-08-16 12:22:32 +08:00
|
|
|
entry->offset, false);
|
2002-07-31 00:40:34 +08:00
|
|
|
PG_RETURN_POINTER(retval);
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
PG_RETURN_POINTER(entry);
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
Datum
|
|
|
|
ltree_same(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
ltree_gist *a = (ltree_gist *) PG_GETARG_POINTER(0);
|
|
|
|
ltree_gist *b = (ltree_gist *) PG_GETARG_POINTER(1);
|
|
|
|
bool *result = (bool *) PG_GETARG_POINTER(2);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
*result = false;
|
2002-09-05 04:31:48 +08:00
|
|
|
if (LTG_ISONENODE(a) != LTG_ISONENODE(b))
|
|
|
|
PG_RETURN_POINTER(result);
|
|
|
|
|
|
|
|
if (LTG_ISONENODE(a))
|
|
|
|
*result = (ISEQ(LTG_NODE(a), LTG_NODE(b))) ? true : false;
|
|
|
|
else
|
|
|
|
{
|
2012-06-25 06:51:46 +08:00
|
|
|
int32 i;
|
2002-09-05 04:31:48 +08:00
|
|
|
BITVECP sa = LTG_SIGN(a),
|
|
|
|
sb = LTG_SIGN(b);
|
|
|
|
|
|
|
|
if (LTG_ISALLTRUE(a) != LTG_ISALLTRUE(b))
|
|
|
|
PG_RETURN_POINTER(result);
|
|
|
|
|
|
|
|
if (!ISEQ(LTG_LNODE(a), LTG_LNODE(b)))
|
|
|
|
PG_RETURN_POINTER(result);
|
|
|
|
if (!ISEQ(LTG_RNODE(a), LTG_RNODE(b)))
|
2002-07-31 00:40:34 +08:00
|
|
|
PG_RETURN_POINTER(result);
|
|
|
|
|
|
|
|
*result = true;
|
2002-09-05 04:31:48 +08:00
|
|
|
if (!LTG_ISALLTRUE(a))
|
2007-11-16 08:13:02 +08:00
|
|
|
{
|
|
|
|
LOOPBYTE
|
|
|
|
{
|
2007-11-16 09:12:24 +08:00
|
|
|
if (sa[i] != sb[i])
|
|
|
|
{
|
2007-11-16 08:13:02 +08:00
|
|
|
*result = false;
|
|
|
|
break;
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
2007-11-16 08:13:02 +08:00
|
|
|
}
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
|
|
|
|
PG_RETURN_POINTER(result);
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-11 22:49:15 +08:00
|
|
|
hashing(BITVECP sign, ltree *t)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
|
|
|
int tlen = t->numlevel;
|
2002-07-31 00:40:34 +08:00
|
|
|
ltree_level *cur = LTREE_FIRST(t);
|
2002-09-05 04:31:48 +08:00
|
|
|
int hash;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
while (tlen > 0)
|
|
|
|
{
|
|
|
|
hash = ltree_crc32_sz(cur->name, cur->len);
|
|
|
|
HASH(sign, hash);
|
2002-07-31 00:40:34 +08:00
|
|
|
cur = LEVEL_NEXT(cur);
|
|
|
|
tlen--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
Datum
|
|
|
|
ltree_union(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
|
2002-09-05 04:31:48 +08:00
|
|
|
int *size = (int *) PG_GETARG_POINTER(1);
|
|
|
|
BITVEC base;
|
2012-06-25 06:51:46 +08:00
|
|
|
int32 i,
|
2002-09-05 04:31:48 +08:00
|
|
|
j;
|
|
|
|
ltree_gist *result,
|
|
|
|
*cur;
|
|
|
|
ltree *left = NULL,
|
|
|
|
*right = NULL,
|
|
|
|
*curtree;
|
|
|
|
bool isalltrue = false;
|
|
|
|
bool isleqr;
|
|
|
|
|
|
|
|
MemSet((void *) base, 0, sizeof(BITVEC));
|
2004-03-30 23:45:33 +08:00
|
|
|
for (j = 0; j < entryvec->n; j++)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
cur = GETENTRY(entryvec, j);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (LTG_ISONENODE(cur))
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
curtree = LTG_NODE(cur);
|
2002-09-05 04:31:48 +08:00
|
|
|
hashing(base, curtree);
|
|
|
|
if (!left || ltree_compare(left, curtree) > 0)
|
|
|
|
left = curtree;
|
|
|
|
if (!right || ltree_compare(right, curtree) < 0)
|
2002-07-31 00:40:34 +08:00
|
|
|
right = curtree;
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (isalltrue || LTG_ISALLTRUE(cur))
|
2002-07-31 00:40:34 +08:00
|
|
|
isalltrue = true;
|
2002-09-05 04:31:48 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
BITVECP sc = LTG_SIGN(cur);
|
|
|
|
|
2007-11-16 08:13:02 +08:00
|
|
|
LOOPBYTE
|
2007-11-16 09:12:24 +08:00
|
|
|
((unsigned char *) base)[i] |= sc[i];
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
curtree = LTG_LNODE(cur);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (!left || ltree_compare(left, curtree) > 0)
|
|
|
|
left = curtree;
|
2002-07-31 00:40:34 +08:00
|
|
|
curtree = LTG_RNODE(cur);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (!right || ltree_compare(right, curtree) < 0)
|
2002-07-31 00:40:34 +08:00
|
|
|
right = curtree;
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
|
|
|
|
if (isalltrue == false)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
isalltrue = true;
|
2007-11-16 08:13:02 +08:00
|
|
|
LOOPBYTE
|
|
|
|
{
|
|
|
|
if (((unsigned char *) base)[i] != 0xff)
|
|
|
|
{
|
|
|
|
isalltrue = false;
|
|
|
|
break;
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
isleqr = (left == right || ISEQ(left, right)) ? true : false;
|
2007-03-01 06:44:38 +08:00
|
|
|
*size = LTG_HDRSIZE + ((isalltrue) ? 0 : SIGLEN) + VARSIZE(left) + ((isleqr) ? 0 : VARSIZE(right));
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2016-03-09 06:59:29 +08:00
|
|
|
result = (ltree_gist *) palloc0(*size);
|
2007-03-01 06:44:38 +08:00
|
|
|
SET_VARSIZE(result, *size);
|
2002-07-31 00:40:34 +08:00
|
|
|
result->flag = 0;
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
if (isalltrue)
|
2002-07-31 00:40:34 +08:00
|
|
|
result->flag |= LTG_ALLTRUE;
|
|
|
|
else
|
2002-09-05 04:31:48 +08:00
|
|
|
memcpy((void *) LTG_SIGN(result), base, SIGLEN);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy((void *) LTG_LNODE(result), (void *) left, VARSIZE(left));
|
2002-09-05 04:31:48 +08:00
|
|
|
if (isleqr)
|
2002-07-31 00:40:34 +08:00
|
|
|
result->flag |= LTG_NORIGHT;
|
|
|
|
else
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy((void *) LTG_RNODE(result), (void *) right, VARSIZE(right));
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
PG_RETURN_POINTER(result);
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
Datum
|
|
|
|
ltree_penalty(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
|
|
|
|
ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
|
|
|
|
float *penalty = (float *) PG_GETARG_POINTER(2);
|
2012-06-25 06:51:46 +08:00
|
|
|
int32 cmpr,
|
2002-09-05 04:31:48 +08:00
|
|
|
cmpl;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval));
|
|
|
|
cmpr = ltree_compare(LTG_GETRNODE(newval), LTG_GETRNODE(origval));
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2004-10-22 03:28:36 +08:00
|
|
|
*penalty = Max(cmpl, 0) + Max(cmpr, 0);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
PG_RETURN_POINTER(penalty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* used for sorting */
|
2002-09-05 04:31:48 +08:00
|
|
|
typedef struct rix
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
ltree *r;
|
2009-06-11 22:49:15 +08:00
|
|
|
} RIX;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
static int
|
2002-09-05 04:31:48 +08:00
|
|
|
treekey_cmp(const void *a, const void *b)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
return ltree_compare(
|
2012-02-28 18:42:08 +08:00
|
|
|
((const RIX *) a)->r,
|
|
|
|
((const RIX *) b)->r
|
2004-08-29 13:07:03 +08:00
|
|
|
);
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
Datum
|
|
|
|
ltree_picksplit(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
|
2002-09-05 04:31:48 +08:00
|
|
|
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
|
2002-07-31 00:40:34 +08:00
|
|
|
OffsetNumber j;
|
2012-06-25 06:51:46 +08:00
|
|
|
int32 i;
|
2002-09-05 04:31:48 +08:00
|
|
|
RIX *array;
|
2002-07-31 00:40:34 +08:00
|
|
|
OffsetNumber maxoff;
|
2002-09-05 04:31:48 +08:00
|
|
|
int nbytes;
|
|
|
|
int size;
|
|
|
|
ltree *lu_l,
|
|
|
|
*lu_r,
|
|
|
|
*ru_l,
|
|
|
|
*ru_r;
|
|
|
|
ltree_gist *lu,
|
|
|
|
*ru;
|
|
|
|
BITVEC ls,
|
|
|
|
rs;
|
|
|
|
bool lisat = false,
|
|
|
|
risat = false,
|
|
|
|
isleqr;
|
|
|
|
|
|
|
|
memset((void *) ls, 0, sizeof(BITVEC));
|
|
|
|
memset((void *) rs, 0, sizeof(BITVEC));
|
2004-03-30 23:45:33 +08:00
|
|
|
maxoff = entryvec->n - 1;
|
2002-07-31 00:40:34 +08:00
|
|
|
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
|
|
|
|
v->spl_left = (OffsetNumber *) palloc(nbytes);
|
|
|
|
v->spl_right = (OffsetNumber *) palloc(nbytes);
|
|
|
|
v->spl_nleft = 0;
|
|
|
|
v->spl_nright = 0;
|
|
|
|
array = (RIX *) palloc(sizeof(RIX) * (maxoff + 1));
|
2002-09-05 04:31:48 +08:00
|
|
|
|
2002-07-31 00:40:34 +08:00
|
|
|
/* copy the data into RIXes, and sort the RIXes */
|
2002-09-05 04:31:48 +08:00
|
|
|
for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
array[j].index = j;
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:18:54 +08:00
|
|
|
lu = GETENTRY(entryvec, j); /* use as tmp val */
|
2002-07-31 00:40:34 +08:00
|
|
|
array[j].r = LTG_GETLNODE(lu);
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort((void *) &array[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1,
|
2002-09-05 04:31:48 +08:00
|
|
|
sizeof(RIX), treekey_cmp);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
lu_l = lu_r = ru_l = ru_r = NULL;
|
2002-09-05 04:31:48 +08:00
|
|
|
for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
|
|
|
|
{
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:18:54 +08:00
|
|
|
lu = GETENTRY(entryvec, array[j].index); /* use as tmp val */
|
2002-09-05 04:31:48 +08:00
|
|
|
if (j <= (maxoff - FirstOffsetNumber + 1) / 2)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
v->spl_left[v->spl_nleft] = array[j].index;
|
|
|
|
v->spl_nleft++;
|
2002-09-05 04:31:48 +08:00
|
|
|
if (lu_r == NULL || ltree_compare(LTG_GETRNODE(lu), lu_r) > 0)
|
2002-07-31 00:40:34 +08:00
|
|
|
lu_r = LTG_GETRNODE(lu);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (LTG_ISONENODE(lu))
|
|
|
|
hashing(ls, LTG_NODE(lu));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lisat || LTG_ISALLTRUE(lu))
|
2002-07-31 00:40:34 +08:00
|
|
|
lisat = true;
|
2002-09-05 04:31:48 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
BITVECP sc = LTG_SIGN(lu);
|
|
|
|
|
2007-11-16 08:13:02 +08:00
|
|
|
LOOPBYTE
|
2007-11-16 09:12:24 +08:00
|
|
|
((unsigned char *) ls)[i] |= sc[i];
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
v->spl_right[v->spl_nright] = array[j].index;
|
|
|
|
v->spl_nright++;
|
2002-09-05 04:31:48 +08:00
|
|
|
if (ru_r == NULL || ltree_compare(LTG_GETRNODE(lu), ru_r) > 0)
|
2002-07-31 00:40:34 +08:00
|
|
|
ru_r = LTG_GETRNODE(lu);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (LTG_ISONENODE(lu))
|
|
|
|
hashing(rs, LTG_NODE(lu));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (risat || LTG_ISALLTRUE(lu))
|
2002-07-31 00:40:34 +08:00
|
|
|
risat = true;
|
2002-09-05 04:31:48 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
BITVECP sc = LTG_SIGN(lu);
|
|
|
|
|
2007-11-16 08:13:02 +08:00
|
|
|
LOOPBYTE
|
2007-11-16 09:12:24 +08:00
|
|
|
((unsigned char *) rs)[i] |= sc[i];
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
|
|
|
|
if (lisat == false)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
lisat = true;
|
2007-11-16 08:13:02 +08:00
|
|
|
LOOPBYTE
|
|
|
|
{
|
|
|
|
if (((unsigned char *) ls)[i] != 0xff)
|
|
|
|
{
|
|
|
|
lisat = false;
|
|
|
|
break;
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
if (risat == false)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
risat = true;
|
2007-11-16 08:13:02 +08:00
|
|
|
LOOPBYTE
|
|
|
|
{
|
|
|
|
if (((unsigned char *) rs)[i] != 0xff)
|
|
|
|
{
|
|
|
|
risat = false;
|
|
|
|
break;
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
lu_l = LTG_GETLNODE(GETENTRY(entryvec, array[FirstOffsetNumber].index));
|
|
|
|
isleqr = (lu_l == lu_r || ISEQ(lu_l, lu_r)) ? true : false;
|
2007-03-01 06:44:38 +08:00
|
|
|
size = LTG_HDRSIZE + ((lisat) ? 0 : SIGLEN) + VARSIZE(lu_l) + ((isleqr) ? 0 : VARSIZE(lu_r));
|
2016-03-09 06:59:29 +08:00
|
|
|
lu = (ltree_gist *) palloc0(size);
|
2007-03-01 06:44:38 +08:00
|
|
|
SET_VARSIZE(lu, size);
|
2002-07-31 00:40:34 +08:00
|
|
|
lu->flag = 0;
|
2002-09-05 04:31:48 +08:00
|
|
|
if (lisat)
|
2002-07-31 00:40:34 +08:00
|
|
|
lu->flag |= LTG_ALLTRUE;
|
|
|
|
else
|
2002-09-05 04:31:48 +08:00
|
|
|
memcpy((void *) LTG_SIGN(lu), ls, SIGLEN);
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy((void *) LTG_LNODE(lu), (void *) lu_l, VARSIZE(lu_l));
|
2002-09-05 04:31:48 +08:00
|
|
|
if (isleqr)
|
2002-07-31 00:40:34 +08:00
|
|
|
lu->flag |= LTG_NORIGHT;
|
|
|
|
else
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy((void *) LTG_RNODE(lu), (void *) lu_r, VARSIZE(lu_r));
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
ru_l = LTG_GETLNODE(GETENTRY(entryvec, array[1 + ((maxoff - FirstOffsetNumber + 1) / 2)].index));
|
|
|
|
isleqr = (ru_l == ru_r || ISEQ(ru_l, ru_r)) ? true : false;
|
2007-03-01 06:44:38 +08:00
|
|
|
size = LTG_HDRSIZE + ((risat) ? 0 : SIGLEN) + VARSIZE(ru_l) + ((isleqr) ? 0 : VARSIZE(ru_r));
|
2016-03-09 06:59:29 +08:00
|
|
|
ru = (ltree_gist *) palloc0(size);
|
2007-03-01 06:44:38 +08:00
|
|
|
SET_VARSIZE(ru, size);
|
2002-07-31 00:40:34 +08:00
|
|
|
ru->flag = 0;
|
2002-09-05 04:31:48 +08:00
|
|
|
if (risat)
|
2002-07-31 00:40:34 +08:00
|
|
|
ru->flag |= LTG_ALLTRUE;
|
|
|
|
else
|
2002-09-05 04:31:48 +08:00
|
|
|
memcpy((void *) LTG_SIGN(ru), rs, SIGLEN);
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy((void *) LTG_LNODE(ru), (void *) ru_l, VARSIZE(ru_l));
|
2002-09-05 04:31:48 +08:00
|
|
|
if (isleqr)
|
2002-07-31 00:40:34 +08:00
|
|
|
ru->flag |= LTG_NORIGHT;
|
|
|
|
else
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy((void *) LTG_RNODE(ru), (void *) ru_r, VARSIZE(ru_r));
|
2002-07-31 00:40:34 +08:00
|
|
|
|
|
|
|
v->spl_ldatum = PointerGetDatum(lu);
|
|
|
|
v->spl_rdatum = PointerGetDatum(ru);
|
|
|
|
|
|
|
|
PG_RETURN_POINTER(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2009-06-11 22:49:15 +08:00
|
|
|
gist_isparent(ltree_gist *key, ltree *query)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
2012-06-25 06:51:46 +08:00
|
|
|
int32 numlevel = query->numlevel;
|
2002-09-05 04:31:48 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = query->numlevel; i >= 0; i--)
|
|
|
|
{
|
|
|
|
query->numlevel = i;
|
|
|
|
if (ltree_compare(query, LTG_GETLNODE(key)) >= 0 && ltree_compare(query, LTG_GETRNODE(key)) <= 0)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
query->numlevel = numlevel;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
query->numlevel = numlevel;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-08 23:45:18 +08:00
|
|
|
static ltree *
|
2009-06-11 22:49:15 +08:00
|
|
|
copy_ltree(ltree *src)
|
2006-10-04 08:30:14 +08:00
|
|
|
{
|
2016-03-09 06:59:29 +08:00
|
|
|
ltree *dst = (ltree *) palloc0(VARSIZE(src));
|
2006-10-04 08:30:14 +08:00
|
|
|
|
2007-03-01 06:44:38 +08:00
|
|
|
memcpy(dst, src, VARSIZE(src));
|
2006-08-08 23:45:18 +08:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2002-07-31 00:40:34 +08:00
|
|
|
static bool
|
2009-06-11 22:49:15 +08:00
|
|
|
gist_ischild(ltree_gist *key, ltree *query)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
2006-10-04 08:30:14 +08:00
|
|
|
ltree *left = copy_ltree(LTG_GETLNODE(key));
|
|
|
|
ltree *right = copy_ltree(LTG_GETRNODE(key));
|
|
|
|
bool res = true;
|
2006-08-08 23:45:18 +08:00
|
|
|
|
|
|
|
if (left->numlevel > query->numlevel)
|
|
|
|
left->numlevel = query->numlevel;
|
|
|
|
|
|
|
|
if (ltree_compare(query, left) < 0)
|
|
|
|
res = false;
|
|
|
|
|
|
|
|
if (right->numlevel > query->numlevel)
|
|
|
|
right->numlevel = query->numlevel;
|
|
|
|
|
|
|
|
if (res && ltree_compare(query, right) > 0)
|
|
|
|
res = false;
|
2002-09-05 04:31:48 +08:00
|
|
|
|
2006-08-08 23:45:18 +08:00
|
|
|
pfree(left);
|
|
|
|
pfree(right);
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2006-08-08 23:45:18 +08:00
|
|
|
return res;
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2009-06-11 22:49:15 +08:00
|
|
|
gist_qe(ltree_gist *key, lquery *query)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
|
|
|
lquery_level *curq = LQUERY_FIRST(query);
|
|
|
|
BITVECP sign = LTG_SIGN(key);
|
|
|
|
int qlen = query->numlevel;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
if (LTG_ISALLTRUE(key))
|
2002-07-31 00:40:34 +08:00
|
|
|
return true;
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
while (qlen > 0)
|
|
|
|
{
|
|
|
|
if (curq->numvar && LQL_CANLOOKSIGN(curq))
|
|
|
|
{
|
|
|
|
bool isexist = false;
|
|
|
|
int vlen = curq->numvar;
|
2002-07-31 00:40:34 +08:00
|
|
|
lquery_variant *curv = LQL_FIRST(curq);
|
2002-09-05 04:31:48 +08:00
|
|
|
|
|
|
|
while (vlen > 0)
|
|
|
|
{
|
|
|
|
if (GETBIT(sign, HASHVAL(curv->val)))
|
|
|
|
{
|
|
|
|
isexist = true;
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
curv = LVAR_NEXT(curv);
|
|
|
|
vlen--;
|
|
|
|
}
|
2002-09-05 04:31:48 +08:00
|
|
|
if (!isexist)
|
|
|
|
return false;
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
curq = LQL_NEXT(curq);
|
|
|
|
qlen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-06-11 22:49:15 +08:00
|
|
|
gist_tqcmp(ltree *t, lquery *q)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
ltree_level *al = LTREE_FIRST(t);
|
|
|
|
lquery_level *ql = LQUERY_FIRST(q);
|
|
|
|
lquery_variant *bl;
|
2002-09-05 04:31:48 +08:00
|
|
|
int an = t->numlevel;
|
|
|
|
int bn = q->firstgood;
|
|
|
|
int res = 0;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
while (an > 0 && bn > 0)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
bl = LQL_FIRST(ql);
|
2010-12-22 11:11:40 +08:00
|
|
|
if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
|
|
|
if (al->len != bl->len)
|
2002-07-31 00:40:34 +08:00
|
|
|
return al->len - bl->len;
|
2002-09-05 04:31:48 +08:00
|
|
|
}
|
|
|
|
else
|
2002-07-31 00:40:34 +08:00
|
|
|
return res;
|
2002-09-05 04:31:48 +08:00
|
|
|
an--;
|
|
|
|
bn--;
|
2002-07-31 00:40:34 +08:00
|
|
|
al = LEVEL_NEXT(al);
|
|
|
|
ql = LQL_NEXT(ql);
|
|
|
|
}
|
|
|
|
|
2006-08-08 01:39:04 +08:00
|
|
|
return Min(t->numlevel, q->firstgood) - q->firstgood;
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2009-06-11 22:49:15 +08:00
|
|
|
gist_between(ltree_gist *key, lquery *query)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
|
|
|
if (query->firstgood == 0)
|
2002-07-31 00:40:34 +08:00
|
|
|
return true;
|
|
|
|
|
2006-08-08 01:39:04 +08:00
|
|
|
if (gist_tqcmp(LTG_GETLNODE(key), query) > 0)
|
|
|
|
return false;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2006-08-08 01:39:04 +08:00
|
|
|
if (gist_tqcmp(LTG_GETRNODE(key), query) < 0)
|
|
|
|
return false;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2006-08-08 01:39:04 +08:00
|
|
|
return true;
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2009-06-11 22:49:15 +08:00
|
|
|
checkcondition_bit(void *checkval, ITEM *val)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
|
|
|
return (FLG_CANLOOKSIGN(val->flag)) ? GETBIT(checkval, HASHVAL(val->val)) : true;
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2009-06-11 22:49:15 +08:00
|
|
|
gist_qtxt(ltree_gist *key, ltxtquery *query)
|
2002-09-05 04:31:48 +08:00
|
|
|
{
|
|
|
|
if (LTG_ISALLTRUE(key))
|
2002-07-31 00:40:34 +08:00
|
|
|
return true;
|
2002-09-05 04:31:48 +08:00
|
|
|
|
2002-08-11 04:46:24 +08:00
|
|
|
return ltree_execute(
|
2002-09-05 04:31:48 +08:00
|
|
|
GETQUERY(query),
|
|
|
|
(void *) LTG_SIGN(key), false,
|
|
|
|
checkcondition_bit
|
|
|
|
);
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
2003-02-19 11:50:09 +08:00
|
|
|
static bool
|
2009-06-11 22:49:15 +08:00
|
|
|
arrq_cons(ltree_gist *key, ArrayType *_query)
|
2004-08-29 13:07:03 +08:00
|
|
|
{
|
|
|
|
lquery *query = (lquery *) ARR_DATA_PTR(_query);
|
|
|
|
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
|
2003-02-19 11:50:09 +08:00
|
|
|
|
2010-02-25 02:02:24 +08:00
|
|
|
if (ARR_NDIM(_query) > 1)
|
2004-08-29 13:07:03 +08:00
|
|
|
ereport(ERROR,
|
2003-07-25 01:52:50 +08:00
|
|
|
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
|
|
|
|
errmsg("array must be one-dimensional")));
|
2011-01-10 02:09:07 +08:00
|
|
|
if (array_contains_nulls(_query))
|
2005-11-19 10:08:45 +08:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
|
|
|
|
errmsg("array must not contain nulls")));
|
2003-02-19 11:50:09 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
while (num > 0)
|
|
|
|
{
|
|
|
|
if (gist_qe(key, query) && gist_between(key, query))
|
|
|
|
return true;
|
|
|
|
num--;
|
|
|
|
query = NEXTVAL(query);
|
|
|
|
}
|
2003-02-19 11:50:09 +08:00
|
|
|
return false;
|
|
|
|
}
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
Datum
|
|
|
|
ltree_consistent(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
2002-07-31 00:40:34 +08:00
|
|
|
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2008-04-15 01:05:34 +08:00
|
|
|
/* Oid subtype = PG_GETARG_OID(3); */
|
|
|
|
bool *recheck = (bool *) PG_GETARG_POINTER(4);
|
|
|
|
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
|
|
|
|
void *query = NULL;
|
2002-09-05 04:31:48 +08:00
|
|
|
bool res = false;
|
2002-07-31 00:40:34 +08:00
|
|
|
|
2008-04-15 01:05:34 +08:00
|
|
|
/* All cases served by this function are exact */
|
|
|
|
*recheck = false;
|
|
|
|
|
2002-09-05 04:31:48 +08:00
|
|
|
switch (strategy)
|
|
|
|
{
|
2002-07-31 00:40:34 +08:00
|
|
|
case BTLessStrategyNumber:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTREE_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
res = (GIST_LEAF(entry)) ?
|
|
|
|
(ltree_compare((ltree *) query, LTG_NODE(key)) > 0)
|
2002-07-31 00:40:34 +08:00
|
|
|
:
|
2002-09-05 04:31:48 +08:00
|
|
|
(ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0);
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
case BTLessEqualStrategyNumber:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTREE_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
res = (ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0);
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
case BTEqualStrategyNumber:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTREE_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (GIST_LEAF(entry))
|
|
|
|
res = (ltree_compare((ltree *) query, LTG_NODE(key)) == 0);
|
2002-07-31 00:40:34 +08:00
|
|
|
else
|
|
|
|
res = (
|
2005-10-15 10:49:52 +08:00
|
|
|
ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0
|
2002-09-05 04:31:48 +08:00
|
|
|
&&
|
2005-10-15 10:49:52 +08:00
|
|
|
ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0
|
2002-09-05 04:31:48 +08:00
|
|
|
);
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
case BTGreaterEqualStrategyNumber:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTREE_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
res = (ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0);
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
case BTGreaterStrategyNumber:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTREE_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
res = (GIST_LEAF(entry)) ?
|
|
|
|
(ltree_compare((ltree *) query, LTG_GETRNODE(key)) < 0)
|
2002-07-31 00:40:34 +08:00
|
|
|
:
|
2002-09-05 04:31:48 +08:00
|
|
|
(ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0);
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
case 10:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTREE_P_COPY(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
res = (GIST_LEAF(entry)) ?
|
|
|
|
inner_isparent((ltree *) query, LTG_NODE(key))
|
2002-07-31 00:40:34 +08:00
|
|
|
:
|
2002-09-05 04:31:48 +08:00
|
|
|
gist_isparent(key, (ltree *) query);
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
case 11:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTREE_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
res = (GIST_LEAF(entry)) ?
|
|
|
|
inner_isparent(LTG_NODE(key), (ltree *) query)
|
2002-07-31 00:40:34 +08:00
|
|
|
:
|
2002-09-05 04:31:48 +08:00
|
|
|
gist_ischild(key, (ltree *) query);
|
2002-07-31 00:40:34 +08:00
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
case 13:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LQUERY_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (GIST_LEAF(entry))
|
|
|
|
res = DatumGetBool(DirectFunctionCall2(ltq_regex,
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:35:54 +08:00
|
|
|
PointerGetDatum(LTG_NODE(key)),
|
|
|
|
PointerGetDatum((lquery *) query)
|
2002-09-05 04:31:48 +08:00
|
|
|
));
|
|
|
|
else
|
|
|
|
res = (gist_qe(key, (lquery *) query) && gist_between(key, (lquery *) query));
|
|
|
|
break;
|
2002-07-31 00:40:34 +08:00
|
|
|
case 14:
|
|
|
|
case 15:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_LTXTQUERY_P(1);
|
2002-09-05 04:31:48 +08:00
|
|
|
if (GIST_LEAF(entry))
|
|
|
|
res = DatumGetBool(DirectFunctionCall2(ltxtq_exec,
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:35:54 +08:00
|
|
|
PointerGetDatum(LTG_NODE(key)),
|
2017-09-19 03:21:23 +08:00
|
|
|
PointerGetDatum((ltxtquery *) query)
|
2002-09-05 04:31:48 +08:00
|
|
|
));
|
|
|
|
else
|
|
|
|
res = gist_qtxt(key, (ltxtquery *) query);
|
|
|
|
break;
|
2003-02-19 11:50:09 +08:00
|
|
|
case 16:
|
|
|
|
case 17:
|
2017-09-19 03:21:23 +08:00
|
|
|
query = PG_GETARG_ARRAYTYPE_P(1);
|
2003-02-19 11:50:09 +08:00
|
|
|
if (GIST_LEAF(entry))
|
|
|
|
res = DatumGetBool(DirectFunctionCall2(lt_q_regex,
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-22 03:35:54 +08:00
|
|
|
PointerGetDatum(LTG_NODE(key)),
|
|
|
|
PointerGetDatum((ArrayType *) query)
|
2003-02-19 11:50:09 +08:00
|
|
|
));
|
|
|
|
else
|
|
|
|
res = arrq_cons(key, (ArrayType *) query);
|
|
|
|
break;
|
2002-07-31 00:40:34 +08:00
|
|
|
default:
|
2003-07-25 01:52:50 +08:00
|
|
|
/* internal error */
|
|
|
|
elog(ERROR, "unrecognized StrategyNumber: %d", strategy);
|
2002-07-31 00:40:34 +08:00
|
|
|
}
|
2006-07-12 00:00:44 +08:00
|
|
|
|
2006-10-04 08:30:14 +08:00
|
|
|
PG_FREE_IF_COPY(query, 1);
|
2002-07-31 00:40:34 +08:00
|
|
|
PG_RETURN_BOOL(res);
|
|
|
|
}
|