PostgreSQL Source Code  git master
ltree.h File Reference
#include "fmgr.h"
#include "tsearch/ts_locale.h"
#include "utils/memutils.h"
Include dependency graph for ltree.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ltree_level
 
struct  ltree
 
struct  lquery_variant
 
struct  lquery_level
 
struct  lquery
 
struct  ITEM
 
struct  ltxtquery
 
struct  ltree_gist
 
struct  LtreeGistOptions
 

Macros

#define LTREE_LABEL_MAX_CHARS   255
 
#define LEVEL_HDRSIZE   (offsetof(ltree_level,name))
 
#define LEVEL_NEXT(x)   ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) )
 
#define LTREE_HDRSIZE   MAXALIGN( offsetof(ltree, data) )
 
#define LTREE_FIRST(x)   ( (ltree_level*)( ((char*)(x))+LTREE_HDRSIZE ) )
 
#define LTREE_MAX_LEVELS   PG_UINT16_MAX /* ltree.numlevel is uint16 */
 
#define LVAR_HDRSIZE   MAXALIGN(offsetof(lquery_variant, name))
 
#define LVAR_NEXT(x)   ( (lquery_variant*)( ((char*)(x)) + MAXALIGN(((lquery_variant*)(x))->len) + LVAR_HDRSIZE ) )
 
#define LVAR_ANYEND   0x01 /* '*' flag: prefix match */
 
#define LVAR_INCASE   0x02 /* '@' flag: case-insensitive match */
 
#define LVAR_SUBLEXEME   0x04 /* '%' flag: word-wise match */
 
#define LQL_HDRSIZE   MAXALIGN( offsetof(lquery_level,variants) )
 
#define LQL_NEXT(x)   ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) )
 
#define LQL_FIRST(x)   ( (lquery_variant*)( ((char*)(x))+LQL_HDRSIZE ) )
 
#define LQL_NOT   0x10 /* level has '!' (NOT) prefix */
 
#define LQL_COUNT   0x20 /* level is non-'*' and has repeat counts */
 
#define FLG_CANLOOKSIGN(x)   ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME | LVAR_INCASE ) ) == 0 )
 
#define LQL_CANLOOKSIGN(x)   FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag )
 
#define LQUERY_HDRSIZE   MAXALIGN( offsetof(lquery, data) )
 
#define LQUERY_FIRST(x)   ( (lquery_level*)( ((char*)(x))+LQUERY_HDRSIZE ) )
 
#define LQUERY_MAX_LEVELS   PG_UINT16_MAX /* lquery.numlevel is uint16 */
 
#define LQUERY_HASNOT   0x01
 
#define ISALNUM(x)   ( t_isalpha(x) || t_isdigit(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
 
#define HDRSIZEQT   MAXALIGN(VARHDRSZ + sizeof(int32))
 
#define COMPUTESIZE(size, lenofoperand)   ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )
 
#define LTXTQUERY_TOO_BIG(size, lenofoperand)   ((size) > (MaxAllocSize - HDRSIZEQT - (lenofoperand)) / sizeof(ITEM))
 
#define GETQUERY(x)   (ITEM*)( (char*)(x)+HDRSIZEQT )
 
#define GETOPERAND(x)   ( (char*)GETQUERY(x) + ((ltxtquery*)x)->size * sizeof(ITEM) )
 
#define ISOPERATOR(x)   ( (x)=='!' || (x)=='&' || (x)=='|' || (x)=='(' || (x)==')' )
 
#define END   0
 
#define ERR   1
 
#define VAL   2
 
#define OPR   3
 
#define OPEN   4
 
#define CLOSE   5
 
#define VALTRUE   6 /* for stop words */
 
#define VALFALSE   7
 
#define DatumGetLtreeP(X)   ((ltree *) PG_DETOAST_DATUM(X))
 
#define DatumGetLtreePCopy(X)   ((ltree *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_LTREE_P(n)   DatumGetLtreeP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_LTREE_P_COPY(n)   DatumGetLtreePCopy(PG_GETARG_DATUM(n))
 
#define DatumGetLqueryP(X)   ((lquery *) PG_DETOAST_DATUM(X))
 
#define DatumGetLqueryPCopy(X)   ((lquery *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_LQUERY_P(n)   DatumGetLqueryP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_LQUERY_P_COPY(n)   DatumGetLqueryPCopy(PG_GETARG_DATUM(n))
 
#define DatumGetLtxtqueryP(X)   ((ltxtquery *) PG_DETOAST_DATUM(X))
 
#define DatumGetLtxtqueryPCopy(X)   ((ltxtquery *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_LTXTQUERY_P(n)   DatumGetLtxtqueryP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_LTXTQUERY_P_COPY(n)   DatumGetLtxtqueryPCopy(PG_GETARG_DATUM(n))
 
#define SIGLEN_MAX   GISTMaxIndexKeySize
 
#define SIGLEN_DEFAULT   (2 * sizeof(int32))
 
#define BITBYTE   8
 
#define SIGLEN   (sizeof(int32) * SIGLENINT)
 
#define SIGLENBIT(siglen)   ((siglen) * BITBYTE)
 
#define LOOPBYTE(siglen)   for(i = 0; i < (siglen); i++)
 
#define GETBYTE(x, i)   ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
 
#define GETBITBYTE(x, i)   ( ((unsigned char)(x)) >> i & 0x01 )
 
#define CLRBIT(x, i)   GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
 
#define SETBIT(x, i)   GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
 
#define GETBIT(x, i)   ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
 
#define HASHVAL(val, siglen)   (((unsigned int)(val)) % SIGLENBIT(siglen))
 
#define HASH(sign, val, siglen)   SETBIT((sign), HASHVAL(val, siglen))
 
#define LTG_ONENODE   0x01
 
#define LTG_ALLTRUE   0x02
 
#define LTG_NORIGHT   0x04
 
#define LTG_HDRSIZE   MAXALIGN(VARHDRSZ + sizeof(uint32))
 
#define LTG_SIGN(x)   ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) )
 
#define LTG_NODE(x)   ( (ltree*)( ((char*)(x))+LTG_HDRSIZE ) )
 
#define LTG_ISONENODE(x)   ( ((ltree_gist*)(x))->flag & LTG_ONENODE )
 
#define LTG_ISALLTRUE(x)   ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE )
 
