PostgreSQL Source Code  git master
ltree_gist.c File Reference
#include "postgres.h"
#include "access/gist.h"
#include "access/reloptions.h"
#include "access/stratnum.h"
#include "crc32.h"
#include "ltree.h"
Include dependency graph for ltree_gist.c:

Go to the source code of this file.

Data Structures

struct  rix
 
struct  LtreeSignature
 

Macros

#define NEXTVAL(x)   ( (lquery*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
 
#define ISEQ(a, b)   ( (a)->numlevel == (b)->numlevel && ltree_compare(a,b)==0 )
 
#define GETENTRY(vec, pos)   ((ltree_gist *) DatumGetPointer((vec)->vector[(pos)].key))
 

Typedefs

typedef struct rix RIX
 
typedef struct LtreeSignature LtreeSignature
 

Functions

 PG_FUNCTION_INFO_V1 (ltree_gist_in)
 
 PG_FUNCTION_INFO_V1 (ltree_gist_out)
 
Datum ltree_gist_in (PG_FUNCTION_ARGS)
 
Datum ltree_gist_out (PG_FUNCTION_ARGS)
 
ltree_gistltree_gist_alloc (bool isalltrue, BITVECP sign, int siglen, ltree *left, ltree *right)
 
 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)
 
 PG_FUNCTION_INFO_V1 (ltree_gist_options)
 
Datum ltree_compress (PG_FUNCTION_ARGS)
 
Datum ltree_decompress (PG_FUNCTION_ARGS)
 
Datum ltree_same (PG_FUNCTION_ARGS)
 
static void hashing (BITVECP sign, ltree *t, int siglen)
 
Datum ltree_union (PG_FUNCTION_ARGS)
 
Datum ltree_penalty (PG_FUNCTION_ARGS)
 
static int treekey_cmp (const void *a, const void *b)
 
Datum ltree_picksplit (PG_FUNCTION_ARGS)
 
static bool gist_isparent (ltree_gist *key, ltree *query, int siglen)
 
static ltreecopy_ltree (ltree *src)
 
static bool gist_ischild (ltree_gist *key, ltree *query, int siglen)
 
static bool gist_qe (ltree_gist *key, lquery *query, int siglen)
 
static int gist_tqcmp (ltree *t, lquery *q)
 
static bool gist_between (ltree_gist *key, lquery *query, int siglen)
 
static bool checkcondition_bit (void *cxt, ITEM *val)
 
static bool gist_qtxt (ltree_gist *key, ltxtquery *query, int siglen)
 
static bool arrq_cons (ltree_gist *key, ArrayType *_query, int siglen)
 
Datum ltree_consistent (PG_FUNCTION_ARGS)
 
Datum ltree_gist_options (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ GETENTRY

#define GETENTRY (   vec,
  pos 
)    ((ltree_gist *) DatumGetPointer((vec)->vector[(pos)].key))

Definition at line 88 of file ltree_gist.c.

Referenced by ltree_picksplit(), and ltree_union().

◆ ISEQ

#define ISEQ (   a,
 
)    ( (a)->numlevel == (b)->numlevel && ltree_compare(a,b)==0 )

Definition at line 15 of file ltree_gist.c.

Referenced by ltree_gist_alloc(), and ltree_same().

◆ NEXTVAL

#define NEXTVAL (   x)    ( (lquery*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )

Definition at line 14 of file ltree_gist.c.

Referenced by arrq_cons().

Typedef Documentation

◆ LtreeSignature

◆ RIX

typedef struct rix RIX

Function Documentation

◆ arrq_cons()

static bool arrq_cons ( ltree_gist key,
ArrayType _query,
int  siglen 
)
static

Definition at line 589 of file ltree_gist.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), ArrayGetNItems(), ereport, errcode(), errmsg(), ERROR, gist_between(), gist_qe(), and NEXTVAL.

Referenced by ltree_consistent().

590 {
591  lquery *query = (lquery *) ARR_DATA_PTR(_query);
592  int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
593 
594  if (ARR_NDIM(_query) > 1)
595  ereport(ERROR,
596  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
597  errmsg("array must be one-dimensional")));
598  if (array_contains_nulls(_query))
599  ereport(ERROR,
600  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
601  errmsg("array must not contain nulls")));
602 
603  while (num > 0)
604  {
605  if (gist_qe(key, query, siglen) && gist_between(key, query, siglen))
606  return true;
607  num--;
608  query = NEXTVAL(query);
609  }
610  return false;
611 }
Definition: ltree.h:100
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:282
#define ARR_DATA_PTR(a)
Definition: array.h:310
static bool gist_qe(ltree_gist *key, lquery *query, int siglen)
Definition: ltree_gist.c:476
static bool gist_between(ltree_gist *key, lquery *query, int siglen)
Definition: ltree_gist.c:544
#define ereport(elevel,...)
Definition: elog.h:144
#define NEXTVAL(x)
Definition: ltree_gist.c:14
#define ARR_NDIM(a)
Definition: array.h:278
int errmsg(const char *fmt,...)
Definition: elog.c:824
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3529

◆ checkcondition_bit()

static bool checkcondition_bit ( void *  cxt,
ITEM val 
)
static

Definition at line 565 of file ltree_gist.c.

References ITEM::flag, FLG_CANLOOKSIGN, GETBIT, HASHVAL, sig, LtreeSignature::siglen, LtreeSignature::sign, and ITEM::val.

Referenced by gist_qtxt().

566 {
567  LtreeSignature *sig = cxt;
568 
569  return (FLG_CANLOOKSIGN(val->flag)) ? GETBIT(sig->sign, HASHVAL(val->val, sig->siglen)) : true;
570 }
uint8 flag
Definition: ltree.h:129
#define true
Definition: c.h:321
#define GETBIT(x, i)
Definition: blutils.c:33
int32 val
Definition: _int.h:144
static int sig
Definition: pg_ctl.c:84
#define HASHVAL(val, siglen)
Definition: hstore_gist.c:44
#define FLG_CANLOOKSIGN(x)
Definition: ltree.h:96

