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 "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 (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 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:42
Definition: ltree.h:43

Definition at line 76 of file ltree_op.c.

Function Documentation

◆ inner_isparent()

bool inner_isparent ( const ltree c,
const ltree p 
)

Definition at line 143 of file ltree_op.c.

144 {
145  ltree_level *cl = LTREE_FIRST(c);
146  ltree_level *pl = LTREE_FIRST(p);
147  int pn = p->numlevel;
148 
149  if (pn > c->numlevel)
150  return false;
151 
152  while (pn > 0)
153  {
154  if (cl->len != pl->len)
155  return false;
156  if (memcmp(cl->name, pl->name, cl->len) != 0)
157  return false;
158 
159  pn--;
160  cl = LEVEL_NEXT(cl);
161  pl = LEVEL_NEXT(pl);
162  }
163  return true;
164 }
#define LTREE_FIRST(x)
Definition: ltree.h:51
#define LEVEL_NEXT(x)
Definition: ltree.h:40
char * c
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:36
uint16 len
Definition: ltree.h:35
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 192 of file ltree_op.c.

193 {
194  char *start = NULL,
195  *end = NULL;
196  ltree_level *ptr = LTREE_FIRST(t);
197  ltree *res;
198  int i;
199 
200  if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos > endpos)
201  ereport(ERROR,
202  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
203  errmsg("invalid positions")));
204 
205  if (endpos > t->numlevel)
206  endpos = t->numlevel;
207 
208  start = end = (char *) ptr;
209  for (i = 0; i < endpos; i++)
210  {
211  if (i == startpos)
212  start = (char *) ptr;
213  if (i == endpos - 1)
214  {
215  end = (char *) LEVEL_NEXT(ptr);
216  break;
217  }
218  ptr = LEVEL_NEXT(ptr);
219  }
220 
221  res = (ltree *) palloc0(LTREE_HDRSIZE + (end - start));
222  SET_VARSIZE(res, LTREE_HDRSIZE + (end - start));
223  res->numlevel = endpos - startpos;
224 
225  memcpy(LTREE_FIRST(res), start, end - start);
226 
227  return res;
228 }
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int i
Definition: isn.c:73
#define LTREE_HDRSIZE
Definition: ltree.h:50
void * palloc0(Size size)
Definition: mcxt.c:1257
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, and startpos.

Referenced by subltree(), and subpath().

◆ lca()

Definition at line 501 of file ltree_op.c.

502 {
503  int i;
504  ltree **a,
505  *res;
506 
507  a = (ltree **) palloc(sizeof(ltree *) * fcinfo->nargs);
508  for (i = 0; i < fcinfo->nargs; i++)
509  a[i] = PG_GETARG_LTREE_P(i);
510  res = lca_inner(a, (int) fcinfo->nargs);
511  for (i = 0; i < fcinfo->nargs; i++)
512  PG_FREE_IF_COPY(a[i], i);
513  pfree(a);
514 
515  if (res)
517  else
518  PG_RETURN_NULL();
519 }
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#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:426
void pfree(void *pointer)
Definition: mcxt.c:1456
void * palloc(Size size)
Definition: mcxt.c:1226

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 426 of file ltree_op.c.

427 {
428  int tmp,
429  num,
430  i,
431  reslen;
432  ltree **ptr;
433  ltree_level *l1,
434  *l2;
435  ltree *res;
436 
437  if (len <= 0)
438  return NULL; /* no inputs? */
439  if ((*a)->numlevel == 0)
440  return NULL; /* any empty input means NULL result */
441 
442  /* num is the length of the longest common ancestor so far */
443  num = (*a)->numlevel - 1;
444 
445  /* Compare each additional input to *a */
446  ptr = a + 1;
447  while (ptr - a < len)
448  {
449  if ((*ptr)->numlevel == 0)
450  return NULL;
451  else if ((*ptr)->numlevel == 1)
452  num = 0;
453  else
454  {
455  l1 = LTREE_FIRST(*a);
456  l2 = LTREE_FIRST(*ptr);
457  tmp = Min(num, (*ptr)->numlevel - 1);
458  num = 0;
459  for (i = 0; i < tmp; i++)
460  {
461  if (l1->len == l2->len &&
462  memcmp(l1->name, l2->name, l1->len) == 0)
463  num = i + 1;
464  else
465  break;
466  l1 = LEVEL_NEXT(l1);
467  l2 = LEVEL_NEXT(l2);
468  }
469  }
470  ptr++;
471  }
472 
473  /* Now compute size of result ... */
474  reslen = LTREE_HDRSIZE;
475  l1 = LTREE_FIRST(*a);
476  for (i = 0; i < num; i++)
477  {
478  reslen += MAXALIGN(l1->len + LEVEL_HDRSIZE);
479  l1 = LEVEL_NEXT(l1);
480  }
481 
482  /* ... and construct it by copying from *a */
483  res = (ltree *) palloc0(reslen);
484  SET_VARSIZE(res, reslen);
485  res->numlevel = num;
486 
487  l1 = LTREE_FIRST(*a);
488  l2 = LTREE_FIRST(res);
489 
490  for (i = 0; i < num; i++)
491  {
492  memcpy(l2, l1, MAXALIGN(l1->len + LEVEL_HDRSIZE));
493  l1 = LEVEL_NEXT(l1);
494  l2 = LEVEL_NEXT(l2);
495  }
496 
497  return res;
498 }
#define Min(x, y)
Definition: c.h:993
#define MAXALIGN(LEN)
Definition: c.h:800
#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 539 of file ltree_op.c.

