PostgreSQL Source Code git master
Loading...
Searching...
No Matches
ltree_op.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "common/hashfn.h"
#include "ltree.h"
#include "utils/builtins.h"
#include "utils/selfuncs.h"
#include "varatt.h"
Include dependency graph for ltree_op.c:

Go to the source code of this file.

Macros

#define RUNCMP
 

Functions

 PG_MODULE_MAGIC_EXT (.name="ltree",.version=PG_VERSION)
 
 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)
 
float ltree_compare_distance (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)
 

Macro Definition Documentation

◆ RUNCMP

#define RUNCMP
Value:
int res = ltree_compare(a,b); \
int b
Definition isn.c:74
int a
Definition isn.c:73
#define PG_GETARG_LTREE_P(n)
Definition ltree.h:220
int ltree_compare(const ltree *a, const ltree *b)
Definition ltree_op.c:49
static int fb(int x)
Definition ltree.h:43

Definition at line 117 of file ltree_op.c.

Function Documentation

◆ hash_ltree()

Datum hash_ltree ( PG_FUNCTION_ARGS  )

Definition at line 175 of file ltree_op.c.

176{
178 uint32 result = 1;
179 int an = a->numlevel;
181
182 while (an > 0)
183 {
184 uint32 levelHash = DatumGetUInt32(hash_any((unsigned char *) al->name, al->len));
185
186 /*
187 * Combine hash values of successive elements by multiplying the
188 * current value by 31 and adding on the new element's hash value.
189 *
190 * This method is borrowed from hash_array(), which see for further
191 * commentary.
192 */
193 result = (result << 5) - result + levelHash;
194
195 an--;
196 al = LEVEL_NEXT(al);
197 }
198
199 PG_FREE_IF_COPY(a, 0);
201}
uint32_t uint32
Definition c.h:680
uint32 result
#define PG_FREE_IF_COPY(ptr, n)
Definition fmgr.h:260
#define PG_RETURN_UINT32(x)
Definition fmgr.h:356
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

References a, DatumGetUInt32(), fb(), hash_any(), LEVEL_NEXT, LTREE_FIRST, PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_RETURN_UINT32, and result.

◆ hash_ltree_extended()

Datum hash_ltree_extended ( PG_FUNCTION_ARGS  )

Definition at line 205 of file ltree_op.c.

206{
208 const uint64 seed = PG_GETARG_INT64(1);
209 uint64 result = 1;
210 int an = a->numlevel;
212
213 /*
214 * If the path has length zero, return 1 + seed to ensure that the low 32
215 * bits of the result match hash_ltree when the seed is 0, as required by
216 * the hash index support functions, but to also return a different value
217 * when there is a seed.
218 */
219 if (an == 0)
220 {
221 PG_FREE_IF_COPY(a, 0);
222 PG_RETURN_UINT64(result + seed);
223 }
224
225 while (an > 0)
226 {
227 uint64 levelHash = DatumGetUInt64(hash_any_extended((unsigned char *) al->name, al->len, seed));
228
229 result = (result << 5) - result + levelHash;
230
231 an--;
232 al = LEVEL_NEXT(al);
233 }
234
235 PG_FREE_IF_COPY(a, 0);
237}
uint64_t uint64
Definition c.h:681
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
#define PG_RETURN_UINT64(x)
Definition fmgr.h:371
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:436

References a, DatumGetUInt64(), fb(), hash_any_extended(), LEVEL_NEXT, LTREE_FIRST, PG_FREE_IF_COPY, PG_GETARG_INT64, PG_GETARG_LTREE_P, PG_RETURN_UINT64, and result.

◆ inner_isparent()

bool inner_isparent ( const ltree c,
const ltree p 
)

Definition at line 250 of file ltree_op.c.

251{
254 int pn = p->numlevel;
255
256 if (pn > c->numlevel)
257 return false;
258
259 while (pn > 0)
260 {
261 if (cl->len != pl->len)
262 return false;
263 if (memcmp(cl->name, pl->name, cl->len) != 0)
264 return false;
265
266 pn--;
267 cl = LEVEL_NEXT(cl);
268 pl = LEVEL_NEXT(pl);
269 }
270 return true;
271}
char * c
uint16 numlevel
Definition ltree.h:45

References fb(), LEVEL_NEXT, LTREE_FIRST, 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 299 of file ltree_op.c.