◆ copy_ltree()

static ltree* copy_ltree ( ltree src)
static

Definition at line 442 of file ltree_gist.c.

References palloc0(), and VARSIZE.

Referenced by gist_ischild().

443 {
444  ltree *dst = (ltree *) palloc0(VARSIZE(src));
445 
446  memcpy(dst, src, VARSIZE(src));
447  return dst;
448 }
#define VARSIZE(PTR)
Definition: postgres.h:303
Definition: ltree.h:29
void * palloc0(Size size)
Definition: mcxt.c:980

◆ gist_between()

static bool gist_between ( ltree_gist key,
lquery query,
int  siglen 
)
static

Definition at line 544 of file ltree_gist.c.

References lquery::firstgood, gist_tqcmp(), LTG_GETLNODE, LTG_GETRNODE, and sign.

Referenced by arrq_cons(), and ltree_consistent().

545 {
546  if (query->firstgood == 0)
547  return true;
548 
549  if (gist_tqcmp(LTG_GETLNODE(key, siglen), query) > 0)
550  return false;
551 
552  if (gist_tqcmp(LTG_GETRNODE(key, siglen), query) < 0)
553  return false;
554 
555  return true;
556 }
uint16 firstgood
Definition: ltree.h:104
#define LTG_GETRNODE(x, siglen)
Definition: ltree.h:272
static int gist_tqcmp(ltree *t, lquery *q)
Definition: ltree_gist.c:515
#define LTG_GETLNODE(x, siglen)
Definition: ltree.h:271

◆ gist_ischild()

static bool gist_ischild ( ltree_gist key,
ltree query,
int  siglen 
)
static

Definition at line 451 of file ltree_gist.c.

References copy_ltree(), LTG_GETLNODE, LTG_GETRNODE, ltree_compare(), ltree::numlevel, and pfree().

Referenced by ltree_consistent().

452 {
453  ltree *left = copy_ltree(LTG_GETLNODE(key, siglen));
454  ltree *right = copy_ltree(LTG_GETRNODE(key, siglen));
455  bool res = true;
456 
457  if (left->numlevel > query->numlevel)
458  left->numlevel = query->numlevel;
459 
460  if (ltree_compare(query, left) < 0)
461  res = false;
462 
463  if (right->numlevel > query->numlevel)
464  right->numlevel = query->numlevel;
465 
466  if (res && ltree_compare(query, right) > 0)
467  res = false;
468 
469  pfree(left);
470  pfree(right);
471 
472  return res;
473 }
#define LTG_GETRNODE(x, siglen)
Definition: ltree.h:272
void pfree(void *pointer)
Definition: mcxt.c:1056
static ltree * copy_ltree(ltree *src)
Definition: ltree_gist.c:442
Definition: ltree.h:29
uint16 numlevel
Definition: ltree.h:32
#define LTG_GETLNODE(x, siglen)
Definition: ltree.h:271
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42

◆ gist_isparent()

static bool gist_isparent ( ltree_gist key,
ltree query,
int  siglen 
)
static

Definition at line 421 of file ltree_gist.c.

References i, LTG_GETLNODE, LTG_GETRNODE, ltree_compare(), and ltree::numlevel.

Referenced by ltree_consistent().

422 {
423  int32 numlevel = query->numlevel;
424  int i;
425 
426  for (i = query->numlevel; i >= 0; i--)
427  {
428  query->numlevel = i;
429  if (ltree_compare(query, LTG_GETLNODE(key, siglen)) >= 0 &&
430  ltree_compare(query, LTG_GETRNODE(key, siglen)) <= 0)
431  {
432  query->numlevel = numlevel;
433  return true;
434  }
435  }
436 
437  query->numlevel = numlevel;
438  return false;
439 }
#define LTG_GETRNODE(x, siglen)
Definition: ltree.h:272
signed int int32
Definition: c.h:355
uint16 numlevel
Definition: ltree.h:32
#define LTG_GETLNODE(x, siglen)
Definition: ltree.h:271
int i
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42

◆ gist_qe()

static bool gist_qe ( ltree_gist key,
lquery query,
int  siglen 
)
static

Definition at line 476 of file ltree_gist.c.

References GETBIT, HASHVAL, LQL_CANLOOKSIGN, LQL_FIRST, LQL_NEXT, LQUERY_FIRST, LTG_ISALLTRUE, LTG_SIGN, LVAR_NEXT, lquery::numlevel, lquery_level::numvar, sign, and lquery_variant::val.

Referenced by arrq_cons(), and ltree_consistent().

477 {
478  lquery_level *curq = LQUERY_FIRST(query);
479  BITVECP sign = LTG_SIGN(key);
480  int qlen = query->numlevel;
481 
482  if (LTG_ISALLTRUE(key))
483  return true;
484 
485  while (qlen > 0)
486  {
487  if (curq->numvar && LQL_CANLOOKSIGN(curq))
488  {
489  bool isexist = false;
490  int vlen = curq->numvar;
491  lquery_variant *curv = LQL_FIRST(curq);
492 
493  while (vlen > 0)
494  {
495  if (GETBIT(sign, HASHVAL(curv->val, siglen)))
496  {
497  isexist = true;
498  break;
499  }
500  curv = LVAR_NEXT(curv);
501  vlen--;
502  }
503  if (!isexist)
504  return false;
505  }
506 
507  curq = LQL_NEXT(curq);
508  qlen--;
509  }
510 
511  return true;
512 }
#define LQUERY_FIRST(x)
Definition: ltree.h:111
#define LTG_ISALLTRUE(x)
Definition: ltree.h:265
#define LTG_SIGN(x)
Definition: ltree.h:262
#define LQL_FIRST(x)
Definition: ltree.h:88
#define LQL_NEXT(x)
Definition: ltree.h:87
#define LVAR_NEXT(x)
Definition: ltree.h:59
#define GETBIT(x, i)
Definition: blutils.c:33
char sign
Definition: informix.c:668
int32 val
Definition: ltree.h:47
#define HASHVAL(val, siglen)
Definition: hstore_gist.c:44
uint16 numlevel
Definition: ltree.h:103
uint16 numvar
Definition: ltree.h:79
char * BITVECP
Definition: hstore_gist.c:30
#define LQL_CANLOOKSIGN(x)
Definition: ltree.h:98