540 {
541  ltree *in = PG_GETARG_LTREE_P(0);
542  char *ptr;
543  int i;
544  ltree_level *curlevel;
545  text *out;
546 
547  out = (text *) palloc(VARSIZE(in) + VARHDRSZ);
548  ptr = VARDATA(out);
549  curlevel = LTREE_FIRST(in);
550  for (i = 0; i < in->numlevel; i++)
551  {
552  if (i != 0)
553  {
554  *ptr = '.';
555  ptr++;
556  }
557  memcpy(ptr, curlevel->name, curlevel->len);
558  ptr += curlevel->len;
559  curlevel = LEVEL_NEXT(curlevel);
560  }
561 
562  SET_VARSIZE(out, ptr - ((char *) out));
563  PG_FREE_IF_COPY(in, 0);
564 
565  PG_RETURN_POINTER(out);
566 }
#define VARHDRSZ
Definition: c.h:681
Definition: c.h:676
#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 297 of file ltree_op.c.

298 {
299  ltree *a = PG_GETARG_LTREE_P(0);
300  ltree *b = PG_GETARG_LTREE_P(1);
301  ltree *r;
302 
303  r = ltree_concat(a, b);
304  PG_FREE_IF_COPY(a, 0);
305  PG_FREE_IF_COPY(b, 1);
307 }
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:274

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 310 of file ltree_op.c.

311 {
312  ltree *a = PG_GETARG_LTREE_P(0);
313  text *b = PG_GETARG_TEXT_PP(1);
314  char *s;
315  ltree *r,
316  *tmp;
317 
318  s = text_to_cstring(b);
319 
321  PointerGetDatum(s)));
322 
323  pfree(s);
324 
325  r = ltree_concat(a, tmp);
326 
327  pfree(tmp);
328 
329  PG_FREE_IF_COPY(a, 0);
330  PG_FREE_IF_COPY(b, 1);
332 }
#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 84 of file ltree_op.c.

85 {
86  RUNCMP;
88 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define RUNCMP
Definition: ltree_op.c:76

References PG_RETURN_INT32, res, and RUNCMP.

◆ ltree_compare()

int ltree_compare ( const ltree a,
const ltree b 
)

Definition at line 42 of file ltree_op.c.

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

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 274 of file ltree_op.c.

275 {
276  ltree *r;
277  int numlevel = (int) a->numlevel + b->numlevel;
278 
279  if (numlevel > LTREE_MAX_LEVELS)
280  ereport(ERROR,
281  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
282  errmsg("number of ltree levels (%d) exceeds the maximum allowed (%d)",
283  numlevel, LTREE_MAX_LEVELS)));
284 
285  r = (ltree *) palloc0(VARSIZE(a) + VARSIZE(b) - LTREE_HDRSIZE);
287  r->numlevel = (uint16) numlevel;
288 
289  memcpy(LTREE_FIRST(r), LTREE_FIRST(a), VARSIZE(a) - LTREE_HDRSIZE);
290  memcpy(((char *) LTREE_FIRST(r)) + VARSIZE(a) - LTREE_HDRSIZE,
291  LTREE_FIRST(b),
292  VARSIZE(b) - LTREE_HDRSIZE);
293  return r;
294 }
unsigned short uint16
Definition: c.h:494
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 105 of file ltree_op.c.

106 {
107  RUNCMP;
108  PG_RETURN_BOOL(res == 0);
109 }
#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 112 of file ltree_op.c.