#define LTG_ISNORIGHT(x)   ( ((ltree_gist*)(x))->flag & LTG_NORIGHT )
 
#define LTG_LNODE(x, siglen)   ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : (siglen) ) ) )
 
#define LTG_RENODE(x, siglen)   ( (ltree*)( ((char*)LTG_LNODE(x, siglen)) + VARSIZE(LTG_LNODE(x, siglen))) )
 
#define LTG_RNODE(x, siglen)   ( LTG_ISNORIGHT(x) ? LTG_LNODE(x, siglen) : LTG_RENODE(x, siglen) )
 
#define LTG_GETLNODE(x, siglen)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x, siglen) )
 
#define LTG_GETRNODE(x, siglen)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x, siglen) )
 
#define LTREE_ASIGLEN_DEFAULT   (7 * sizeof(int32))
 
#define LTREE_ASIGLEN_MAX   GISTMaxIndexKeySize
 
#define LTREE_GET_ASIGLEN()
 
#define ASIGLENBIT(siglen)   ((siglen) * BITBYTE)
 
#define ALOOPBYTE(siglen)   for (i = 0; i < (siglen); i++)
 
#define AHASHVAL(val, siglen)   (((unsigned int)(val)) % ASIGLENBIT(siglen))
 
#define AHASH(sign, val, siglen)   SETBIT((sign), AHASHVAL(val, siglen))
 

Typedefs

typedef struct ITEM ITEM
 
typedef unsigned char * BITVECP
 

Functions

Datum ltree_isparent (PG_FUNCTION_ARGS)
 
Datum ltree_risparent (PG_FUNCTION_ARGS)
 
Datum ltq_regex (PG_FUNCTION_ARGS)
 
Datum ltq_rregex (PG_FUNCTION_ARGS)
 
Datum lt_q_regex (PG_FUNCTION_ARGS)
 
Datum lt_q_rregex (PG_FUNCTION_ARGS)
 
Datum ltxtq_exec (PG_FUNCTION_ARGS)
 
Datum ltxtq_rexec (PG_FUNCTION_ARGS)
 
Datum _ltq_regex (PG_FUNCTION_ARGS)
 
Datum _ltq_rregex (PG_FUNCTION_ARGS)
 
Datum _lt_q_regex (PG_FUNCTION_ARGS)
 
Datum _lt_q_rregex (PG_FUNCTION_ARGS)
 
Datum _ltxtq_exec (PG_FUNCTION_ARGS)
 
Datum _ltxtq_rexec (PG_FUNCTION_ARGS)
 
Datum _ltree_isparent (PG_FUNCTION_ARGS)
 
Datum _ltree_risparent (PG_FUNCTION_ARGS)
 
Datum ltree_addltree (PG_FUNCTION_ARGS)
 
Datum ltree_addtext (PG_FUNCTION_ARGS)
 
Datum ltree_textadd (PG_FUNCTION_ARGS)
 
Datum ltree_in (PG_FUNCTION_ARGS)
 
bool ltree_execute (ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
 
int ltree_compare (const ltree *a, const ltree *b)
 
bool inner_isparent (const ltree *c, const ltree *p)
 
bool compare_subnode (ltree_level *t, char *q, int len, int(*cmpptr)(const char *, const char *, size_t), bool anyend)
 
ltreelca_inner (ltree **a, int len)
 
int ltree_strncasecmp (const char *a, const char *b, size_t s)
 
ltree_gistltree_gist_alloc (bool isalltrue, BITVECP sign, int siglen, ltree *left, ltree *right)
 

Macro Definition Documentation

◆ AHASH

#define AHASH (   sign,
  val,
  siglen 
)    SETBIT((sign), AHASHVAL(val, siglen))

Definition at line 290 of file ltree.h.

Referenced by hashing().

◆ AHASHVAL

#define AHASHVAL (   val,
  siglen 
)    (((unsigned int)(val)) % ASIGLENBIT(siglen))

Definition at line 289 of file ltree.h.

Referenced by checkcondition_bit(), gist_qe(), and gist_te().

◆ ALOOPBYTE

#define ALOOPBYTE (   siglen)    for (i = 0; i < (siglen); i++)

Definition at line 286 of file ltree.h.

Referenced by _ltree_compress(), _ltree_picksplit(), _ltree_same(), hemdistsign(), and unionkey().

◆ ASIGLENBIT

#define ASIGLENBIT (   siglen)    ((siglen) * BITBYTE)

Definition at line 284 of file ltree.h.

Referenced by hemdist().

◆ BITBYTE

#define BITBYTE   8

Definition at line 221 of file ltree.h.

◆ CLOSE

#define CLOSE   5

Definition at line 160 of file ltree.h.

◆ CLRBIT

#define CLRBIT (   x,
  i 
)    GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )

Definition at line 232 of file ltree.h.

◆ COMPUTESIZE

#define COMPUTESIZE (   size,
  lenofoperand 
)    ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )

Definition at line 147 of file ltree.h.

◆ DatumGetLqueryP

#define DatumGetLqueryP (   X)    ((lquery *) PG_DETOAST_DATUM(X))

Definition at line 207 of file ltree.h.

◆ DatumGetLqueryPCopy

#define DatumGetLqueryPCopy (   X)    ((lquery *) PG_DETOAST_DATUM_COPY(X))

Definition at line 208 of file ltree.h.

◆ DatumGetLtreeP

#define DatumGetLtreeP (   X)    ((ltree *) PG_DETOAST_DATUM(X))

Definition at line 202 of file ltree.h.

Referenced by ltree_compress().

◆ DatumGetLtreePCopy

#define DatumGetLtreePCopy (   X)    ((ltree *) PG_DETOAST_DATUM_COPY(X))

Definition at line 203 of file ltree.h.

◆ DatumGetLtxtqueryP

#define DatumGetLtxtqueryP (   X)    ((ltxtquery *) PG_DETOAST_DATUM(X))

Definition at line 212 of file ltree.h.

◆ DatumGetLtxtqueryPCopy

#define DatumGetLtxtqueryPCopy (   X)    ((ltxtquery *) PG_DETOAST_DATUM_COPY(X))

Definition at line 213 of file ltree.h.

◆ END

#define END   0

Definition at line 155 of file ltree.h.

◆ ERR

#define ERR   1

Definition at line 156 of file ltree.h.

◆ FLG_CANLOOKSIGN