◆ gist_qtxt()

static bool gist_qtxt ( ltree_gist key,
ltxtquery query,
int  siglen 
)
static

Definition at line 573 of file ltree_gist.c.

References checkcondition_bit(), GETQUERY, LTG_ISALLTRUE, LTG_SIGN, ltree_execute(), sig, LtreeSignature::siglen, and LtreeSignature::sign.

Referenced by ltree_consistent().

574 {
576 
577  if (LTG_ISALLTRUE(key))
578  return true;
579 
580  sig.sign = LTG_SIGN(key);
581  sig.siglen = siglen;
582 
583  return ltree_execute(GETQUERY(query),
584  &sig, false,
586 }
#define LTG_ISALLTRUE(x)
Definition: ltree.h:265
#define LTG_SIGN(x)
Definition: ltree.h:262
#define GETQUERY(x)
Definition: _int.h:157
bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
Definition: ltxtquery_op.c:20
static bool checkcondition_bit(void *cxt, ITEM *val)
Definition: ltree_gist.c:565
static int sig
Definition: pg_ctl.c:84

◆ gist_tqcmp()

static int gist_tqcmp ( ltree t,
lquery q 
)
static

Definition at line 515 of file ltree_gist.c.

References lquery::firstgood, ltree_level::len, lquery_variant::len, LEVEL_NEXT, LQL_FIRST, LQL_NEXT, LQUERY_FIRST, LTREE_FIRST, Min, ltree_level::name, lquery_variant::name, and ltree::numlevel.

Referenced by gist_between().

516 {
517  ltree_level *al = LTREE_FIRST(t);
518  lquery_level *ql = LQUERY_FIRST(q);
519  lquery_variant *bl;
520  int an = t->numlevel;
521  int bn = q->firstgood;
522  int res = 0;
523 
524  while (an > 0 && bn > 0)
525  {
526  bl = LQL_FIRST(ql);
527  if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
528  {
529  if (al->len != bl->len)
530  return al->len - bl->len;
531  }
532  else
533  return res;
534  an--;
535  bn--;
536  al = LEVEL_NEXT(al);
537  ql = LQL_NEXT(ql);
538  }
539 
540  return Min(t->numlevel, q->firstgood) - q->firstgood;
541 }
uint16 firstgood
Definition: ltree.h:104
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:23
#define LQUERY_FIRST(x)
Definition: ltree.h:111
uint16 len
Definition: ltree.h:48
uint16 len
Definition: ltree.h:22
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:50
#define Min(x, y)
Definition: c.h:920
#define LQL_FIRST(x)
Definition: ltree.h:88
#define LQL_NEXT(x)
Definition: ltree.h:87
#define LEVEL_NEXT(x)
Definition: ltree.h:27
uint16 numlevel
Definition: ltree.h:32
#define LTREE_FIRST(x)
Definition: ltree.h:38

◆ hashing()

static void hashing ( BITVECP  sign,
ltree t,
int  siglen 
)
static

Definition at line 173 of file ltree_gist.c.

References cur, HASH, hash(), ltree_level::len, LEVEL_NEXT, ltree_crc32_sz(), LTREE_FIRST, ltree_level::name, and ltree::numlevel.

Referenced by ltree_picksplit(), and ltree_union().

174 {
175  int tlen = t->numlevel;
177  int hash;
178 
179  while (tlen > 0)
180  {
181  hash = ltree_crc32_sz(cur->name, cur->len);
182  HASH(sign, hash, siglen);
183  cur = LEVEL_NEXT(cur);
184  tlen--;
185  }
186 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:23
unsigned int ltree_crc32_sz(const char *buf, int size)
Definition: crc32.c:23
uint16 len
Definition: ltree.h:22
struct cursor * cur
Definition: ecpg.c:28
#define HASH(sign, val, siglen)
Definition: hstore_gist.c:45
char sign
Definition: informix.c:668
#define LEVEL_NEXT(x)
Definition: ltree.h:27
uint16 numlevel
Definition: ltree.h:32
#define LTREE_FIRST(x)
Definition: ltree.h:38
static unsigned hash(unsigned *uv, int n)
Definition: rege_dfa.c:541

◆ ltree_compress()

Datum ltree_compress ( PG_FUNCTION_ARGS  )

Definition at line 91 of file ltree_gist.c.

References DatumGetLtreeP, gistentryinit, sort-test::key, GISTENTRY::key, GISTENTRY::leafkey, ltree_gist_alloc(), GISTENTRY::offset, GISTENTRY::page, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, GISTENTRY::rel, and val.

Referenced by ltree_gist_alloc().

92 {
93  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
94  GISTENTRY *retval = entry;
95 
96  if (entry->leafkey)
97  { /* ltree */
98  ltree *val = DatumGetLtreeP(entry->key);
99  ltree_gist *key = ltree_gist_alloc(false, NULL, 0, val, 0);
100 
101  retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
102  gistentryinit(*retval, PointerGetDatum(key),
103  entry->rel, entry->page,
104  entry->offset, false);
105  }
106  PG_RETURN_POINTER(retval);
107 }
Relation rel
Definition: gist.h:152
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
Page page
Definition: gist.h:153
Datum key
Definition: gist.h:151
Definition: ltree.h:29
bool leafkey
Definition: gist.h:155
#define DatumGetLtreeP(X)
Definition: ltree.h:202
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:235
void * palloc(Size size)
Definition: mcxt.c:949
OffsetNumber offset
Definition: gist.h:154
long val
Definition: informix.c:664
ltree_gist * ltree_gist_alloc(bool isalltrue, BITVECP sign, int siglen, ltree *left, ltree *right)
Definition: ltree_gist.c:39

◆ ltree_consistent()

Datum ltree_consistent ( PG_FUNCTION_ARGS  )

Definition at line 614 of file ltree_gist.c.

References arrq_cons(), BTEqualStrategyNumber, BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, DatumGetBool, DatumGetPointer, DirectFunctionCall2, elog, ERROR, gist_between(), gist_ischild(), gist_isparent(), GIST_LEAF, gist_qe(), gist_qtxt(), inner_isparent(), sort-test::key, GISTENTRY::key, lt_q_regex(), LTG_GETLNODE, LTG_GETRNODE, LTG_NODE, ltq_regex(), ltree_compare(), LTREE_GET_ASIGLEN, ltxtq_exec(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LQUERY_P, PG_GETARG_LTREE_P, PG_GETARG_LTREE_P_COPY, PG_GETARG_LTXTQUERY_P, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, and PointerGetDatum.

Referenced by ltree_gist_alloc().

615 {
616  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
618 
619  /* Oid subtype = PG_GETARG_OID(3); */
620  bool *recheck = (bool *) PG_GETARG_POINTER(4);
621  int siglen = LTREE_GET_ASIGLEN();
623  void *query = NULL;
624  bool res = false;
625 
626  /* All cases served by this function are exact */
627  *recheck = false;
628 
629  switch (strategy)
630  {
632  query = PG_GETARG_LTREE_P(1);
633  res = (GIST_LEAF(entry)) ?
634  (ltree_compare((ltree *) query, LTG_NODE(key)) > 0)
635  :
636  (ltree_compare((ltree *) query, LTG_GETLNODE(key, siglen)) >= 0);
637  break;
639  query = PG_GETARG_LTREE_P(1);
640  res = (ltree_compare((ltree *) query, LTG_GETLNODE(key, siglen)) >= 0);
641  break;
643  query = PG_GETARG_LTREE_P(1);
644  if (GIST_LEAF(entry))
645  res = (ltree_compare((ltree *) query, LTG_NODE(key)) == 0);
646  else
647  res = (ltree_compare((ltree *) query, LTG_GETLNODE(key, siglen)) >= 0
648  &&
649  ltree_compare((ltree *) query, LTG_GETRNODE(key, siglen)) <= 0);
650  break;
652  query = PG_GETARG_LTREE_P(1);
653  res = (ltree_compare((ltree *) query, LTG_GETRNODE(key, siglen)) <= 0);
654  break;
656  query = PG_GETARG_LTREE_P(1);
657  res = (GIST_LEAF(entry)) ?
658  (ltree_compare((ltree *) query, LTG_GETRNODE(key, siglen)) < 0)
659  :
660  (ltree_compare((ltree *) query, LTG_GETRNODE(key, siglen)) <= 0);
661  break;
662  case 10:
663  query = PG_GETARG_LTREE_P_COPY(1);
664  res = (GIST_LEAF(entry)) ?
665  inner_isparent((ltree *) query, LTG_NODE(key))
666  :
667  gist_isparent(key, (ltree *) query, siglen);
668  break;
669  case 11:
670  query = PG_GETARG_LTREE_P(1);
671  res = (GIST_LEAF(entry)) ?
672  inner_isparent(LTG_NODE(key), (ltree *) query)
673  :
674  gist_ischild(key, (ltree *) query, siglen);
675  break;
676  case 12:
677  case 13:
678  query = PG_GETARG_LQUERY_P(1);
679  if (GIST_LEAF(entry))
682  PointerGetDatum((lquery *) query)
683  ));
684  else
685  res = (gist_qe(key, (lquery *) query, siglen) &&
686  gist_between(key, (lquery *) query, siglen));
687  break;
688  case 14:
689  case 15:
690  query = PG_GETARG_LTXTQUERY_P(1);
691  if (GIST_LEAF(entry))
694  PointerGetDatum((ltxtquery *) query)
695  ));
696  else
697  res = gist_qtxt(key, (ltxtquery *) query, siglen);
698  break;
699  case 16:
700  case 17:
701  query = PG_GETARG_ARRAYTYPE_P(1);
702  if (GIST_LEAF(entry))
705  PointerGetDatum((ArrayType *) query)
706  ));
707  else
708  res = arrq_cons(key, (ArrayType *) query, siglen);
709  break;
710  default:
711  /* internal error */
712  elog(ERROR, "unrecognized StrategyNumber: %d", strategy);
713  }
714 
715  PG_FREE_IF_COPY(query, 1);
716  PG_RETURN_BOOL(res);
717 }
#define GIST_LEAF(entry)
Definition: gist.h:161
static bool arrq_cons(ltree_gist *key, ArrayType *_query, int siglen)
Definition: ltree_gist.c:589
#define PG_GETARG_LTREE_P_COPY(n)
Definition: ltree.h:205
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
#define LTG_GETRNODE(x, siglen)
Definition: ltree.h:272
static bool gist_qtxt(ltree_gist *key, ltxtquery *query, int siglen)
Definition: ltree_gist.c:573
#define PointerGetDatum(X)
Definition: postgres.h:556
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:143
Definition: ltree.h:100
uint16 StrategyNumber
Definition: stratnum.h:22
#define LTG_NODE(x)
Definition: ltree.h:263
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static bool gist_isparent(ltree_gist *key, ltree *query, int siglen)
Definition: ltree_gist.c:421
static bool gist_ischild(ltree_gist *key, ltree *query, int siglen)
Definition: ltree_gist.c:451
#define PG_GETARG_LQUERY_P(n)
Definition: ltree.h:209
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
#define LTREE_GET_ASIGLEN()
Definition: ltree.h:281
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define ERROR
Definition: elog.h:43
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:215
Datum key
Definition: gist.h:151
#define DatumGetBool(X)
Definition: postgres.h:393
static bool gist_qe(ltree_gist *key, lquery *query, int siglen)
Definition: ltree_gist.c:476
Definition: ltree.h:29
Datum lt_q_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:239
static bool gist_between(ltree_gist *key, lquery *query, int siglen)
Definition: ltree_gist.c:544
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define LTG_GETLNODE(x, siglen)
Definition: ltree.h:271
Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:84
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_GETARG_LTXTQUERY_P(n)
Definition: ltree.h:214
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:214
#define BTLessStrategyNumber
Definition: stratnum.h:29
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define BTGreaterEqualStrategyNumber
Definition: stratnum.h:32