300{
301 char *start = NULL,
302 *end = NULL;
303 ltree_level *ptr = LTREE_FIRST(t);
304 ltree *res;
305 int i;
306
310 errmsg("invalid positions")));
311
312 if (endpos > t->numlevel)
313 endpos = t->numlevel;
314
315 start = end = (char *) ptr;
316 for (i = 0; i < endpos; i++)
317 {
318 if (i == startpos)
319 start = (char *) ptr;
320 if (i == endpos - 1)
321 {
322 end = (char *) LEVEL_NEXT(ptr);
323 break;
324 }
325 ptr = LEVEL_NEXT(ptr);
326 }
327
328 res = (ltree *) palloc0(LTREE_HDRSIZE + (end - start));
329 SET_VARSIZE(res, LTREE_HDRSIZE + (end - start));
330 res->numlevel = endpos - startpos;
331
332 memcpy(LTREE_FIRST(res), start, end - start);
333
334 return res;
335}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
return str start
int i
Definition isn.c:77
#define LTREE_HDRSIZE
Definition ltree.h:50
void * palloc0(Size size)
Definition mcxt.c:1420
static char * errmsg
static XLogRecPtr endpos
static XLogRecPtr startpos
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

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

Referenced by subltree(), and subpath().

◆ lca()

Definition at line 600 of file ltree_op.c.

601{
602 int i;
603 ltree **a,
604 *res;
605
606 a = palloc_array(ltree *, fcinfo->nargs);
607 for (i = 0; i < fcinfo->nargs; i++)
609 res = lca_inner(a, (int) fcinfo->nargs);
610 for (i = 0; i < fcinfo->nargs; i++)
611 PG_FREE_IF_COPY(a[i], i);
612 pfree(a);
613
614 if (res)
616 else
618}
#define palloc_array(type, count)
Definition fe_memutils.h:91
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
ltree * lca_inner(ltree **a, int len)
Definition ltree_op.c:525
void pfree(void *pointer)
Definition mcxt.c:1619

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

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

526{
527 int tmp,
528 num,
529 i,
530 reslen;
531 ltree **ptr;
532 ltree_level *l1,
533 *l2;
534 ltree *res;
535
536 if (len <= 0)
537 return NULL; /* no inputs? */
538 if ((*a)->numlevel == 0)
539 return NULL; /* any empty input means NULL result */
540
541 /* num is the length of the longest common ancestor so far */
542 num = (*a)->numlevel - 1;
543
544 /* Compare each additional input to *a */
545 ptr = a + 1;
546 while (ptr - a < len)
547 {
548 if ((*ptr)->numlevel == 0)
549 return NULL;
550 else if ((*ptr)->numlevel == 1)
551 num = 0;
552 else
553 {
554 l1 = LTREE_FIRST(*a);
555 l2 = LTREE_FIRST(*ptr);
556 tmp = Min(num, (*ptr)->numlevel - 1);
557 num = 0;
558 for (i = 0; i < tmp; i++)
559 {
560 if (l1->len == l2->len &&
561 memcmp(l1->name, l2->name, l1->len) == 0)
562 num = i + 1;
563 else
564 break;
565 l1 = LEVEL_NEXT(l1);
566 l2 = LEVEL_NEXT(l2);
567 }
568 }
569 ptr++;
570 }
571
572 /* Now compute size of result ... */
573 reslen = LTREE_HDRSIZE;
574 l1 = LTREE_FIRST(*a);
575 for (i = 0; i < num; i++)
576 {
577 reslen += MAXALIGN(l1->len + LEVEL_HDRSIZE);
578 l1 = LEVEL_NEXT(l1);
579 }
580
581 /* ... and construct it by copying from *a */
582 res = (ltree *) palloc0(reslen);
583 SET_VARSIZE(res, reslen);
584 res->numlevel = num;
585
586 l1 = LTREE_FIRST(*a);
587 l2 = LTREE_FIRST(res);
588
589 for (i = 0; i < num; i++)
590 {
591 memcpy(l2, l1, MAXALIGN(l1->len + LEVEL_HDRSIZE));
592 l1 = LEVEL_NEXT(l1);
593 l2 = LEVEL_NEXT(l2);
594 }
595
596 return res;
597}
#define Min(x, y)
Definition c.h:1147
#define MAXALIGN(LEN)
Definition c.h:952
#define LEVEL_HDRSIZE
Definition ltree.h:39
const void size_t len
char name[FLEXIBLE_ARRAY_MEMBER]
Definition ltree.h:36
uint16 len
Definition ltree.h:35

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