#define FLG_CANLOOKSIGN (   x)    ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME | LVAR_INCASE ) ) == 0 )

Definition at line 96 of file ltree.h.

Referenced by checkcondition_bit().

◆ GETBIT

#define GETBIT (   x,
  i 
)    ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )

Definition at line 234 of file ltree.h.

◆ GETBITBYTE

#define GETBITBYTE (   x,
  i 
)    ( ((unsigned char)(x)) >> i & 0x01 )

Definition at line 231 of file ltree.h.

◆ GETBYTE

#define GETBYTE (   x,
  i 
)    ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )

Definition at line 230 of file ltree.h.

◆ GETOPERAND

◆ GETQUERY

#define GETQUERY (   x)    (ITEM*)( (char*)(x)+HDRSIZEQT )

Definition at line 150 of file ltree.h.

◆ HASH

#define HASH (   sign,
  val,
  siglen 
)    SETBIT((sign), HASHVAL(val, siglen))

Definition at line 237 of file ltree.h.

◆ HASHVAL

#define HASHVAL (   val,
  siglen 
)    (((unsigned int)(val)) % SIGLENBIT(siglen))

Definition at line 236 of file ltree.h.

◆ HDRSIZEQT

#define HDRSIZEQT   MAXALIGN(VARHDRSZ + sizeof(int32))

Definition at line 146 of file ltree.h.

◆ ISALNUM

#define ISALNUM (   x)    ( t_isalpha(x) || t_isdigit(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )

Definition at line 116 of file ltree.h.

Referenced by gettoken_query(), lquery_in(), and ltree_in().

◆ ISOPERATOR

#define ISOPERATOR (   x)    ( (x)=='!' || (x)=='&' || (x)=='|' || (x)=='(' || (x)==')' )

Definition at line 153 of file ltree.h.

Referenced by gettoken_query_websearch(), and gettoken_tsvector().

◆ LEVEL_HDRSIZE

#define LEVEL_HDRSIZE   (offsetof(ltree_level,name))

Definition at line 26 of file ltree.h.

Referenced by lca_inner(), and ltree_in().

◆ LEVEL_NEXT

◆ LOOPBYTE

#define LOOPBYTE (   siglen)    for(i = 0; i < (siglen); i++)

Definition at line 227 of file ltree.h.

◆ LQL_CANLOOKSIGN

#define LQL_CANLOOKSIGN (   x)    FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag )

Definition at line 98 of file ltree.h.

Referenced by gist_qe().

◆ LQL_COUNT

#define LQL_COUNT   0x20 /* level is non-'*' and has repeat counts */

Definition at line 91 of file ltree.h.

Referenced by checkCond(), lquery_in(), and lquery_out().

◆ LQL_FIRST

#define LQL_FIRST (   x)    ( (lquery_variant*)( ((char*)(x))+LQL_HDRSIZE ) )

Definition at line 88 of file ltree.h.

Referenced by checkLevel(), gist_qe(), gist_tqcmp(), lquery_in(), and lquery_out().

◆ LQL_HDRSIZE

#define LQL_HDRSIZE   MAXALIGN( offsetof(lquery_level,variants) )

Definition at line 86 of file ltree.h.

Referenced by lquery_in().

◆ LQL_NEXT

#define LQL_NEXT (   x)    ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) )

Definition at line 87 of file ltree.h.

Referenced by checkCond(), gist_qe(), gist_tqcmp(), lquery_in(), and lquery_out().

◆ LQL_NOT

#define LQL_NOT   0x10 /* level has '!' (NOT) prefix */

Definition at line 90 of file ltree.h.

Referenced by checkLevel(), lquery_in(), and lquery_out().

◆ LQUERY_FIRST

#define LQUERY_FIRST (   x)    ( (lquery_level*)( ((char*)(x))+LQUERY_HDRSIZE ) )

Definition at line 111 of file ltree.h.

Referenced by gist_qe(), gist_tqcmp(), lquery_in(), lquery_out(), and ltq_regex().

◆ LQUERY_HASNOT

#define LQUERY_HASNOT   0x01

Definition at line 114 of file ltree.h.

Referenced by lquery_in().

◆ LQUERY_HDRSIZE

#define LQUERY_HDRSIZE   MAXALIGN( offsetof(lquery, data) )

Definition at line 110 of file ltree.h.

Referenced by lquery_in().

◆ LQUERY_MAX_LEVELS

#define LQUERY_MAX_LEVELS   PG_UINT16_MAX /* lquery.numlevel is uint16 */

Definition at line 112 of file ltree.h.

Referenced by lquery_in().

◆ LTG_ALLTRUE

#define LTG_ALLTRUE   0x02

Definition at line 258 of file ltree.h.

Referenced by _ltree_union(), and ltree_gist_alloc().

◆ LTG_GETLNODE

#define LTG_GETLNODE (   x,
  siglen 
)    ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x, siglen) )

◆ LTG_GETRNODE

#define LTG_GETRNODE (   x,
  siglen 
)    ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x, siglen) )

◆ LTG_HDRSIZE

#define LTG_HDRSIZE   MAXALIGN(VARHDRSZ + sizeof(uint32))

Definition at line 261 of file ltree.h.

Referenced by _ltree_union(), and ltree_gist_alloc().

◆ LTG_ISALLTRUE

#define LTG_ISALLTRUE (   x)    ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE )

◆ LTG_ISNORIGHT

#define LTG_ISNORIGHT (   x)    ( ((ltree_gist*)(x))->flag & LTG_NORIGHT )

Definition at line 266 of file ltree.h.

◆ LTG_ISONENODE

#define LTG_ISONENODE (   x)    ( ((ltree_gist*)(x))->flag & LTG_ONENODE )

Definition at line 264 of file ltree.h.

Referenced by ltree_picksplit(), ltree_same(), and ltree_union().

◆ LTG_LNODE

#define LTG_LNODE (   x,
  siglen 
)    ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : (siglen) ) ) )

Definition at line 267 of file ltree.h.

Referenced by ltree_gist_alloc(), ltree_same(), and ltree_union().

◆ LTG_NODE

#define LTG_NODE (   x)    ( (ltree*)( ((char*)(x))+LTG_HDRSIZE ) )

Definition at line 263 of file ltree.h.

Referenced by ltree_consistent(), ltree_gist_alloc(), ltree_picksplit(), ltree_same(), and ltree_union().

◆ LTG_NORIGHT

