PostgreSQL Source Code  git master
ltree_op.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/htup_details.h"
#include "catalog/pg_statistic.h"
#include "common/hashfn.h"
#include "ltree.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/selfuncs.h"
Include dependency graph for ltree_op.c:

Go to the source code of this file.

Macros

#define RUNCMP
 

Functions

 PG_FUNCTION_INFO_V1 (ltree_cmp)
 
 PG_FUNCTION_INFO_V1 (ltree_lt)
 
 PG_FUNCTION_INFO_V1 (ltree_le)
 
 PG_FUNCTION_INFO_V1 (ltree_eq)
 
 PG_FUNCTION_INFO_V1 (ltree_ne)
 
 PG_FUNCTION_INFO_V1 (ltree_ge)
 
 PG_FUNCTION_INFO_V1 (ltree_gt)
 
 PG_FUNCTION_INFO_V1 (hash_ltree)
 
 PG_FUNCTION_INFO_V1 (hash_ltree_extended)
 
 PG_FUNCTION_INFO_V1 (nlevel)
 
 PG_FUNCTION_INFO_V1 (ltree_isparent)
 
 PG_FUNCTION_INFO_V1 (ltree_risparent)
 
 PG_FUNCTION_INFO_V1 (subltree)
 
 PG_FUNCTION_INFO_V1 (subpath)
 
 PG_FUNCTION_INFO_V1 (ltree_index)
 
 PG_FUNCTION_INFO_V1 (ltree_addltree)
 
 PG_FUNCTION_INFO_V1 (ltree_addtext)
 
 PG_FUNCTION_INFO_V1 (ltree_textadd)
 
 PG_FUNCTION_INFO_V1 (lca)
 
 PG_FUNCTION_INFO_V1 (ltree2text)
 
 PG_FUNCTION_INFO_V1 (text2ltree)
 
 PG_FUNCTION_INFO_V1 (ltreeparentsel)
 
int ltree_compare (const ltree *a, const ltree *b)
 
Datum ltree_cmp (PG_FUNCTION_ARGS)
 
Datum ltree_lt (PG_FUNCTION_ARGS)
 
Datum ltree_le (PG_FUNCTION_ARGS)
 
Datum ltree_eq (PG_FUNCTION_ARGS)
 
Datum ltree_ge (PG_FUNCTION_ARGS)
 
Datum ltree_gt (PG_FUNCTION_ARGS)
 
Datum ltree_ne (PG_FUNCTION_ARGS)
 
Datum hash_ltree (PG_FUNCTION_ARGS)
 
Datum hash_ltree_extended (PG_FUNCTION_ARGS)
 
Datum nlevel (PG_FUNCTION_ARGS)
 
bool inner_isparent (const ltree *c, const ltree *p)
 
Datum ltree_isparent (PG_FUNCTION_ARGS)
 
Datum ltree_risparent (PG_FUNCTION_ARGS)
 
static ltreeinner_subltree (ltree *t, int32 startpos, int32 endpos)
 
Datum subltree (PG_FUNCTION_ARGS)
 
Datum subpath (PG_FUNCTION_ARGS)
 
static ltreeltree_concat (ltree *a, ltree *b)
 
Datum ltree_addltree (PG_FUNCTION_ARGS)
 
Datum ltree_addtext (PG_FUNCTION_ARGS)
 
Datum ltree_index (PG_FUNCTION_ARGS)
 
Datum ltree_textadd (PG_FUNCTION_ARGS)
 
ltreelca_inner (ltree **a, int len)
 
Datum lca (PG_FUNCTION_ARGS)
 
Datum text2ltree (PG_FUNCTION_ARGS)
 
Datum ltree2text (PG_FUNCTION_ARGS)
 