◆ ltree_decompress()

Datum ltree_decompress ( PG_FUNCTION_ARGS  )

Definition at line 110 of file ltree_gist.c.

References gistentryinit, sort-test::key, GISTENTRY::key, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_DETOAST_DATUM, PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, and GISTENTRY::rel.

Referenced by ltree_gist_alloc().

111 {
112  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
114 
115  if (PointerGetDatum(key) != entry->key)
116  {
117  GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
118 
119  gistentryinit(*retval, PointerGetDatum(key),
120  entry->rel, entry->page,
121  entry->offset, false);
122  PG_RETURN_POINTER(retval);
123  }
124  PG_RETURN_POINTER(entry);
125 }
Relation rel
Definition: gist.h:152
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
Page page
Definition: gist.h:153
Datum key
Definition: gist.h:151
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:235
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
OffsetNumber offset
Definition: gist.h:154

◆ ltree_gist_alloc()

ltree_gist* ltree_gist_alloc ( bool  isalltrue,
BITVECP  sign,
int  siglen,
ltree left,
ltree right 
)

Definition at line 39 of file ltree_gist.c.

References Assert, ltree_gist::flag, ISEQ, LTG_ALLTRUE, LTG_HDRSIZE, LTG_LNODE, LTG_NODE, LTG_NORIGHT, LTG_ONENODE, LTG_RNODE, LTG_SIGN, ltree_compress(), ltree_consistent(), ltree_decompress(), ltree_gist_options(), ltree_penalty(), ltree_picksplit(), ltree_same(), ltree_union(), palloc(), PG_FUNCTION_INFO_V1(), SET_VARSIZE, and VARSIZE.