#define LTG_NORIGHT   0x04

Definition at line 259 of file ltree.h.

Referenced by ltree_gist_alloc().

◆ LTG_ONENODE

#define LTG_ONENODE   0x01

Definition at line 257 of file ltree.h.

Referenced by ltree_gist_alloc().

◆ LTG_RENODE

#define LTG_RENODE (   x,
  siglen 
)    ( (ltree*)( ((char*)LTG_LNODE(x, siglen)) + VARSIZE(LTG_LNODE(x, siglen))) )

Definition at line 268 of file ltree.h.

◆ LTG_RNODE

#define LTG_RNODE (   x,
  siglen 
)    ( LTG_ISNORIGHT(x) ? LTG_LNODE(x, siglen) : LTG_RENODE(x, siglen) )

Definition at line 269 of file ltree.h.

Referenced by ltree_gist_alloc(), ltree_same(), and ltree_union().

◆ LTG_SIGN

◆ LTREE_ASIGLEN_DEFAULT

#define LTREE_ASIGLEN_DEFAULT   (7 * sizeof(int32))

Definition at line 279 of file ltree.h.

Referenced by _ltree_gist_options().

◆ LTREE_ASIGLEN_MAX

#define LTREE_ASIGLEN_MAX   GISTMaxIndexKeySize

Definition at line 280 of file ltree.h.

Referenced by _ltree_gist_options().

◆ LTREE_FIRST

◆ LTREE_GET_ASIGLEN

#define LTREE_GET_ASIGLEN ( )

◆ LTREE_HDRSIZE

#define LTREE_HDRSIZE   MAXALIGN( offsetof(ltree, data) )

Definition at line 37 of file ltree.h.

Referenced by inner_subltree(), lca_inner(), ltree_concat(), and ltree_in().

◆ LTREE_LABEL_MAX_CHARS

#define LTREE_LABEL_MAX_CHARS   255

Definition at line 18 of file ltree.h.

Referenced by lquery_in(), and ltree_in().

◆ LTREE_MAX_LEVELS

#define LTREE_MAX_LEVELS   PG_UINT16_MAX /* ltree.numlevel is uint16 */

Definition at line 39 of file ltree.h.

Referenced by lquery_in(), lquery_out(), ltree_concat(), and ltree_in().

◆ LTXTQUERY_TOO_BIG

#define LTXTQUERY_TOO_BIG (   size,
  lenofoperand 
)    ((size) > (MaxAllocSize - HDRSIZEQT - (lenofoperand)) / sizeof(ITEM))

Definition at line 148 of file ltree.h.

Referenced by queryin().

◆ LVAR_ANYEND

#define LVAR_ANYEND   0x01 /* '*' flag: prefix match */

Definition at line 61 of file ltree.h.

Referenced by checkcondition_str(), checkLevel(), gettoken_query(), infix(), lquery_in(), and lquery_out().

◆ LVAR_HDRSIZE

#define LVAR_HDRSIZE   MAXALIGN(offsetof(lquery_variant, name))

Definition at line 58 of file ltree.h.

Referenced by lquery_in().

◆ LVAR_INCASE

#define LVAR_INCASE   0x02 /* '@' flag: case-insensitive match */

Definition at line 62 of file ltree.h.

Referenced by checkcondition_str(), checkLevel(), gettoken_query(), infix(), lquery_in(), and lquery_out().

◆ LVAR_NEXT

#define LVAR_NEXT (   x)    ( (lquery_variant*)( ((char*)(x)) + MAXALIGN(((lquery_variant*)(x))->len) + LVAR_HDRSIZE ) )

Definition at line 59 of file ltree.h.

Referenced by checkLevel(), gist_qe(), lquery_in(), and lquery_out().

◆ LVAR_SUBLEXEME

#define LVAR_SUBLEXEME   0x04 /* '%' flag: word-wise match */

Definition at line 63 of file ltree.h.

Referenced by checkcondition_str(), checkLevel(), gettoken_query(), infix(), lquery_in(), and lquery_out().

◆ OPEN

#define OPEN   4

Definition at line 159 of file ltree.h.

◆ OPR

#define OPR   3

Definition at line 158 of file ltree.h.

◆ PG_GETARG_LQUERY_P

#define PG_GETARG_LQUERY_P (   n)    DatumGetLqueryP(PG_GETARG_DATUM(n))

Definition at line 209 of file ltree.h.

Referenced by _ltq_extract_regex(), _ltq_regex(), lquery_out(), ltq_regex(), and ltree_consistent().

◆ PG_GETARG_LQUERY_P_COPY

#define PG_GETARG_LQUERY_P_COPY (   n)    DatumGetLqueryPCopy(PG_GETARG_DATUM(n))

Definition at line 210 of file ltree.h.

◆ PG_GETARG_LTREE_P

◆ PG_GETARG_LTREE_P_COPY

#define PG_GETARG_LTREE_P_COPY (   n)    DatumGetLtreePCopy(PG_GETARG_DATUM(n))

Definition at line 205 of file ltree.h.

Referenced by ltree_consistent().

◆ PG_GETARG_LTXTQUERY_P

#define PG_GETARG_LTXTQUERY_P (   n)    DatumGetLtxtqueryP(PG_GETARG_DATUM(n))

Definition at line 214 of file ltree.h.

Referenced by _ltxtq_exec(), _ltxtq_extract_exec(), ltree_consistent(), ltxtq_exec(), and ltxtq_out().

◆ PG_GETARG_LTXTQUERY_P_COPY

#define PG_GETARG_LTXTQUERY_P_COPY (   n)    DatumGetLtxtqueryPCopy(PG_GETARG_DATUM(n))

Definition at line 215 of file ltree.h.

◆ SETBIT

#define SETBIT (   x,
  i 
)    GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )

Definition at line 233 of file ltree.h.

◆ SIGLEN

#define SIGLEN   (sizeof(int32) * SIGLENINT)

Definition at line 222 of file ltree.h.

◆ SIGLEN_DEFAULT

#define SIGLEN_DEFAULT   (2 * sizeof(int32))

Definition at line 220 of file ltree.h.

◆ SIGLEN_MAX

#define SIGLEN_MAX   GISTMaxIndexKeySize

Definition at line 219 of file ltree.h.

◆ SIGLENBIT

#define SIGLENBIT (   siglen)    ((siglen) * BITBYTE)