Datum ltreeparentsel (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Macro Definition Documentation

◆ RUNCMP

#define RUNCMP
Value:
ltree *b = PG_GETARG_LTREE_P(1); \
int res = ltree_compare(a,b); \
PG_FREE_IF_COPY(a,0); \
PG_FREE_IF_COPY(b,1)
int b
Definition: isn.c:70
int a
Definition: isn.c:69
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:218
int ltree_compare(const ltree *a, const ltree *b)
Definition: ltree_op.c:45
Definition: ltree.h:43

Definition at line 79 of file ltree_op.c.

Function Documentation

◆ hash_ltree()

Datum hash_ltree ( PG_FUNCTION_ARGS  )

Definition at line 137 of file ltree_op.c.

138 {
139  ltree *a = PG_GETARG_LTREE_P(0);
140  uint32 result = 1;
141  int an = a->numlevel;
142  ltree_level *al = LTREE_FIRST(a);
143 
144  while (an > 0)
145  {
146  uint32 levelHash = DatumGetUInt32(hash_any((unsigned char *) al->name, al->len));
147 
148  /*
149  * Combine hash values of successive elements by multiplying the
150  * current value by 31 and adding on the new element's hash value.
151  *
152  * This method is borrowed from hash_array(), which see for further
153  * commentary.
154  */
155  result = (result << 5) - result + levelHash;
156 
157  an--;
158  al = LEVEL_NEXT(al);
159  }
160 
161  PG_FREE_IF_COPY(a, 0);
162  PG_RETURN_UINT32(result);
163 }
unsigned int uint32
Definition: c.h:506
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:355
static Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.h:31
#define LTREE_FIRST(x)
Definition: ltree.h:51
#define LEVEL_NEXT(x)
Definition: ltree.h:40
static uint32 DatumGetUInt32(Datum X)
Definition: postgres.h:222
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:36
uint16 len
Definition: ltree.h:35

References a, DatumGetUInt32(), hash_any(), ltree_level::len, LEVEL_NEXT, LTREE_FIRST, ltree_level::name, PG_FREE_IF_COPY, PG_GETARG_LTREE_P, and PG_RETURN_UINT32.

◆ hash_ltree_extended()

Datum hash_ltree_extended ( PG_FUNCTION_ARGS  )

Definition at line 167 of file ltree_op.c.

168 {
169  ltree *a = PG_GETARG_LTREE_P(0);
170  const uint64 seed = PG_GETARG_INT64(1);
171  uint64 result = 1;
172  int an = a->numlevel;
173  ltree_level *al = LTREE_FIRST(a);
174 
175  /*
176  * If the path has length zero, return 1 + seed to ensure that the low 32
177  * bits of the result match hash_ltree when the seed is 0, as required by
178  * the hash index support functions, but to also return a different value
179  * when there is a seed.
180  */
181  if (an == 0)
182  {
183  PG_FREE_IF_COPY(a, 0);
184  PG_RETURN_UINT64(result + seed);
185  }
186 
187  while (an > 0)
188  {
189  uint64 levelHash = DatumGetUInt64(hash_any_extended((unsigned char *) al->name, al->len, seed));
190 
191  result = (result << 5) - result + levelHash;
192 
193  an--;
194  al = LEVEL_NEXT(al);
195  }
196 
197  PG_FREE_IF_COPY(a, 0);
198  PG_RETURN_UINT64(result);
199 }
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_RETURN_UINT64(x)
Definition: fmgr.h:369
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition: hashfn.h:37
static uint64 DatumGetUInt64(Datum X)
Definition: postgres.h:419

References a, DatumGetUInt64(), hash_any_extended(), ltree_level::len, LEVEL_NEXT, LTREE_FIRST, ltree_level::name, PG_FREE_IF_COPY, PG_GETARG_INT64, PG_GETARG_LTREE_P, and PG_RETURN_UINT64.

◆ inner_isparent()

bool inner_isparent ( const ltree c,
const ltree p 
)

Definition at line 212 of file ltree_op.c.

213 {
214  ltree_level *cl = LTREE_FIRST(c);
215  ltree_level *pl = LTREE_FIRST(p);
216  int pn = p->numlevel;
217 
218  if (pn > c->numlevel)
219  return false;
220 
221  while (pn > 0)
222  {
223  if (cl->len != pl->len)
224  return false;
225  if (memcmp(cl->name, pl->name, cl->len) != 0)
226  return false;
227 
228  pn--;
229  cl = LEVEL_NEXT(cl);
230  pl = LEVEL_NEXT(pl);
231  }
232  return true;
233 }
char * c
uint16 numlevel
Definition: ltree.h:45

References ltree_level::len, LEVEL_NEXT, LTREE_FIRST, ltree_level::name, and ltree::numlevel.

Referenced by ltree_consistent(), ltree_isparent(), and ltree_risparent().

◆ inner_subltree()

static ltree* inner_subltree ( ltree t,
int32  startpos,
int32  endpos 
)
static

Definition at line 261 of file ltree_op.c.

262 {
263  char *start = NULL,
264  *end = NULL;
265  ltree_level *ptr = LTREE_FIRST(t);
266  ltree *res;
267  int i;
268 
269  if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos > endpos)
270  ereport(ERROR,
271  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
272  errmsg("invalid positions")));
273 
274  if (endpos > t->numlevel)
275  endpos = t->numlevel;
276 
277  start = end = (char *) ptr;
278  for (i = 0; i < endpos; i++)
279  {
280  if (i == startpos)
281  start = (char *) ptr;
282  if (i == endpos - 1)
283  {
284  end = (char *) LEVEL_NEXT(ptr);
285  break;
286  }
287  ptr = LEVEL_NEXT(ptr);
288  }
289 
290  res = (ltree *) palloc0(LTREE_HDRSIZE + (end - start));
291  SET_VARSIZE(res, LTREE_HDRSIZE + (end - start));
292  res->numlevel = endpos - startpos;
293 
294  memcpy(LTREE_FIRST(res), start, end - start);
295 
296  return res;
297 }
int errcode(int sqlerrcode)
Definition: elog.c:855
int errmsg(const char *fmt,...)
Definition: elog.c:1068
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
return str start
int i
Definition: isn.c:73
#define LTREE_HDRSIZE
Definition: ltree.h:50
void * palloc0(Size size)
Definition: mcxt.c:1347
static XLogRecPtr endpos
Definition: pg_receivewal.c:56
static XLogRecPtr startpos
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