Referenced by _lca(), and lca().

◆ ltree2text()

Datum ltree2text ( PG_FUNCTION_ARGS  )

Definition at line 638 of file ltree_op.c.

639{
640 ltree *in = PG_GETARG_LTREE_P(0);
641 char *ptr;
642 int i;
644 text *out;
645
646 out = (text *) palloc(VARSIZE(in) + VARHDRSZ);
647 ptr = VARDATA(out);
648 curlevel = LTREE_FIRST(in);
649 for (i = 0; i < in->numlevel; i++)
650 {
651 if (i != 0)
652 {
653 *ptr = '.';
654 ptr++;
655 }
656 memcpy(ptr, curlevel->name, curlevel->len);
657 ptr += curlevel->len;
659 }
660
661 SET_VARSIZE(out, ptr - ((char *) out));
662 PG_FREE_IF_COPY(in, 0);
663
665}
#define VARHDRSZ
Definition c.h:837
void * palloc(Size size)
Definition mcxt.c:1390
Definition c.h:832
static Size VARSIZE(const void *PTR)
Definition varatt.h:298
static char * VARDATA(const void *PTR)
Definition varatt.h:305

References fb(), i, LEVEL_NEXT, LTREE_FIRST, memcpy(), 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 396 of file ltree_op.c.

397{
400 ltree *r;
401
402 r = ltree_concat(a, b);
403 PG_FREE_IF_COPY(a, 0);
404 PG_FREE_IF_COPY(b, 1);
406}
static ltree * ltree_concat(ltree *a, ltree *b)
Definition ltree_op.c:373

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

410{
413 char *s;
414 ltree *r,
415 *tmp;
416
417 s = text_to_cstring(b);
418
420 PointerGetDatum(s)));
421
422 pfree(s);
423
424 r = ltree_concat(a, tmp);
425
426 pfree(tmp);
427
428 PG_FREE_IF_COPY(a, 0);
429 PG_FREE_IF_COPY(b, 1);
431}
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:688
PGDLLEXPORT Datum ltree_in(PG_FUNCTION_ARGS)
Definition ltree_io.c:175
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
#define PointerGetDatum(X)
Definition postgres.h:354
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 125 of file ltree_op.c.

126{
127 RUNCMP;
128 PG_RETURN_INT32(res);
129}
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define RUNCMP
Definition ltree_op.c:117

References PG_RETURN_INT32, and RUNCMP.

◆ ltree_compare()

int ltree_compare ( const ltree a,
const ltree b 
)

Definition at line 49 of file ltree_op.c.

50{
53 int an = a->numlevel;
54 int bn = b->numlevel;
55
56 while (an > 0 && bn > 0)
57 {
58 int res;
59
60 res = memcmp(al->name, bl->name, Min(al->len, bl->len));
61 if (res == 0)
62 {
63 if (al->len != bl->len)
64 return (int) al->len - (int) bl->len;
65 }
66 else
67 return res;
68
69 an--;
70 bn--;
71 al = LEVEL_NEXT(al);
72 bl = LEVEL_NEXT(bl);
73 }
74
75 return a->numlevel - b->numlevel;
76}

References a, b, fb(), LEVEL_NEXT, LTREE_FIRST, and Min.

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

◆ ltree_compare_distance()

float ltree_compare_distance ( const ltree a,
const ltree b 
)

Definition at line 83 of file ltree_op.c.

84{
87 int an = a->numlevel;
88 int bn = b->numlevel;
89
90 while (an > 0 && bn > 0)
91 {
92 int res;
93
94 res = memcmp(al->name, bl->name, Min(al->len, bl->len));
95 if (res == 0)
96 {
97 if (al->len != bl->len)
98 return (float) (al->len - bl->len) * 10.0 * (an + 1);
99 }
100 else
101 {
102 if (res < 0)
103 return -1.0 * 10.0 * (an + 1);
104 else
105 return 1.0 * 10.0 * (an + 1);
106 }
107
108 an--;
109 bn--;
110 al = LEVEL_NEXT(al);
111 bl = LEVEL_NEXT(bl);
112 }
113
114 return ((float) (a->numlevel - b->numlevel)) * 10.0 * (an + 1);
115}