113 {
114  RUNCMP;
115  PG_RETURN_BOOL(res >= 0);
116 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_gt()

Datum ltree_gt ( PG_FUNCTION_ARGS  )

Definition at line 119 of file ltree_op.c.

120 {
121  RUNCMP;
122  PG_RETURN_BOOL(res > 0);
123 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_index()

Datum ltree_index ( PG_FUNCTION_ARGS  )

Definition at line 335 of file ltree_op.c.

336 {
337  ltree *a = PG_GETARG_LTREE_P(0);
338  ltree *b = PG_GETARG_LTREE_P(1);
339  int start = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
340  int i,
341  j;
342  ltree_level *startptr,
343  *aptr,
344  *bptr;
345  bool found = false;
346 
347  if (start < 0)
348  {
349  if (-start >= a->numlevel)
350  start = 0;
351  else
352  start = (int) (a->numlevel) + start;
353  }
354 
355  if (a->numlevel - start < b->numlevel || a->numlevel == 0 || b->numlevel == 0)
356  {
357  PG_FREE_IF_COPY(a, 0);
358  PG_FREE_IF_COPY(b, 1);
359  PG_RETURN_INT32(-1);
360  }
361 
362  startptr = LTREE_FIRST(a);
363  for (i = 0; i <= a->numlevel - b->numlevel; i++)
364  {
365  if (i >= start)
366  {
367  aptr = startptr;
368  bptr = LTREE_FIRST(b);
369  for (j = 0; j < b->numlevel; j++)
370  {
371  if (!(aptr->len == bptr->len && memcmp(aptr->name, bptr->name, aptr->len) == 0))
372  break;
373  aptr = LEVEL_NEXT(aptr);
374  bptr = LEVEL_NEXT(bptr);
375  }
376 
377  if (j == b->numlevel)
378  {
379  found = true;
380  break;
381  }
382  }
383  startptr = LEVEL_NEXT(startptr);
384  }
385 
386  if (!found)
387  i = -1;
388 
389  PG_FREE_IF_COPY(a, 0);
390  PG_FREE_IF_COPY(b, 1);
392 }
#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, and PG_RETURN_INT32.

◆ ltree_isparent()

Datum ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 167 of file ltree_op.c.

168 {
169  ltree *c = PG_GETARG_LTREE_P(1);
170  ltree *p = PG_GETARG_LTREE_P(0);
171  bool res = inner_isparent(c, p);
172 
173  PG_FREE_IF_COPY(c, 1);
174  PG_FREE_IF_COPY(p, 0);
176 }
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:143

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 98 of file ltree_op.c.

99 {
100  RUNCMP;
101  PG_RETURN_BOOL(res <= 0);
102 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_lt()

Datum ltree_lt ( PG_FUNCTION_ARGS  )

Definition at line 91 of file ltree_op.c.

92 {
93  RUNCMP;
94  PG_RETURN_BOOL(res < 0);
95 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_ne()

Datum ltree_ne ( PG_FUNCTION_ARGS  )

Definition at line 126 of file ltree_op.c.

127 {
128  RUNCMP;
129  PG_RETURN_BOOL(res != 0);
130 }

References PG_RETURN_BOOL, res, and RUNCMP.

◆ ltree_risparent()

Datum ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 179 of file ltree_op.c.

180 {
181  ltree *c = PG_GETARG_LTREE_P(0);
182  ltree *p = PG_GETARG_LTREE_P(1);
183  bool res = inner_isparent(c, p);
184 
185  PG_FREE_IF_COPY(c, 0);
186  PG_FREE_IF_COPY(p, 1);
188 }

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 395 of file ltree_op.c.

396 {
397  ltree *a = PG_GETARG_LTREE_P(1);
398  text *b = PG_GETARG_TEXT_PP(0);
399  char *s;
400  ltree *r,
401  *tmp;
402 
403  s = text_to_cstring(b);
404 
406  PointerGetDatum(s)));
407 
408  pfree(s);
409 
410  r = ltree_concat(tmp, a);
411 
412  pfree(tmp);
413 
414  PG_FREE_IF_COPY(a, 1);
415  PG_FREE_IF_COPY(b, 0);
417 }

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 576 of file ltree_op.c.

577 {
579  Oid operator = PG_GETARG_OID(1);
580  List *args = (List *) PG_GETARG_POINTER(2);
581  int varRelid = PG_GETARG_INT32(3);
582  double selec;
583 
584  /* Use generic restriction selectivity logic, with default 0.001. */
585  selec = generic_restriction_selectivity(root, operator, InvalidOid,
586  args, varRelid,
587  0.001);
588 
589  PG_RETURN_FLOAT8((float8) selec);
590 }
double float8
Definition: c.h:619
#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
double generic_restriction_selectivity(PlannerInfo *root, Oid oproid, Oid collation, List *args, int varRelid, double default_selectivity)
Definition: selfuncs.c:913
Definition: pg_list.h:54

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

◆ nlevel()

Datum nlevel ( PG_FUNCTION_ARGS  )

Definition at line 133 of file ltree_op.c.

134 {
135  ltree *a = PG_GETARG_LTREE_P(0);
136  int res = a->numlevel;
137 
138  PG_FREE_IF_COPY(a, 0);
140 }

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

◆ PG_FUNCTION_INFO_V1() [1/20]

PG_FUNCTION_INFO_V1 ( lca  )

◆ PG_FUNCTION_INFO_V1() [2/20]

PG_FUNCTION_INFO_V1 ( ltree2text  )

◆ PG_FUNCTION_INFO_V1() [3/20]

PG_FUNCTION_INFO_V1 ( ltree_addltree  )

◆ PG_FUNCTION_INFO_V1() [4/20]

PG_FUNCTION_INFO_V1 ( ltree_addtext  )

◆ PG_FUNCTION_INFO_V1() [5/20]

PG_FUNCTION_INFO_V1 ( ltree_cmp  )

◆ PG_FUNCTION_INFO_V1() [6/20]

PG_FUNCTION_INFO_V1 ( ltree_eq  )

◆ PG_FUNCTION_INFO_V1() [7/20]

PG_FUNCTION_INFO_V1 ( ltree_ge  )

◆ PG_FUNCTION_INFO_V1() [8/20]

PG_FUNCTION_INFO_V1 ( ltree_gt  )

◆ PG_FUNCTION_INFO_V1() [9/20]

PG_FUNCTION_INFO_V1 ( ltree_index  )

◆ PG_FUNCTION_INFO_V1() [10/20]

PG_FUNCTION_INFO_V1 ( ltree_isparent  )

◆ PG_FUNCTION_INFO_V1() [11/20]

PG_FUNCTION_INFO_V1 ( ltree_le  )

◆ PG_FUNCTION_INFO_V1() [12/20]

PG_FUNCTION_INFO_V1 ( ltree_lt  )

◆ PG_FUNCTION_INFO_V1() [13/20]

PG_FUNCTION_INFO_V1 ( ltree_ne  )

◆ PG_FUNCTION_INFO_V1() [14/20]

PG_FUNCTION_INFO_V1 ( ltree_risparent  )

◆ PG_FUNCTION_INFO_V1() [15/20]

PG_FUNCTION_INFO_V1 ( ltree_textadd  )

◆ PG_FUNCTION_INFO_V1() [16/20]

PG_FUNCTION_INFO_V1 ( ltreeparentsel  )

◆ PG_FUNCTION_INFO_V1() [17/20]

PG_FUNCTION_INFO_V1 ( nlevel  )

◆ PG_FUNCTION_INFO_V1() [18/20]

PG_FUNCTION_INFO_V1 ( subltree  )

◆ PG_FUNCTION_INFO_V1() [19/20]

PG_FUNCTION_INFO_V1 ( subpath  )

◆ PG_FUNCTION_INFO_V1() [20/20]

PG_FUNCTION_INFO_V1 ( text2ltree  )

◆ subltree()

Datum subltree ( PG_FUNCTION_ARGS  )

Definition at line 231 of file ltree_op.c.

232 {
233  ltree *t = PG_GETARG_LTREE_P(0);
235 
236  PG_FREE_IF_COPY(t, 0);
238 }
static ltree * inner_subltree(ltree *t, int32 startpos, int32 endpos)
Definition: ltree_op.c:192

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 241 of file ltree_op.c.

242 {
243  ltree *t = PG_GETARG_LTREE_P(0);
244  int32 start = PG_GETARG_INT32(1);
245  int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
246  int32 end;
247  ltree *res;
248 
249  end = start + len;
250 
251  if (start < 0)
252  {
253  start = t->numlevel + start;
254  end = start + len;
255  }
256  if (start < 0)
257  { /* start > t->numlevel */
258  start = t->numlevel + start;
259  end = start + len;
260  }
261 
262  if (len < 0)
263  end = t->numlevel + len;
264  else if (len == 0)
265  end = (fcinfo->nargs == 3) ? start : 0xffff;
266 
267  res = inner_subltree(t, start, end);
268 
269  PG_FREE_IF_COPY(t, 0);
271 }
signed int int32
Definition: c.h:483

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

Referenced by add_foreign_final_paths(), add_paths_to_append_rel(), adjust_paths_for_srfs(), append_nonpartial_cost(), apply_scanjoin_target_to_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 522 of file ltree_op.c.

523 {
524  text *in = PG_GETARG_TEXT_PP(0);
525  char *s;
526  ltree *out;
527 
528  s = text_to_cstring(in);
529 
531  PointerGetDatum(s)));
532  pfree(s);
533  PG_FREE_IF_COPY(in, 0);
534  PG_RETURN_POINTER(out);
535 }

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 17 of file ltree_op.c.