Definition at line 223 of file ltree.h.

◆ VAL

#define VAL   2

Definition at line 157 of file ltree.h.

◆ VALFALSE

#define VALFALSE   7

Definition at line 162 of file ltree.h.

◆ VALTRUE

#define VALTRUE   6 /* for stop words */

Definition at line 161 of file ltree.h.

Referenced by findoprnd().

Typedef Documentation

◆ BITVECP

typedef unsigned char* BITVECP

Definition at line 225 of file ltree.h.

◆ ITEM

typedef struct ITEM ITEM

Function Documentation

◆ _lt_q_regex()

Datum _lt_q_regex ( PG_FUNCTION_ARGS  )

Definition at line 134 of file _ltree_op.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), array_iterator(), ArrayGetNItems(), ereport, errcode(), errmsg(), ERROR, ltq_regex(), NEXTVAL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, and PG_RETURN_BOOL.

Referenced by _lt_q_rregex().

135 {
136  ArrayType *_tree = PG_GETARG_ARRAYTYPE_P(0);
137  ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
138  lquery *query = (lquery *) ARR_DATA_PTR(_query);
139  bool res = false;
140  int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
141 
142  if (ARR_NDIM(_query) > 1)
143  ereport(ERROR,
144  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
145  errmsg("array must be one-dimensional")));
146  if (array_contains_nulls(_query))
147  ereport(ERROR,
148  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
149  errmsg("array must not contain nulls")));
150 
151  while (num > 0)
152  {
153  if (array_iterator(_tree, ltq_regex, (void *) query, NULL))
154  {
155  res = true;
156  break;
157  }
158  num--;
159  query = (lquery *) NEXTVAL(query);
160  }
161 
162  PG_FREE_IF_COPY(_tree, 0);
163  PG_FREE_IF_COPY(_query, 1);
164  PG_RETURN_BOOL(res);
165 }
Definition: ltree.h:100
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
int errcode(int sqlerrcode)
Definition: elog.c:610
#define NEXTVAL(x)
Definition: _ltree_op.c:34
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:282
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:215
#define ARR_DATA_PTR(a)
Definition: array.h:310
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define ereport(elevel,...)
Definition: elog.h:144
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#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:3528

◆ _lt_q_rregex()

Datum _lt_q_rregex ( PG_FUNCTION_ARGS  )

Definition at line 168 of file _ltree_op.c.

References _lt_q_regex(), DirectFunctionCall2, PG_GETARG_DATUM, and PG_RETURN_DATUM.