References a, b, fb(), LEVEL_NEXT, LTREE_FIRST, and Min.

Referenced by ltree_penalty().

◆ ltree_concat()

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

Definition at line 373 of file ltree_op.c.

374{
375 ltree *r;
376 int numlevel = (int) a->numlevel + b->numlevel;
377
378 if (numlevel > LTREE_MAX_LEVELS)
381 errmsg("number of ltree levels (%d) exceeds the maximum allowed (%d)",
382 numlevel, LTREE_MAX_LEVELS)));
383
386 r->numlevel = (uint16) numlevel;
387
389 memcpy(((char *) LTREE_FIRST(r)) + VARSIZE(a) - LTREE_HDRSIZE,
390 LTREE_FIRST(b),
392 return r;
393}
uint16_t uint16
Definition c.h:679
#define LTREE_MAX_LEVELS
Definition ltree.h:52

References a, b, ereport, errcode(), errmsg, ERROR, fb(), LTREE_FIRST, LTREE_HDRSIZE, LTREE_MAX_LEVELS, memcpy(), 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 146 of file ltree_op.c.

147{
148 RUNCMP;
149 PG_RETURN_BOOL(res == 0);
150}
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360

References PG_RETURN_BOOL, and RUNCMP.

◆ ltree_ge()

Datum ltree_ge ( PG_FUNCTION_ARGS  )

Definition at line 153 of file ltree_op.c.

154{
155 RUNCMP;
156 PG_RETURN_BOOL(res >= 0);
157}

References PG_RETURN_BOOL, and RUNCMP.

◆ ltree_gt()

Datum ltree_gt ( PG_FUNCTION_ARGS  )

Definition at line 160 of file ltree_op.c.

161{
162 RUNCMP;
163 PG_RETURN_BOOL(res > 0);
164}

References PG_RETURN_BOOL, and RUNCMP.

◆ ltree_index()

Datum ltree_index ( PG_FUNCTION_ARGS  )

Definition at line 434 of file ltree_op.c.

435{
438 int start = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
439 int i,
440 j;
441 ltree_level *startptr,
442 *aptr,
443 *bptr;
444 bool found = false;
445
446 if (start < 0)
447 {
448 if (-start >= a->numlevel)
449 start = 0;
450 else
451 start = (int) (a->numlevel) + start;
452 }
453
454 if (a->numlevel - start < b->numlevel || a->numlevel == 0 || b->numlevel == 0)
455 {
456 PG_FREE_IF_COPY(a, 0);
457 PG_FREE_IF_COPY(b, 1);
458 PG_RETURN_INT32(-1);
459 }
460
461 startptr = LTREE_FIRST(a);
462 for (i = 0; i <= a->numlevel - b->numlevel; i++)
463 {
464 if (i >= start)
465 {
466 aptr = startptr;
467 bptr = LTREE_FIRST(b);
468 for (j = 0; j < b->numlevel; j++)
469 {
470 if (!(aptr->len == bptr->len && memcmp(aptr->name, bptr->name, aptr->len) == 0))
471 break;
474 }
475
476 if (j == b->numlevel)
477 {
478 found = true;
479 break;
480 }
481 }
482 startptr = LEVEL_NEXT(startptr);
483 }
484
485 if (!found)
486 i = -1;
487
488 PG_FREE_IF_COPY(a, 0);
489 PG_FREE_IF_COPY(b, 1);
491}
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
int j
Definition isn.c:78

References a, b, fb(), i, j, LEVEL_NEXT, LTREE_FIRST, 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 274 of file ltree_op.c.

275{
277 ltree *p = PG_GETARG_LTREE_P(0);
278 bool res = inner_isparent(c, p);
279
280 PG_FREE_IF_COPY(c, 1);
281 PG_FREE_IF_COPY(p, 0);
282 PG_RETURN_BOOL(res);
283}
bool inner_isparent(const ltree *c, const ltree *p)
Definition ltree_op.c:250

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

Referenced by _ltree_extract_isparent(), and _ltree_isparent().

◆ ltree_le()

Datum ltree_le ( PG_FUNCTION_ARGS  )

Definition at line 139 of file ltree_op.c.

140{
141 RUNCMP;
142 PG_RETURN_BOOL(res <= 0);
143}