References endpos, ereport, errcode(), errmsg(), ERROR, i, LEVEL_NEXT, LTREE_FIRST, LTREE_HDRSIZE, ltree::numlevel, palloc0(), res, SET_VARSIZE, start, and startpos.

Referenced by subltree(), and subpath().

◆ lca()

Definition at line 570 of file ltree_op.c.

571 {
572  int i;
573  ltree **a,
574  *res;
575 
576  a = (ltree **) palloc(sizeof(ltree *) * fcinfo->nargs);
577  for (i = 0; i < fcinfo->nargs; i++)
578  a[i] = PG_GETARG_LTREE_P(i);
579  res = lca_inner(a, (int) fcinfo->nargs);
580  for (i = 0; i < fcinfo->nargs; i++)
581  PG_FREE_IF_COPY(a[i], i);
582  pfree(a);
583 
584  if (res)
586  else
587  PG_RETURN_NULL();
588 }
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
ltree * lca_inner(ltree **a, int len)
Definition: ltree_op.c:495
void pfree(void *pointer)
Definition: mcxt.c:1521
void * palloc(Size size)
Definition: mcxt.c:1317

References a, i, lca_inner(), palloc(), pfree(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_NULL, PG_RETURN_POINTER, and res.

Referenced by cmp_list_len_contents_asc(), fix_indexqual_clause(), mbms_add_members(), mbms_int_members(), mbms_overlap_sets(), and set_plan_refs().

◆ lca_inner()

ltree* lca_inner ( ltree **  a,
int  len 
)

Definition at line 495 of file ltree_op.c.

496 {
497  int tmp,
498  num,
499  i,
500  reslen;
501  ltree **ptr;
502  ltree_level *l1,
503  *l2;
504  ltree *res;
505 
506  if (len <= 0)
507  return NULL; /* no inputs? */
508  if ((*a)->numlevel == 0)
509  return NULL; /* any empty input means NULL result */
510 
511  /* num is the length of the longest common ancestor so far */
512  num = (*a)->numlevel - 1;
513 
514  /* Compare each additional input to *a */
515  ptr = a + 1;
516  while (ptr - a < len)
517  {
518  if ((*ptr)->numlevel == 0)
519  return NULL;
520  else if ((*ptr)->numlevel == 1)
521  num = 0;
522  else
523  {
524  l1 = LTREE_FIRST(*a);
525  l2 = LTREE_FIRST(*ptr);
526  tmp = Min(num, (*ptr)->numlevel - 1);
527  num = 0;
528  for (i = 0; i < tmp; i++)
529  {
530  if (l1->len == l2->len &&
531  memcmp(l1->name, l2->name, l1->len) == 0)
532  num = i + 1;
533  else
534  break;
535  l1 = LEVEL_NEXT(l1);
536  l2 = LEVEL_NEXT(l2);
537  }
538  }
539  ptr++;
540  }
541 
542  /* Now compute size of result ... */
543  reslen = LTREE_HDRSIZE;
544  l1 = LTREE_FIRST(*a);
545  for (i = 0; i < num; i++)
546  {
547  reslen += MAXALIGN(l1->len + LEVEL_HDRSIZE);
548  l1 = LEVEL_NEXT(l1);
549  }
550 
551  /* ... and construct it by copying from *a */
552  res = (ltree *) palloc0(reslen);
553  SET_VARSIZE(res, reslen);
554  res->numlevel = num;
555 
556  l1 = LTREE_FIRST(*a);
557  l2 = LTREE_FIRST(res);
558 
559  for (i = 0; i < num; i++)
560  {
561  memcpy(l2, l1, MAXALIGN(l1->len + LEVEL_HDRSIZE));
562  l1 = LEVEL_NEXT(l1);
563  l2 = LEVEL_NEXT(l2);
564  }
565 
566  return res;
567 }
#define Min(x, y)
Definition: c.h:1004
#define MAXALIGN(LEN)
Definition: c.h:811
#define LEVEL_HDRSIZE
Definition: ltree.h:39
const void size_t len

References a, i, ltree_level::len, len, LEVEL_HDRSIZE, LEVEL_NEXT, LTREE_FIRST, LTREE_HDRSIZE, MAXALIGN, Min, ltree_level::name, palloc0(), res, and SET_VARSIZE.

Referenced by _lca(), and lca().

◆ ltree2text()

Datum ltree2text ( PG_FUNCTION_ARGS  )

Definition at line 608 of file ltree_op.c.

609 {
610  ltree *in = PG_GETARG_LTREE_P(0);
611  char *ptr;
612  int i;
613  ltree_level *curlevel;
614  text *out;
615 
616  out = (text *) palloc(VARSIZE(in) + VARHDRSZ);
617  ptr = VARDATA(out);
618  curlevel = LTREE_FIRST(in);
619  for (i = 0; i < in->numlevel; i++)
620  {
621  if (i != 0)
622  {
623  *ptr = '.';
624  ptr++;
625  }
626  memcpy(ptr, curlevel->name, curlevel->len);
627  ptr += curlevel->len;
628  curlevel = LEVEL_NEXT(curlevel);
629  }
630 
631  SET_VARSIZE(out, ptr - ((char *) out));
632  PG_FREE_IF_COPY(in, 0);
633 
634  PG_RETURN_POINTER(out);
635 }
#define VARHDRSZ
Definition: c.h:692
Definition: c.h:687
#define VARDATA(PTR)
Definition: varatt.h:278
#define VARSIZE(PTR)
Definition: varatt.h:279

References i, ltree_level::len, LEVEL_NEXT, LTREE_FIRST, ltree_level::name, ltree::numlevel, palloc(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_POINTER, SET_VARSIZE, VARDATA, VARHDRSZ, and VARSIZE.

◆ ltree_addltree()

Datum ltree_addltree ( PG_FUNCTION_ARGS  )

Definition at line 366 of file ltree_op.c.

367 {
368  ltree *a = PG_GETARG_LTREE_P(0);
369  ltree *b = PG_GETARG_LTREE_P(1);
370  ltree *r;
371 
372  r = ltree_concat(a, b);
373  PG_FREE_IF_COPY(a, 0);
374  PG_FREE_IF_COPY(b, 1);
376 }
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:343

References a, b, ltree_concat(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, and PG_RETURN_POINTER.

◆ ltree_addtext()

Datum ltree_addtext ( PG_FUNCTION_ARGS  )

Definition at line 379 of file ltree_op.c.

380 {
381  ltree *a = PG_GETARG_LTREE_P(0);
382  text *b = PG_GETARG_TEXT_PP(1);
383  char *s;
384  ltree *r,
385  *tmp;
386 
387  s = text_to_cstring(b);
388 
390  PointerGetDatum(s)));
391 
392  pfree(s);
393 
394  r = ltree_concat(a, tmp);
395 
396  pfree(tmp);
397 
398  PG_FREE_IF_COPY(a, 0);
399  PG_FREE_IF_COPY(b, 1);
401 }
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:642
PGDLLEXPORT Datum ltree_in(PG_FUNCTION_ARGS)
Definition: ltree_io.c:175
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
char * text_to_cstring(const text *t)
Definition: varlena.c:217

References a, b, DatumGetPointer(), DirectFunctionCall1, ltree_concat(), ltree_in(), pfree(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, PointerGetDatum(), and text_to_cstring().

◆ ltree_cmp()

Datum ltree_cmp ( PG_FUNCTION_ARGS  )

Definition at line 87 of file ltree_op.c.

88 {
89  RUNCMP;
91 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define RUNCMP
Definition: ltree_op.c:79

References PG_RETURN_INT32, res, and RUNCMP.

◆ ltree_compare()

int ltree_compare ( const ltree a,
const ltree b 
)

Definition at line 45 of file ltree_op.c.

46 {
47  ltree_level *al = LTREE_FIRST(a);
48  ltree_level *bl = LTREE_FIRST(b);
49  int an = a->numlevel;
50  int bn = b->numlevel;
51 
52  while (an > 0 && bn > 0)
53  {
54  int res;
55 
56  if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
57  {
58  if (al->len != bl->len)
59  return (al->len - bl->len) * 10 * (an + 1);
60  }
61  else
62  {
63  if (res < 0)
64  res = -1;
65  else
66  res = 1;
67  return res * 10 * (an + 1);
68  }
69 
70  an--;
71  bn--;
72  al = LEVEL_NEXT(al);
73  bl = LEVEL_NEXT(bl);
74  }
75 
76  return (a->numlevel - b->numlevel) * 10 * (an + 1);
77 }

References a, b, ltree_level::len, LEVEL_NEXT, LTREE_FIRST, Min, ltree_level::name, and res.

Referenced by gist_ischild(), gist_isparent(), ltree_consistent(), ltree_penalty(), ltree_picksplit(), ltree_union(), and treekey_cmp().

◆ ltree_concat()

static ltree* ltree_concat ( ltree a,
ltree b 
)
static

Definition at line 343 of file ltree_op.c.

344 {
345  ltree *r;
346  int numlevel = (int) a->numlevel + b->numlevel;
347 
348  if (numlevel > LTREE_MAX_LEVELS)
349  ereport(ERROR,
350  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
351  errmsg("number of ltree levels (%d) exceeds the maximum allowed (%d)",
352  numlevel, LTREE_MAX_LEVELS)));
353 
354  r = (ltree *) palloc0(VARSIZE(a) + VARSIZE(b) - LTREE_HDRSIZE);
356  r->numlevel = (uint16) numlevel;
357 
358  memcpy(LTREE_FIRST(r), LTREE_FIRST(a), VARSIZE(a) - LTREE_HDRSIZE);
359  memcpy(((char *) LTREE_FIRST(r)) + VARSIZE(a) - LTREE_HDRSIZE,
360  LTREE_FIRST(b),
361  VARSIZE(b) - LTREE_HDRSIZE);
362  return r;
363 }
unsigned short uint16
Definition: c.h:505
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
#define LTREE_MAX_LEVELS
Definition: ltree.h:52

References a, b, ereport, errcode(), errmsg(), ERROR, if(), LTREE_FIRST, LTREE_HDRSIZE, LTREE_MAX_LEVELS, ltree::numlevel, palloc0(), SET_VARSIZE, and VARSIZE.

Referenced by ltree_addltree(), ltree_addtext(), and ltree_textadd().

◆ ltree_eq()

Datum ltree_eq ( PG_FUNCTION_ARGS  )

Definition at line 108 of file ltree_op.c.

109 {
110  RUNCMP;
111  PG_RETURN_BOOL(res == 0);
112 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_ge()

Datum ltree_ge ( PG_FUNCTION_ARGS  )

Definition at line 115 of file ltree_op.c.

116 {
117  RUNCMP;
118  PG_RETURN_BOOL(res >= 0);
119 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_gt()

Datum ltree_gt ( PG_FUNCTION_ARGS  )

Definition at line 122 of file ltree_op.c.

123 {
124  RUNCMP;
125  PG_RETURN_BOOL(res > 0);
126 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_index()

Datum ltree_index ( PG_FUNCTION_ARGS  )

Definition at line 404 of file ltree_op.c.

405 {
406  ltree *a = PG_GETARG_LTREE_P(0);
407  ltree *b = PG_GETARG_LTREE_P(1);
408  int start = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
409  int i,
410  j;
411  ltree_level *startptr,
412  *aptr,
413  *bptr;
414  bool found = false;
415 
416  if (start < 0)
417  {
418  if (-start >= a->numlevel)
419  start = 0;
420  else
421  start = (int) (a->numlevel) + start;
422  }
423 
424  if (a->numlevel - start < b->numlevel || a->numlevel == 0 || b->numlevel == 0)
425  {
426  PG_FREE_IF_COPY(a, 0);
427  PG_FREE_IF_COPY(b, 1);
428  PG_RETURN_INT32(-1);
429  }
430 
431  startptr = LTREE_FIRST(a);
432  for (i = 0; i <= a->numlevel - b->numlevel; i++)
433  {
434  if (i >= start)
435  {
436  aptr = startptr;
437  bptr = LTREE_FIRST(b);
438  for (j = 0; j < b->numlevel; j++)
439  {
440  if (!(aptr->len == bptr->len && memcmp(aptr->name, bptr->name, aptr->len) == 0))
441  break;
442  aptr = LEVEL_NEXT(aptr);
443  bptr = LEVEL_NEXT(bptr);
444  }
445 
446  if (j == b->numlevel)
447  {
448  found = true;
449  break;
450  }
451  }
452  startptr = LEVEL_NEXT(startptr);
453  }
454 
455  if (!found)
456  i = -1;
457 
458  PG_FREE_IF_COPY(a, 0);
459  PG_FREE_IF_COPY(b, 1);
461 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
int j
Definition: isn.c:74

References a, b, i, j, ltree_level::len, LEVEL_NEXT, LTREE_FIRST, ltree_level::name, PG_FREE_IF_COPY, PG_GETARG_INT32, PG_GETARG_LTREE_P, PG_RETURN_INT32, and start.

◆ ltree_isparent()

Datum ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 236 of file ltree_op.c.

237 {
238  ltree *c = PG_GETARG_LTREE_P(1);
239  ltree *p = PG_GETARG_LTREE_P(0);
240  bool res = inner_isparent(c, p);
241 
242  PG_FREE_IF_COPY(c, 1);
243  PG_FREE_IF_COPY(p, 0);
245 }
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:212

References inner_isparent(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_BOOL, and res.

Referenced by _ltree_extract_isparent(), and _ltree_isparent().

◆ ltree_le()

Datum ltree_le ( PG_FUNCTION_ARGS  )

Definition at line 101 of file ltree_op.c.

102 {
103  RUNCMP;
104  PG_RETURN_BOOL(res <= 0);
105 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_lt()

Datum ltree_lt ( PG_FUNCTION_ARGS  )

Definition at line 94 of file ltree_op.c.

95 {
96  RUNCMP;
97  PG_RETURN_BOOL(res < 0);
98 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_ne()

Datum ltree_ne ( PG_FUNCTION_ARGS  )

Definition at line 129 of file ltree_op.c.

130 {
131  RUNCMP;
132  PG_RETURN_BOOL(res != 0);
133 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_risparent()

Datum ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 248 of file ltree_op.c.

249 {
250  ltree *c = PG_GETARG_LTREE_P(0);
251  ltree *p = PG_GETARG_LTREE_P(1);
252  bool res = inner_isparent(c, p);
253 
254  PG_FREE_IF_COPY(c, 0);
255  PG_FREE_IF_COPY(p, 1);
257 }

References inner_isparent(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_BOOL, and res.

Referenced by _ltree_extract_risparent(), and _ltree_risparent().

◆ ltree_textadd()

Datum ltree_textadd ( PG_FUNCTION_ARGS  )

Definition at line 464 of file ltree_op.c.

465 {
466  ltree *a = PG_GETARG_LTREE_P(1);
467  text *b = PG_GETARG_TEXT_PP(0);
468  char *s;
469  ltree *r,
470  *tmp;
471 
472  s = text_to_cstring(b);
473 
475  PointerGetDatum(s)));
476 
477  pfree(s);
478 
479  r = ltree_concat(tmp, a);
480 
481  pfree(tmp);
482 
483  PG_FREE_IF_COPY(a, 1);
484  PG_FREE_IF_COPY(b, 0);
486 }

References a, b, DatumGetPointer(), DirectFunctionCall1, ltree_concat(), ltree_in(), pfree(), PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, PointerGetDatum(), and text_to_cstring().

◆ ltreeparentsel()

Datum ltreeparentsel ( PG_FUNCTION_ARGS  )

Definition at line 645 of file ltree_op.c.

646 {
648  Oid operator = PG_GETARG_OID(1);
649  List *args = (List *) PG_GETARG_POINTER(2);
650  int varRelid = PG_GETARG_INT32(3);
651  double selec;
652 
653  /* Use generic restriction selectivity logic, with default 0.001. */
655  args, varRelid,
656  0.001);
657 
658  PG_RETURN_FLOAT8((float8) selec);
659 }
double float8
Definition: c.h:630
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
tree ctl root
Definition: radixtree.h:1886
double generic_restriction_selectivity(PlannerInfo *root, Oid oproid, Oid collation, List *args, int varRelid, double default_selectivity)
Definition: selfuncs.c:914
Definition: pg_list.h:54

References generate_unaccent_rules::args, generic_restriction_selectivity(), InvalidOid, PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_FLOAT8, and root.

◆ nlevel()

Datum nlevel ( PG_FUNCTION_ARGS  )

Definition at line 202 of file ltree_op.c.

203 {
204  ltree *a = PG_GETARG_LTREE_P(0);
205  int res = a->numlevel;
206 
207  PG_FREE_IF_COPY(a, 0);
209 }

References a, PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_INT32, and res.

◆ PG_FUNCTION_INFO_V1() [1/22]

PG_FUNCTION_INFO_V1 ( hash_ltree  )

◆ PG_FUNCTION_INFO_V1() [2/22]

PG_FUNCTION_INFO_V1 ( hash_ltree_extended  )

◆ PG_FUNCTION_INFO_V1() [3/22]

PG_FUNCTION_INFO_V1 ( lca  )

◆ PG_FUNCTION_INFO_V1() [4/22]

PG_FUNCTION_INFO_V1 ( ltree2text  )

◆ PG_FUNCTION_INFO_V1() [5/22]

PG_FUNCTION_INFO_V1 ( ltree_addltree  )

◆ PG_FUNCTION_INFO_V1() [6/22]

PG_FUNCTION_INFO_V1 ( ltree_addtext  )

◆ PG_FUNCTION_INFO_V1() [7/22]

PG_FUNCTION_INFO_V1 ( ltree_cmp  )

◆ PG_FUNCTION_INFO_V1() [8/22]

PG_FUNCTION_INFO_V1 ( ltree_eq  )

◆ PG_FUNCTION_INFO_V1() [9/22]

PG_FUNCTION_INFO_V1 ( ltree_ge  )

◆ PG_FUNCTION_INFO_V1() [10/22]

PG_FUNCTION_INFO_V1 ( ltree_gt  )

◆ PG_FUNCTION_INFO_V1() [11/22]

PG_FUNCTION_INFO_V1 ( ltree_index  )

◆ PG_FUNCTION_INFO_V1() [12/22]

PG_FUNCTION_INFO_V1 ( ltree_isparent  )

◆ PG_FUNCTION_INFO_V1() [13/22]

PG_FUNCTION_INFO_V1 ( ltree_le  )

◆ PG_FUNCTION_INFO_V1() [14/22]

PG_FUNCTION_INFO_V1 ( ltree_lt  )

◆ PG_FUNCTION_INFO_V1() [15/22]

PG_FUNCTION_INFO_V1 ( ltree_ne  )

◆ PG_FUNCTION_INFO_V1() [16/22]

PG_FUNCTION_INFO_V1 ( ltree_risparent  )

◆ PG_FUNCTION_INFO_V1() [17/22]

PG_FUNCTION_INFO_V1 ( ltree_textadd  )

◆ PG_FUNCTION_INFO_V1() [18/22]

PG_FUNCTION_INFO_V1 ( ltreeparentsel  )

◆ PG_FUNCTION_INFO_V1() [19/22]

PG_FUNCTION_INFO_V1 ( nlevel  )

◆ PG_FUNCTION_INFO_V1() [20/22]

PG_FUNCTION_INFO_V1 ( subltree  )

◆ PG_FUNCTION_INFO_V1() [21/22]

PG_FUNCTION_INFO_V1 ( subpath  )

◆ PG_FUNCTION_INFO_V1() [22/22]

PG_FUNCTION_INFO_V1 ( text2ltree  )

◆ subltree()

Datum subltree ( PG_FUNCTION_ARGS  )

Definition at line 300 of file ltree_op.c.

301 {
302  ltree *t = PG_GETARG_LTREE_P(0);
304 
305  PG_FREE_IF_COPY(t, 0);
307 }
static ltree * inner_subltree(ltree *t, int32 startpos, int32 endpos)
Definition: ltree_op.c:261

References inner_subltree(), PG_FREE_IF_COPY, PG_GETARG_INT32, PG_GETARG_LTREE_P, PG_RETURN_POINTER, and res.

◆ subpath()

Datum subpath ( PG_FUNCTION_ARGS  )

Definition at line 310 of file ltree_op.c.

311 {
312  ltree *t = PG_GETARG_LTREE_P(0);
314  int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
315  int32 end;
316  ltree *res;
317 
318  end = start + len;
319 
320  if (start < 0)
321  {
322  start = t->numlevel + start;
323  end = start + len;
324  }
325  if (start < 0)
326  { /* start > t->numlevel */
327  start = t->numlevel + start;
328  end = start + len;
329  }
330 
331  if (len < 0)
332  end = t->numlevel + len;
333  else if (len == 0)
334  end = (fcinfo->nargs == 3) ? start : 0xffff;
335 
336  res = inner_subltree(t, start, end);
337 
338  PG_FREE_IF_COPY(t, 0);
340 }
signed int int32
Definition: c.h:494

References inner_subltree(), len, ltree::numlevel, PG_FREE_IF_COPY, PG_GETARG_INT32, PG_GETARG_LTREE_P, PG_RETURN_POINTER, res, and start.

Referenced by add_foreign_final_paths(), add_paths_to_append_rel(), adjust_paths_for_srfs(), append_nonpartial_cost(), apply_scanjoin_target_to_paths(), build_setop_child_paths(), cost_append(), cost_bitmap_and_node(), cost_bitmap_or_node(), create_agg_path(), create_append_path(), create_append_plan(), create_gather_merge_path(), create_gather_path(), create_group_path(), create_groupingsets_path(), create_incremental_sort_path(), create_limit_path(), create_lockrows_path(), create_material_path(), create_memoize_path(), create_merge_append_path(), create_merge_append_plan(), create_modifytable_path(), create_modifytable_plan(), create_projection_path(), create_set_projection_path(), create_setop_path(), create_sort_path(), create_subqueryscan_path(), create_unique_path(), create_upper_unique_path(), create_windowagg_path(), ExecSupportsMarkRestore(), generate_gather_paths(), generate_union_paths(), generate_useful_gather_paths(), get_param_path_clause_serials(), is_dummy_rel(), mark_async_capable_plan(), recurse_set_operations(), reparameterize_path(), set_subquery_pathlist(), and walkdir().

◆ text2ltree()

Datum text2ltree ( PG_FUNCTION_ARGS  )

Definition at line 591 of file ltree_op.c.

592 {
593  text *in = PG_GETARG_TEXT_PP(0);
594  char *s;
595  ltree *out;
596 
597  s = text_to_cstring(in);
598 
600  PointerGetDatum(s)));
601  pfree(s);
602  PG_FREE_IF_COPY(in, 0);
603  PG_RETURN_POINTER(out);
604 }

References DatumGetPointer(), DirectFunctionCall1, ltree_in(), pfree(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, PointerGetDatum(), and text_to_cstring().

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 18 of file ltree_op.c.