Referenced by _ltree_compress(), _ltree_picksplit(), _ltree_union(), ltree_compress(), ltree_picksplit(), and ltree_union().

41 {
42  int32 size = LTG_HDRSIZE + (isalltrue ? 0 : siglen) +
43  (left ? VARSIZE(left) + (right ? VARSIZE(right) : 0) : 0);
44  ltree_gist *result = palloc(size);
45 
46  SET_VARSIZE(result, size);
47 
48  if (siglen)
49  {
50  result->flag = 0;
51 
52  if (isalltrue)
53  result->flag |= LTG_ALLTRUE;
54  else if (sign)
55  memcpy(LTG_SIGN(result), sign, siglen);
56  else
57  memset(LTG_SIGN(result), 0, siglen);
58 
59  if (left)
60  {
61  memcpy(LTG_LNODE(result, siglen), left, VARSIZE(left));
62 
63  if (!right || left == right || ISEQ(left, right))
64  result->flag |= LTG_NORIGHT;
65  else
66  memcpy(LTG_RNODE(result, siglen), right, VARSIZE(right));
67  }
68  }
69  else
70  {
71  Assert(left);
72  result->flag = LTG_ONENODE;
73  memcpy(LTG_NODE(result), left, VARSIZE(left));
74  }
75 
76  return result;
77 }
#define VARSIZE(PTR)
Definition: postgres.h:303
#define LTG_SIGN(x)
Definition: ltree.h:262
uint32 flag
Definition: ltree.h:253
#define LTG_NODE(x)
Definition: ltree.h:263
#define LTG_NORIGHT
Definition: ltree.h:259
#define LTG_LNODE(x, siglen)
Definition: ltree.h:267
signed int int32
Definition: c.h:355
#define LTG_RNODE(x, siglen)
Definition: ltree.h:269
char sign
Definition: informix.c:668
#define LTG_ALLTRUE
Definition: ltree.h:258
#define ISEQ(a, b)
Definition: ltree_gist.c:15
#define Assert(condition)
Definition: c.h:738
void * palloc(Size size)
Definition: mcxt.c:949
#define LTG_ONENODE
Definition: ltree.h:257
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define LTG_HDRSIZE
Definition: ltree.h:261

◆ ltree_gist_in()

Datum ltree_gist_in ( PG_FUNCTION_ARGS  )

Definition at line 21 of file ltree_gist.c.

References ereport, errcode(), errmsg(), ERROR, and PG_RETURN_DATUM.

22 {
23  ereport(ERROR,
24  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
25  errmsg("ltree_gist_in() not implemented")));
26  PG_RETURN_DATUM(0);
27 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:352
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ltree_gist_options()

Datum ltree_gist_options ( PG_FUNCTION_ARGS  )

Definition at line 720 of file ltree_gist.c.

References add_local_int_reloption(), init_local_reloptions(), offsetof, PG_GETARG_POINTER, PG_RETURN_VOID, SIGLEN_DEFAULT, and SIGLEN_MAX.

Referenced by ltree_gist_alloc().

721 {
723 
724  init_local_reloptions(relopts, sizeof(LtreeGistOptions));
725  add_local_int_reloption(relopts, "siglen",
726  "signature length in bytes",
728  offsetof(LtreeGistOptions, siglen));
729 
730  PG_RETURN_VOID();
731 }
void init_local_reloptions(local_relopts *opts, Size relopt_struct_size)
Definition: reloptions.c:710
#define SIGLEN_MAX
Definition: hstore_gist.c:23
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
void add_local_int_reloption(local_relopts *relopts, const char *name, const char *desc, int default_val, int min_val, int max_val, int offset)
Definition: reloptions.c:894
#define SIGLEN_DEFAULT
Definition: hstore_gist.c:22
#define PG_RETURN_VOID()
Definition: fmgr.h:348
#define offsetof(type, field)
Definition: c.h:661