References PG_RETURN_BOOL, and RUNCMP.

◆ ltree_lt()

Datum ltree_lt ( PG_FUNCTION_ARGS  )

Definition at line 132 of file ltree_op.c.

133{
134 RUNCMP;
135 PG_RETURN_BOOL(res < 0);
136}

References PG_RETURN_BOOL, and RUNCMP.

◆ ltree_ne()

Datum ltree_ne ( PG_FUNCTION_ARGS  )

Definition at line 167 of file ltree_op.c.

168{
169 RUNCMP;
170 PG_RETURN_BOOL(res != 0);
171}

References PG_RETURN_BOOL, and RUNCMP.

◆ ltree_risparent()

Datum ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 286 of file ltree_op.c.

287{
289 ltree *p = PG_GETARG_LTREE_P(1);
290 bool res = inner_isparent(c, p);
291
292 PG_FREE_IF_COPY(c, 0);
293 PG_FREE_IF_COPY(p, 1);
294 PG_RETURN_BOOL(res);
295}

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

Referenced by _ltree_extract_risparent(), and _ltree_risparent().

◆ ltree_textadd()

Datum ltree_textadd ( PG_FUNCTION_ARGS  )

Definition at line 494 of file ltree_op.c.

495{
498 char *s;
499 ltree *r,
500 *tmp;
501
502 s = text_to_cstring(b);
503
505 PointerGetDatum(s)));
506
507 pfree(s);
508
509 r = ltree_concat(tmp, a);
510
511 pfree(tmp);
512
513 PG_FREE_IF_COPY(a, 1);
514 PG_FREE_IF_COPY(b, 0);
516}

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

676{
678 Oid operator = PG_GETARG_OID(1);
680 int varRelid = PG_GETARG_INT32(3);
681 double selec;
682
683 /* Use generic restriction selectivity logic, with default 0.001. */
685 args, varRelid,
686 0.001);
687
689}
double float8
Definition c.h:770
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define InvalidOid
unsigned int Oid
tree ctl root
Definition radixtree.h:1857
double generic_restriction_selectivity(PlannerInfo *root, Oid oproid, Oid collation, List *args, int varRelid, double default_selectivity)
Definition selfuncs.c:987
Definition pg_list.h:54

References fb(), 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 240 of file ltree_op.c.

241{
243 int res = a->numlevel;
244
245 PG_FREE_IF_COPY(a, 0);
246 PG_RETURN_INT32(res);
247}

References a, PG_FREE_IF_COPY, PG_GETARG_LTREE_P, and PG_RETURN_INT32.

◆ 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  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "ltree",
version = PG_VERSION 
)

◆ subltree()

Datum subltree ( PG_FUNCTION_ARGS  )

Definition at line 338 of file ltree_op.c.

339{
340 ltree *t = PG_GETARG_LTREE_P(0);
342
343 PG_FREE_IF_COPY(t, 0);
345}
static ltree * inner_subltree(ltree *t, int32 startpos, int32 endpos)
Definition ltree_op.c:299

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

◆ subpath()

Datum subpath ( PG_FUNCTION_ARGS  )

Definition at line 348 of file ltree_op.c.

349{
350 ltree *t = PG_GETARG_LTREE_P(0);
352 int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
353 int32 end;
354 ltree *res;
355
356 if (start < 0)
357 start = t->numlevel + start;
358
359 if (len < 0)
360 end = t->numlevel + len;
361 else if (len == 0)
362 end = (fcinfo->nargs == 3) ? start : LTREE_MAX_LEVELS;
363 else
364 end = start + len;
365
366 res = inner_subltree(t, start, end);
367
368 PG_FREE_IF_COPY(t, 0);
370}
int32_t int32
Definition c.h:676

References inner_subltree(), len, LTREE_MAX_LEVELS, ltree::numlevel, PG_FREE_IF_COPY, PG_GETARG_INT32, PG_GETARG_LTREE_P, PG_RETURN_POINTER, 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_sort_path(), create_subqueryscan_path(), create_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 621 of file ltree_op.c.

622{
623 text *in = PG_GETARG_TEXT_PP(0);
624 char *s;
625 ltree *out;
626
627 s = text_to_cstring(in);
628
630 PointerGetDatum(s)));
631 pfree(s);
632 PG_FREE_IF_COPY(in, 0);
634}

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