169 {
171  PG_GETARG_DATUM(1),
172  PG_GETARG_DATUM(0)
173  ));
174 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum _lt_q_regex(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:134
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:347
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621

◆ _ltq_regex()

Datum _ltq_regex ( PG_FUNCTION_ARGS  )

Definition at line 113 of file _ltree_op.c.

References array_iterator(), ltq_regex(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LQUERY_P, and PG_RETURN_BOOL.

Referenced by _ltq_rregex().

114 {
116  lquery *query = PG_GETARG_LQUERY_P(1);
117  bool res = array_iterator(la, ltq_regex, (void *) query, NULL);
118 
119  PG_FREE_IF_COPY(la, 0);
120  PG_FREE_IF_COPY(query, 1);
121  PG_RETURN_BOOL(res);
122 }
Definition: ltree.h:100
#define PG_GETARG_LQUERY_P(n)
Definition: ltree.h:209
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:215
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ _ltq_rregex()

Datum _ltq_rregex ( PG_FUNCTION_ARGS  )

Definition at line 125 of file _ltree_op.c.

References _ltq_regex(), DirectFunctionCall2, PG_GETARG_DATUM, and PG_RETURN_DATUM.

126 {
128  PG_GETARG_DATUM(1),
129  PG_GETARG_DATUM(0)
130  ));
131 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum _ltq_regex(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:113
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:347
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621

◆ _ltree_isparent()

Datum _ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 71 of file _ltree_op.c.

References array_iterator(), ltree_isparent(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE_P, and PG_RETURN_BOOL.

Referenced by _ltree_r_isparent().

72 {
74  ltree *query = PG_GETARG_LTREE_P(1);
75  bool res = array_iterator(la, ltree_isparent, (void *) query, NULL);
76 
77  PG_FREE_IF_COPY(la, 0);
78  PG_FREE_IF_COPY(query, 1);
79  PG_RETURN_BOOL(res);
80 }
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
Definition: ltree.h:29
Datum ltree_isparent(PG_FUNCTION_ARGS)
Definition: ltree_op.c:167
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ _ltree_risparent()

Datum _ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 92 of file _ltree_op.c.

References array_iterator(), ltree_risparent(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE_P, and PG_RETURN_BOOL.

Referenced by _ltree_r_risparent().

93 {
95  ltree *query = PG_GETARG_LTREE_P(1);
96  bool res = array_iterator(la, ltree_risparent, (void *) query, NULL);
97 
98  PG_FREE_IF_COPY(la, 0);
99  PG_FREE_IF_COPY(query, 1);
100  PG_RETURN_BOOL(res);
101 }
Datum ltree_risparent(PG_FUNCTION_ARGS)
Definition: ltree_op.c:179
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
Definition: ltree.h:29
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ _ltxtq_exec()

Datum _ltxtq_exec ( PG_FUNCTION_ARGS  )

Definition at line 178 of file _ltree_op.c.

References array_iterator(), ltxtq_exec(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTXTQUERY_P, and PG_RETURN_BOOL.

Referenced by _ltxtq_rexec().

179 {
181  ltxtquery *query = PG_GETARG_LTXTQUERY_P(1);
182  bool res = array_iterator(la, ltxtq_exec, (void *) query, NULL);
183 
184  PG_FREE_IF_COPY(la, 0);
185  PG_FREE_IF_COPY(query, 1);
186  PG_RETURN_BOOL(res);
187 }
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:84
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define PG_GETARG_LTXTQUERY_P(n)
Definition: ltree.h:214

◆ _ltxtq_rexec()

Datum _ltxtq_rexec ( PG_FUNCTION_ARGS  )

Definition at line 190 of file _ltree_op.c.

References _ltxtq_exec(), DirectFunctionCall2, PG_GETARG_DATUM, and PG_RETURN_DATUM.

191 {
193  PG_GETARG_DATUM(1),
194  PG_GETARG_DATUM(0)
195  ));
196 }
Datum _ltxtq_exec(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:178
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:347
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621

◆ compare_subnode()

bool compare_subnode ( ltree_level t,
char *  q,
int  len,
int(*)(const char *, const char *, size_t)  cmpptr,
bool  anyend 
)

Definition at line 44 of file lquery_op.c.

References getlexeme(), ltree_level::len, and ltree_level::name.

Referenced by checkcondition_str(), and checkLevel().

45 {
46  char *endt = t->name + t->len;
47  char *endq = qn + len;
48  char *tn;
49  int lent,
50  lenq;
51  bool isok;
52 
53  while ((qn = getlexeme(qn, endq, &lenq)) != NULL)
54  {
55  tn = t->name;
56  isok = false;
57  while ((tn = getlexeme(tn, endt, &lent)) != NULL)
58  {
59  if ((lent == lenq || (lent > lenq && anyend)) &&
60  (*cmpptr) (qn, tn, lenq) == 0)
61  {
62 
63  isok = true;
64  break;
65  }
66  tn += lent;
67  }
68 
69  if (!isok)
70  return false;
71  qn += lenq;
72  }
73 
74  return true;
75 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:23
uint16 len
Definition: ltree.h:22
static char * getlexeme(char *start, char *end, int *len)
Definition: lquery_op.c:24

◆ inner_isparent()

bool inner_isparent ( const ltree c,
const ltree p 
)

Definition at line 143 of file ltree_op.c.

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

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

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 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:23
uint16 len
Definition: ltree.h:22
#define LEVEL_NEXT(x)
Definition: ltree.h:27
uint16 numlevel
Definition: ltree.h:32
#define LTREE_FIRST(x)
Definition: ltree.h:38

◆ lca_inner()

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

Definition at line 426 of file ltree_op.c.

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

Referenced by _lca(), and lca().

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 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:23
uint16 len
Definition: ltree.h:22
#define Min(x, y)
Definition: c.h:920
#define LTREE_HDRSIZE
Definition: ltree.h:37
#define LEVEL_NEXT(x)
Definition: ltree.h:27
Definition: ltree.h:29
uint16 numlevel
Definition: ltree.h:32
void * palloc0(Size size)
Definition: mcxt.c:980
#define MAXALIGN(LEN)
Definition: c.h:691
#define LTREE_FIRST(x)
Definition: ltree.h:38
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define LEVEL_HDRSIZE
Definition: ltree.h:26

◆ lt_q_regex()

Datum lt_q_regex ( PG_FUNCTION_ARGS  )

Definition at line 239 of file lquery_op.c.

References ARR_DATA_PTR, ARR_DIMS, ARR_NDIM, array_contains_nulls(), ArrayGetNItems(), DatumGetBool, DirectFunctionCall2, ereport, errcode(), errmsg(), ERROR, ltq_regex(), NEXTVAL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE_P, PG_RETURN_BOOL, and PointerGetDatum.

Referenced by lt_q_rregex(), and ltree_consistent().

240 {
241  ltree *tree = PG_GETARG_LTREE_P(0);
242  ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
243  lquery *query = (lquery *) ARR_DATA_PTR(_query);
244  bool res = false;
245  int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
246 
247  if (ARR_NDIM(_query) > 1)
248  ereport(ERROR,
249  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
250  errmsg("array must be one-dimensional")));
251  if (array_contains_nulls(_query))
252  ereport(ERROR,
253  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
254  errmsg("array must not contain nulls")));
255 
256  while (num > 0)
257  {
259  PointerGetDatum(tree), PointerGetDatum(query))))
260  {
261 
262  res = true;
263  break;
264  }
265  num--;
266  query = NEXTVAL(query);
267  }
268 
269  PG_FREE_IF_COPY(tree, 0);
270  PG_FREE_IF_COPY(_query, 1);
271  PG_RETURN_BOOL(res);
272 }
#define PointerGetDatum(X)
Definition: postgres.h:556
Definition: ltree.h:100
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
#define NEXTVAL(x)
Definition: lquery_op.c:21
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:282
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:215
#define ARR_DATA_PTR(a)
Definition: array.h:310
#define DatumGetBool(X)
Definition: postgres.h:393
Definition: ltree.h:29
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define ereport(elevel,...)
Definition: elog.h:144
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#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:3528
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621

◆ lt_q_rregex()

Datum lt_q_rregex ( PG_FUNCTION_ARGS  )

Definition at line 275 of file lquery_op.c.

References DirectFunctionCall2, lt_q_regex(), PG_GETARG_DATUM, and PG_RETURN_DATUM.

276 {
278  PG_GETARG_DATUM(1),
279  PG_GETARG_DATUM(0)
280  ));
281 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum lt_q_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:239
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:347
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621

◆ ltq_regex()

Datum ltq_regex ( PG_FUNCTION_ARGS  )

Definition at line 215 of file lquery_op.c.

References checkCond(), LQUERY_FIRST, LTREE_FIRST, ltree::numlevel, lquery::numlevel, PG_FREE_IF_COPY, PG_GETARG_LQUERY_P, PG_GETARG_LTREE_P, and PG_RETURN_BOOL.

Referenced by _lt_q_regex(), _ltq_extract_regex(), _ltq_regex(), lt_q_regex(), ltq_rregex(), and ltree_consistent().

216 {
217  ltree *tree = PG_GETARG_LTREE_P(0);
218  lquery *query = PG_GETARG_LQUERY_P(1);
219  bool res;
220 
221  res = checkCond(LQUERY_FIRST(query), query->numlevel,
222  LTREE_FIRST(tree), tree->numlevel);
223 
224  PG_FREE_IF_COPY(tree, 0);
225  PG_FREE_IF_COPY(query, 1);
226  PG_RETURN_BOOL(res);
227 }
#define LQUERY_FIRST(x)
Definition: ltree.h:111
Definition: ltree.h:100
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
static bool checkCond(lquery_level *curq, int qlen, ltree_level *curt, int tlen)
Definition: lquery_op.c:136
#define PG_GETARG_LQUERY_P(n)
Definition: ltree.h:209
Definition: ltree.h:29
uint16 numlevel
Definition: ltree.h:32
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
uint16 numlevel
Definition: ltree.h:103
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define LTREE_FIRST(x)
Definition: ltree.h:38

◆ ltq_rregex()