◆ ltree_gist_out()

Datum ltree_gist_out ( PG_FUNCTION_ARGS  )

Definition at line 30 of file ltree_gist.c.

References ereport, errcode(), errmsg(), ERROR, and PG_RETURN_DATUM.

31 {
32  ereport(ERROR,
33  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
34  errmsg("ltree_gist_out() not implemented")));
35  PG_RETURN_DATUM(0);
36 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:352
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ltree_penalty()

Datum ltree_penalty ( PG_FUNCTION_ARGS  )

Definition at line 258 of file ltree_gist.c.

References DatumGetPointer, sort-test::key, LTG_GETLNODE, LTG_GETRNODE, ltree_compare(), LTREE_GET_ASIGLEN, Max, newval, PG_GETARG_POINTER, and PG_RETURN_POINTER.

Referenced by ltree_gist_alloc().

259 {
260  ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
262  float *penalty = (float *) PG_GETARG_POINTER(2);
263  int siglen = LTREE_GET_ASIGLEN();
264  int32 cmpr,
265  cmpl;
266 
267  cmpl = ltree_compare(LTG_GETLNODE(origval, siglen), LTG_GETLNODE(newval, siglen));
268  cmpr = ltree_compare(LTG_GETRNODE(newval, siglen), LTG_GETRNODE(origval, siglen));
269 
270  *penalty = Max(cmpl, 0) + Max(cmpr, 0);
271 
272  PG_RETURN_POINTER(penalty);
273 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define LTG_GETRNODE(x, siglen)
Definition: ltree.h:272
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
signed int int32
Definition: c.h:355
#define LTREE_GET_ASIGLEN()
Definition: ltree.h:281
#define LTG_GETLNODE(x, siglen)
Definition: ltree.h:271
#define Max(x, y)
Definition: c.h:914
#define newval
#define DatumGetPointer(X)
Definition: postgres.h:549
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42

◆ ltree_picksplit()

Datum ltree_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 291 of file ltree_gist.c.

References FirstOffsetNumber, GETENTRY, hashing(), i, rix::index, LOOPBYTE, LTG_GETLNODE, LTG_GETRNODE, LTG_ISALLTRUE, LTG_ISONENODE, LTG_NODE, LTG_SIGN, ltree_compare(), LTREE_GET_ASIGLEN, ltree_gist_alloc(), GistEntryVector::n, OffsetNumberNext, palloc(), palloc0(), pfree(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, qsort, rix::r, GIST_SPLITVEC::spl_ldatum, GIST_SPLITVEC::spl_left, GIST_SPLITVEC::spl_nleft, GIST_SPLITVEC::spl_nright, GIST_SPLITVEC::spl_rdatum, GIST_SPLITVEC::spl_right, and treekey_cmp().

Referenced by ltree_gist_alloc().

292 {
295  int siglen = LTREE_GET_ASIGLEN();
296  OffsetNumber j;
297  int32 i;
298  RIX *array;
299  OffsetNumber maxoff;
300  int nbytes;
301  ltree *lu_l,
302  *lu_r,
303  *ru_l,
304  *ru_r;
305  ltree_gist *lu,
306  *ru;
307  BITVECP ls = palloc0(siglen),
308  rs = palloc0(siglen);
309  bool lisat = false,
310  risat = false;
311 
312  maxoff = entryvec->n - 1;
313  nbytes = (maxoff + 2) * sizeof(OffsetNumber);
314  v->spl_left = (OffsetNumber *) palloc(nbytes);
315  v->spl_right = (OffsetNumber *) palloc(nbytes);
316  v->spl_nleft = 0;
317  v->spl_nright = 0;
318  array = (RIX *) palloc(sizeof(RIX) * (maxoff + 1));
319 
320  /* copy the data into RIXes, and sort the RIXes */
321  for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
322  {
323  array[j].index = j;
324  lu = GETENTRY(entryvec, j); /* use as tmp val */
325  array[j].r = LTG_GETLNODE(lu, siglen);
326  }
327 
328  qsort((void *) &array[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1,
329  sizeof(RIX), treekey_cmp);
330 
331  lu_l = lu_r = ru_l = ru_r = NULL;
332  for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
333  {
334  lu = GETENTRY(entryvec, array[j].index); /* use as tmp val */
335  if (j <= (maxoff - FirstOffsetNumber + 1) / 2)
336  {
337  v->spl_left[v->spl_nleft] = array[j].index;
338  v->spl_nleft++;
339  if (lu_r == NULL || ltree_compare(LTG_GETRNODE(lu, siglen), lu_r) > 0)
340  lu_r = LTG_GETRNODE(lu, siglen);
341  if (LTG_ISONENODE(lu))
342  hashing(ls, LTG_NODE(lu), siglen);
343  else
344  {
345  if (lisat || LTG_ISALLTRUE(lu))
346  lisat = true;
347  else
348  {
349  BITVECP sc = LTG_SIGN(lu);
350 
351  LOOPBYTE(siglen)
352  ((unsigned char *) ls)[i] |= sc[i];
353  }
354  }
355  }
356  else
357  {
358  v->spl_right[v->spl_nright] = array[j].index;
359  v->spl_nright++;
360  if (ru_r == NULL || ltree_compare(LTG_GETRNODE(lu, siglen), ru_r) > 0)
361  ru_r = LTG_GETRNODE(lu, siglen);
362  if (LTG_ISONENODE(lu))
363  hashing(rs, LTG_NODE(lu), siglen);
364  else
365  {
366  if (risat || LTG_ISALLTRUE(lu))
367  risat = true;
368  else
369  {
370  BITVECP sc = LTG_SIGN(lu);
371 
372  LOOPBYTE(siglen)
373  ((unsigned char *) rs)[i] |= sc[i];
374  }
375  }
376  }
377  }
378 
379  if (lisat == false)
380  {
381  lisat = true;
382  LOOPBYTE(siglen)
383  {
384  if (((unsigned char *) ls)[i] != 0xff)
385  {
386  lisat = false;
387  break;
388  }
389  }
390  }
391 
392  if (risat == false)
393  {
394  risat = true;
395  LOOPBYTE(siglen)
396  {
397  if (((unsigned char *) rs)[i] != 0xff)
398  {
399  risat = false;
400  break;
401  }
402  }
403  }
404 
405  lu_l = LTG_GETLNODE(GETENTRY(entryvec, array[FirstOffsetNumber].index), siglen);
406  lu = ltree_gist_alloc(lisat, ls, siglen, lu_l, lu_r);
407 
408  ru_l = LTG_GETLNODE(GETENTRY(entryvec, array[1 + ((maxoff - FirstOffsetNumber + 1) / 2)].index), siglen);
409  ru = ltree_gist_alloc(risat, rs, siglen, ru_l, ru_r);
410 
411  pfree(ls);
412  pfree(rs);
413 
414  v->spl_ldatum = PointerGetDatum(lu);
415  v->spl_rdatum = PointerGetDatum(ru);
416 
418 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
ltree * r
Definition: ltree_gist.c:279
#define LOOPBYTE(siglen)
Definition: hstore_gist.c:32
#define LTG_GETRNODE(x, siglen)
Definition: ltree.h:272
#define LTG_ISALLTRUE(x)
Definition: ltree.h:265
#define PointerGetDatum(X)
Definition: postgres.h:556
#define LTG_SIGN(x)
Definition: ltree.h:262
OffsetNumber * spl_left
Definition: gist.h:133
Datum spl_rdatum
Definition: gist.h:140
int32 n
Definition: gist.h:226
#define LTG_NODE(x)
Definition: ltree.h:263
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
int spl_nleft
Definition: gist.h:134
signed int int32
Definition: c.h:355
uint16 OffsetNumber
Definition: off.h:24
Definition: type.h:89
#define LTREE_GET_ASIGLEN()
Definition: ltree.h:281
void pfree(void *pointer)
Definition: mcxt.c:1056
int spl_nright
Definition: gist.h:139
#define FirstOffsetNumber
Definition: off.h:27
static int treekey_cmp(const void *a, const void *b)
Definition: ltree_gist.c:283
#define GETENTRY(vec, pos)
Definition: ltree_gist.c:88
Definition: ltree.h:29
void * palloc0(Size size)
Definition: mcxt.c:980
static void hashing(BITVECP sign, ltree *t, int siglen)
Definition: ltree_gist.c:173
#define LTG_GETLNODE(x, siglen)
Definition: ltree.h:271
#define LTG_ISONENODE(x)
Definition: ltree.h:264
Datum spl_ldatum
Definition: gist.h:135
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
OffsetNumber * spl_right
Definition: gist.h:138
void * palloc(Size size)
Definition: mcxt.c:949
int i
char * BITVECP
Definition: hstore_gist.c:30
#define qsort(a, b, c, d)
Definition: port.h:479
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42
int index
Definition: ltree_gist.c:278
ltree_gist * ltree_gist_alloc(bool isalltrue, BITVECP sign, int siglen, ltree *left, ltree *right)
Definition: ltree_gist.c:39

◆ ltree_same()

Datum ltree_same ( PG_FUNCTION_ARGS  )

Definition at line 128 of file ltree_gist.c.

References i, ISEQ, LOOPBYTE, LTG_ISALLTRUE, LTG_ISONENODE, LTG_LNODE, LTG_NODE, LTG_RNODE, LTG_SIGN, LTREE_GET_ASIGLEN, PG_GETARG_POINTER, and PG_RETURN_POINTER.

Referenced by ltree_gist_alloc().

129 {
132  bool *result = (bool *) PG_GETARG_POINTER(2);
133  int siglen = LTREE_GET_ASIGLEN();
134 
135  *result = false;
136  if (LTG_ISONENODE(a) != LTG_ISONENODE(b))
137  PG_RETURN_POINTER(result);
138 
139  if (LTG_ISONENODE(a))
140  *result = (ISEQ(LTG_NODE(a), LTG_NODE(b))) ? true : false;
141  else
142  {
143  int32 i;
144  BITVECP sa = LTG_SIGN(a),
145  sb = LTG_SIGN(b);
146 
147  if (LTG_ISALLTRUE(a) != LTG_ISALLTRUE(b))
148  PG_RETURN_POINTER(result);
149 
150  if (!ISEQ(LTG_LNODE(a, siglen), LTG_LNODE(b, siglen)))
151  PG_RETURN_POINTER(result);
152  if (!ISEQ(LTG_RNODE(a, siglen), LTG_RNODE(b, siglen)))
153  PG_RETURN_POINTER(result);
154 
155  *result = true;
156  if (!LTG_ISALLTRUE(a))
157  {
158  LOOPBYTE(siglen)
159  {
160  if (sa[i] != sb[i])
161  {
162  *result = false;
163  break;
164  }
165  }
166  }
167  }
168 
169  PG_RETURN_POINTER(result);
170 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define LOOPBYTE(siglen)
Definition: hstore_gist.c:32
#define LTG_ISALLTRUE(x)
Definition: ltree.h:265
#define LTG_SIGN(x)
Definition: ltree.h:262
#define LTG_NODE(x)
Definition: ltree.h:263
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define LTG_LNODE(x, siglen)
Definition: ltree.h:267
signed int int32
Definition: c.h:355
#define LTREE_GET_ASIGLEN()
Definition: ltree.h:281
#define LTG_RNODE(x, siglen)
Definition: ltree.h:269
#define ISEQ(a, b)
Definition: ltree_gist.c:15
#define LTG_ISONENODE(x)
Definition: ltree.h:264
int i
char * BITVECP
Definition: hstore_gist.c:30

◆ ltree_union()

Datum ltree_union ( PG_FUNCTION_ARGS  )

Definition at line 189 of file ltree_gist.c.

References cur, GETENTRY, hashing(), i, LOOPBYTE, LTG_ISALLTRUE, LTG_ISONENODE, LTG_LNODE, LTG_NODE, LTG_RNODE, LTG_SIGN, ltree_compare(), LTREE_GET_ASIGLEN, ltree_gist_alloc(), GistEntryVector::n, palloc0(), PG_GETARG_POINTER, PG_RETURN_POINTER, and VARSIZE.

Referenced by ltree_gist_alloc().

190 {
192  int *size = (int *) PG_GETARG_POINTER(1);
193  int siglen = LTREE_GET_ASIGLEN();
194  BITVECP base = palloc0(siglen);
195  int32 i,
196  j;
197  ltree_gist *result,
198  *cur;
199  ltree *left = NULL,
200  *right = NULL,
201  *curtree;
202  bool isalltrue = false;
203 
204  for (j = 0; j < entryvec->n; j++)
205  {
206  cur = GETENTRY(entryvec, j);
207  if (LTG_ISONENODE(cur))
208  {
209  curtree = LTG_NODE(cur);
210  hashing(base, curtree, siglen);
211  if (!left || ltree_compare(left, curtree) > 0)
212  left = curtree;
213  if (!right || ltree_compare(right, curtree) < 0)
214  right = curtree;
215  }
216  else
217  {
218  if (isalltrue || LTG_ISALLTRUE(cur))
219  isalltrue = true;
220  else
221  {
222  BITVECP sc = LTG_SIGN(cur);
223 
224  LOOPBYTE(siglen)
225  ((unsigned char *) base)[i] |= sc[i];
226  }
227 
228  curtree = LTG_LNODE(cur, siglen);
229  if (!left || ltree_compare(left, curtree) > 0)
230  left = curtree;
231  curtree = LTG_RNODE(cur, siglen);
232  if (!right || ltree_compare(right, curtree) < 0)
233  right = curtree;
234  }
235  }
236 
237  if (isalltrue == false)
238  {
239  isalltrue = true;
240  LOOPBYTE(siglen)
241  {
242  if (((unsigned char *) base)[i] != 0xff)
243  {
244  isalltrue = false;
245  break;
246  }
247  }
248  }
249 
250  result = ltree_gist_alloc(isalltrue, base, siglen, left, right);
251 
252  *size = VARSIZE(result);
253 
254  PG_RETURN_POINTER(result);
255 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define LOOPBYTE(siglen)
Definition: hstore_gist.c:32
#define LTG_ISALLTRUE(x)
Definition: ltree.h:265
#define VARSIZE(PTR)
Definition: postgres.h:303
#define LTG_SIGN(x)
Definition: ltree.h:262
int32 n
Definition: gist.h:226
struct cursor * cur
Definition: ecpg.c:28
#define LTG_NODE(x)
Definition: ltree.h:263
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define LTG_LNODE(x, siglen)
Definition: ltree.h:267
signed int int32
Definition: c.h:355
#define LTREE_GET_ASIGLEN()
Definition: ltree.h:281
#define LTG_RNODE(x, siglen)
Definition: ltree.h:269
#define GETENTRY(vec, pos)
Definition: ltree_gist.c:88
Definition: ltree.h:29
void * palloc0(Size size)
Definition: mcxt.c:980
static void hashing(BITVECP sign, ltree *t, int siglen)
Definition: ltree_gist.c:173
#define LTG_ISONENODE(x)
Definition: ltree.h:264
int i
char * BITVECP
Definition: hstore_gist.c:30
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42
ltree_gist * ltree_gist_alloc(bool isalltrue, BITVECP sign, int siglen, ltree *left, ltree *right)
Definition: ltree_gist.c:39

◆ PG_FUNCTION_INFO_V1() [1/10]

PG_FUNCTION_INFO_V1 ( ltree_gist_in  )

Referenced by ltree_gist_alloc().

◆ PG_FUNCTION_INFO_V1() [2/10]

PG_FUNCTION_INFO_V1 ( ltree_gist_out  )

◆ PG_FUNCTION_INFO_V1() [3/10]

PG_FUNCTION_INFO_V1 ( ltree_compress  )

◆ PG_FUNCTION_INFO_V1() [4/10]

PG_FUNCTION_INFO_V1 ( ltree_decompress  )

◆ PG_FUNCTION_INFO_V1() [5/10]

PG_FUNCTION_INFO_V1 ( ltree_same  )

◆ PG_FUNCTION_INFO_V1() [6/10]

PG_FUNCTION_INFO_V1 ( ltree_union  )

◆ PG_FUNCTION_INFO_V1() [7/10]

PG_FUNCTION_INFO_V1 ( ltree_penalty  )

◆ PG_FUNCTION_INFO_V1() [8/10]

PG_FUNCTION_INFO_V1 ( ltree_picksplit  )

◆ PG_FUNCTION_INFO_V1() [9/10]

PG_FUNCTION_INFO_V1 ( ltree_consistent  )

◆ PG_FUNCTION_INFO_V1() [10/10]

PG_FUNCTION_INFO_V1 ( ltree_gist_options  )

◆ treekey_cmp()

static int treekey_cmp ( const void *  a,
const void *  b 
)
static

Definition at line 283 of file ltree_gist.c.

References ltree_compare(), and rix::r.

Referenced by ltree_picksplit().

284 {
285  return ltree_compare(((const RIX *) a)->r,
286  ((const RIX *) b)->r);
287 }
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:42