Datum ltq_rregex ( PG_FUNCTION_ARGS  )

Definition at line 230 of file lquery_op.c.

References DirectFunctionCall2, ltq_regex(), PG_GETARG_DATUM, and PG_RETURN_DATUM.

231 {
233  PG_GETARG_DATUM(1),
234  PG_GETARG_DATUM(0)
235  ));
236 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:215
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:347
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621

◆ ltree_addltree()

Datum ltree_addltree ( PG_FUNCTION_ARGS  )

Definition at line 297 of file ltree_op.c.

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

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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:355
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:274
Definition: ltree.h:29
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ ltree_addtext()

Datum ltree_addtext ( PG_FUNCTION_ARGS  )

Definition at line 310 of file ltree_op.c.

References 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().

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_RETURN_POINTER(x)
Definition: fmgr.h:355
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
Datum ltree_in(PG_FUNCTION_ARGS)
Definition: ltree_io.c:32
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1056
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:274
Definition: ltree.h:29
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define DatumGetPointer(X)
Definition: postgres.h:549
char * text_to_cstring(const text *t)
Definition: varlena.c:204
Definition: c.h:555

◆ ltree_compare()

int ltree_compare ( const ltree a,
const ltree b 
)

Definition at line 42 of file ltree_op.c.

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

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

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 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:23
uint16 len
Definition: ltree.h:22
#define Min(x, y)
Definition: c.h:920
#define LEVEL_NEXT(x)
Definition: ltree.h:27
uint16 numlevel
Definition: ltree.h:32
#define LTREE_FIRST(x)
Definition: ltree.h:38

◆ ltree_execute()

bool ltree_execute ( ITEM curitem,
void *  checkval,
bool  calcnot,
bool(*)(void *checkval, ITEM *val chkcond 
)

Definition at line 20 of file ltxtquery_op.c.

References check_stack_depth(), ITEM::left, ITEM::type, ITEM::val, and VAL.

Referenced by gist_qtxt(), and ltxtq_exec().

21 {
22  /* since this function recurses, it could be driven to stack overflow */
24 
25  if (curitem->type == VAL)
26  return (*chkcond) (checkval, curitem);
27  else if (curitem->val == (int32) '!')
28  {
29  return calcnot ?
30  ((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
31  : true;
32  }
33  else if (curitem->val == (int32) '&')
34  {
35  if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
36  return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
37  else
38  return false;
39  }
40  else
41  { /* |-operator */
42  if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
43  return true;
44  else
45  return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
46  }
47 }
signed int int32
Definition: c.h:355
int16 type
Definition: _int.h:142
#define true
Definition: c.h:321
void check_stack_depth(void)
Definition: postgres.c:3295
int32 val
Definition: _int.h:144
int16 left
Definition: _int.h:143
#define VAL
Definition: _int.h:162
bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
Definition: ltxtquery_op.c:20

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

Datum ltree_in ( PG_FUNCTION_ARGS  )

Definition at line 32 of file ltree_io.c.

References buf, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, ISALNUM, ltree_level::len, nodeitem::len, LEVEL_HDRSIZE, LEVEL_NEXT, sort-test::list, LTPRS_WAITDELIM, LTPRS_WAITNAME, LTREE_FIRST, LTREE_HDRSIZE, LTREE_LABEL_MAX_CHARS, LTREE_MAX_LEVELS, MAXALIGN, ltree_level::name, ltree::numlevel, palloc(), palloc0(), pfree(), PG_GETARG_POINTER, pg_mblen(), PG_RETURN_POINTER, SET_VARSIZE, nodeitem::start, t_iseq, UNCHAR, and nodeitem::wlen.

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

33 {
34  char *buf = (char *) PG_GETARG_POINTER(0);
35  char *ptr;
36  nodeitem *list,
37  *lptr;
38  int num = 0,
39  totallen = 0;
40  int state = LTPRS_WAITNAME;
41  ltree *result;
42  ltree_level *curlevel;
43  int charlen;
44  int pos = 1; /* character position for error messages */
45 
46 #define UNCHAR ereport(ERROR, \
47  errcode(ERRCODE_SYNTAX_ERROR), \
48  errmsg("ltree syntax error at character %d", \
49  pos))
50 
51  ptr = buf;
52  while (*ptr)
53  {
54  charlen = pg_mblen(ptr);
55  if (charlen == 1 && t_iseq(ptr, '.'))
56  num++;
57  ptr += charlen;
58  }
59 
60  if (num + 1 > LTREE_MAX_LEVELS)
61  ereport(ERROR,
62  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
63  errmsg("number of ltree labels (%d) exceeds the maximum allowed (%d)",
64  num + 1, LTREE_MAX_LEVELS)));
65  list = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (num + 1));
66  ptr = buf;
67  while (*ptr)
68  {
69  charlen = pg_mblen(ptr);
70 
71  if (state == LTPRS_WAITNAME)
72  {
73  if (ISALNUM(ptr))
74  {
75  lptr->start = ptr;
76  lptr->wlen = 0;
77  state = LTPRS_WAITDELIM;
78  }
79  else
80  UNCHAR;
81  }
82  else if (state == LTPRS_WAITDELIM)
83  {
84  if (charlen == 1 && t_iseq(ptr, '.'))
85  {
86  lptr->len = ptr - lptr->start;
87  if (lptr->wlen > LTREE_LABEL_MAX_CHARS)
88  ereport(ERROR,
89  (errcode(ERRCODE_NAME_TOO_LONG),
90  errmsg("label string is too long"),
91  errdetail("Label length is %d, must be at most %d, at character %d.",
93  pos)));
94 
95  totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
96  lptr++;
97  state = LTPRS_WAITNAME;
98  }
99  else if (!ISALNUM(ptr))
100  UNCHAR;
101  }
102  else
103  /* internal error */
104  elog(ERROR, "internal error in parser");
105 
106  ptr += charlen;
107  lptr->wlen++;
108  pos++;
109  }
110 
111  if (state == LTPRS_WAITDELIM)
112  {
113  lptr->len = ptr - lptr->start;
114  if (lptr->wlen > LTREE_LABEL_MAX_CHARS)
115  ereport(ERROR,
116  (errcode(ERRCODE_NAME_TOO_LONG),
117  errmsg("label string is too long"),
118  errdetail("Label length is %d, must be at most %d, at character %d.",
119  lptr->wlen, LTREE_LABEL_MAX_CHARS, pos)));
120 
121  totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
122  lptr++;
123  }
124  else if (!(state == LTPRS_WAITNAME && lptr == list))
125  ereport(ERROR,
126  (errcode(ERRCODE_SYNTAX_ERROR),
127  errmsg("ltree syntax error"),
128  errdetail("Unexpected end of input.")));
129 
130  result = (ltree *) palloc0(LTREE_HDRSIZE + totallen);
131  SET_VARSIZE(result, LTREE_HDRSIZE + totallen);
132  result->numlevel = lptr - list;
133  curlevel = LTREE_FIRST(result);
134  lptr = list;
135  while (lptr - list < result->numlevel)
136  {
137  curlevel->len = (uint16) lptr->len;
138  memcpy(curlevel->name, lptr->start, lptr->len);
139  curlevel = LEVEL_NEXT(curlevel);
140  lptr++;
141  }
142 
143  pfree(list);
144  PG_RETURN_POINTER(result);
145 
146 #undef UNCHAR
147 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:355
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:23
char * start
Definition: ltree_io.c:22
#define ISALNUM(x)
Definition: ltree.h:116
uint16 len
Definition: ltree.h:22
int len
Definition: ltree_io.c:23
int wlen
Definition: ltree_io.c:25
#define LTREE_HDRSIZE
Definition: ltree.h:37
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
unsigned short uint16
Definition: c.h:366
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
#define LTPRS_WAITNAME
Definition: ltree_io.c:28
#define LTREE_LABEL_MAX_CHARS
Definition: ltree.h:18
static char * buf
Definition: pg_test_fsync.c:67
#define t_iseq(x, c)
Definition: ts_locale.h:43
#define UNCHAR
int errdetail(const char *fmt,...)
Definition: elog.c:957
#define LEVEL_NEXT(x)
Definition: ltree.h:27
Definition: ltree.h:29
uint16 numlevel
Definition: ltree.h:32
void * palloc0(Size size)
Definition: mcxt.c:980
#define ereport(elevel,...)
Definition: elog.h:144
Definition: regguts.h:298
#define LTPRS_WAITDELIM
Definition: ltree_io.c:29
#define MAXALIGN(LEN)
Definition: c.h:691
int pg_mblen(const char *mbstr)
Definition: mbutils.c:907
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define LTREE_FIRST(x)
Definition: ltree.h:38
#define elog(elevel,...)
Definition: elog.h:214
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define LTREE_MAX_LEVELS
Definition: ltree.h:39
#define LEVEL_HDRSIZE
Definition: ltree.h:26

◆ ltree_isparent()

Datum ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 167 of file ltree_op.c.

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

Referenced by _ltree_extract_isparent(), and _ltree_isparent().

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);
175  PG_RETURN_BOOL(res);
176 }
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:143
char * c
Definition: ltree.h:29
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ ltree_risparent()

Datum ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 179 of file ltree_op.c.

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

Referenced by _ltree_extract_risparent(), and _ltree_risparent().

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);
187  PG_RETURN_BOOL(res);
188 }
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:143
char * c
Definition: ltree.h:29
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ ltree_strncasecmp()

int ltree_strncasecmp ( const char *  a,
const char *  b,
size_t  s 
)

Definition at line 78 of file lquery_op.c.

References pfree(), and str_tolower().

Referenced by checkcondition_str(), and checkLevel().

79 {
80  char *al = str_tolower(a, s, DEFAULT_COLLATION_OID);
81  char *bl = str_tolower(b, s, DEFAULT_COLLATION_OID);
82  int res;
83 
84  res = strncmp(al, bl, s);
85 
86  pfree(al);
87  pfree(bl);
88 
89  return res;
90 }
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1637
void pfree(void *pointer)
Definition: mcxt.c:1056

◆ ltree_textadd()

Datum ltree_textadd ( PG_FUNCTION_ARGS  )

Definition at line 395 of file ltree_op.c.

References 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().

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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:355
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
Datum ltree_in(PG_FUNCTION_ARGS)
Definition: ltree_io.c:32
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1056
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:274
Definition: ltree.h:29
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define DatumGetPointer(X)
Definition: postgres.h:549
char * text_to_cstring(const text *t)
Definition: varlena.c:204
Definition: c.h:555

◆ ltxtq_exec()

Datum ltxtq_exec ( PG_FUNCTION_ARGS  )

Definition at line 84 of file ltxtquery_op.c.

References checkcondition_str(), GETOPERAND, GETQUERY, ltree_execute(), CHKVAL::node, CHKVAL::operand, PG_FREE_IF_COPY, PG_GETARG_LTREE_P, PG_GETARG_LTXTQUERY_P, PG_RETURN_BOOL, and val.

Referenced by _ltxtq_exec(), _ltxtq_extract_exec(), ltree_consistent(), and ltxtq_rexec().

85 {
87  ltxtquery *query = PG_GETARG_LTXTQUERY_P(1);
88  CHKVAL chkval;
89  bool result;
90 
91  chkval.node = val;
92  chkval.operand = GETOPERAND(query);
93 
94  result = ltree_execute(GETQUERY(query),
95  &chkval,
96  true,
98 
99  PG_FREE_IF_COPY(val, 0);
100  PG_FREE_IF_COPY(query, 1);
101  PG_RETURN_BOOL(result);
102 }
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:204
#define GETQUERY(x)
Definition: _int.h:157
#define GETOPERAND(x)
Definition: ltree.h:151
static bool checkcondition_str(void *checkval, ITEM *val)
Definition: ltxtquery_op.c:56
char * operand
Definition: ltxtquery_op.c:52
Definition: ltree.h:29
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:353
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define PG_GETARG_LTXTQUERY_P(n)
Definition: ltree.h:214
ltree * node
Definition: ltxtquery_op.c:51
long val
Definition: informix.c:664
bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
Definition: ltxtquery_op.c:20

◆ ltxtq_rexec()

Datum ltxtq_rexec ( PG_FUNCTION_ARGS  )

Definition at line 105 of file ltxtquery_op.c.

References DirectFunctionCall2, ltxtq_exec(), PG_GETARG_DATUM, and PG_RETURN_DATUM.

106 {
108  PG_GETARG_DATUM(1),
109  PG_GETARG_DATUM(0)
110  ));
111 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:84
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:347
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621