PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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
 

Macros

#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 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
 
#define LVAR_INCASE   0x02
 
#define LVAR_SUBLEXEME   0x04
 
#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
 
#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_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 PG_GETARG_LTREE(x)   ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
 
#define PG_GETARG_LTREE_COPY(x)   ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
 
#define PG_GETARG_LQUERY(x)   ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
 
#define PG_GETARG_LQUERY_COPY(x)   ((lquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
 
#define PG_GETARG_LTXTQUERY(x)   ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
 
#define PG_GETARG_LTXTQUERY_COPY(x)   ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
 
#define BITBYTE   8
 
#define SIGLENINT   2
 
#define SIGLEN   ( sizeof(int32)*SIGLENINT )
 
#define SIGLENBIT   (SIGLEN*BITBYTE)
 
#define LOOPBYTE   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)   (((unsigned int)(val)) % SIGLENBIT)
 
#define HASH(sign, val)   SETBIT((sign), HASHVAL(val))
 
#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)   ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : SIGLEN ) ) )
 
#define LTG_RENODE(x)   ( (ltree*)( ((char*)LTG_LNODE(x)) + VARSIZE(LTG_LNODE(x))) )
 
#define LTG_RNODE(x)   ( LTG_ISNORIGHT(x) ? LTG_LNODE(x) : LTG_RENODE(x) )
 
#define LTG_GETLNODE(x)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x) )
 
#define LTG_GETRNODE(x)   ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x) )
 
#define ASIGLENINT   (7)
 
#define ASIGLEN   (sizeof(int32)*ASIGLENINT)
 
#define ASIGLENBIT   (ASIGLEN*BITBYTE)
 
#define ALOOPBYTE   for(i=0;i<ASIGLEN;i++)
 
#define AHASHVAL(val)   (((unsigned int)(val)) % ASIGLENBIT)
 
#define AHASH(sign, val)   SETBIT((sign), AHASHVAL(val))
 

Typedefs

typedef struct ITEM ITEM
 
typedef unsigned char BITVEC [SIGLEN]
 
typedef unsigned char * BITVECP
 
typedef unsigned char ABITVEC [ASIGLEN]
 

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)
 

Macro Definition Documentation

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

Definition at line 243 of file ltree.h.

Referenced by hashing().

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

Definition at line 242 of file ltree.h.

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

#define ALOOPBYTE   for(i=0;i<ASIGLEN;i++)
#define ASIGLEN   (sizeof(int32)*ASIGLENINT)

Definition at line 235 of file ltree.h.

Referenced by _ltree_compress(), _ltree_picksplit(), and _ltree_union().

#define ASIGLENBIT   (ASIGLEN*BITBYTE)

Definition at line 236 of file ltree.h.

Referenced by hemdist().

#define ASIGLENINT   (7)

Definition at line 234 of file ltree.h.

#define BITBYTE   8

Definition at line 177 of file ltree.h.

#define CLOSE   5

Definition at line 127 of file ltree.h.

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

Definition at line 189 of file ltree.h.

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

Definition at line 114 of file ltree.h.

#define END   0

Definition at line 122 of file ltree.h.

#define ERR   1

Definition at line 123 of file ltree.h.

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

Definition at line 65 of file ltree.h.

Referenced by checkcondition_bit().

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

Definition at line 191 of file ltree.h.

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

Definition at line 188 of file ltree.h.

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

Definition at line 187 of file ltree.h.

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

Definition at line 117 of file ltree.h.

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

Definition at line 194 of file ltree.h.

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

Definition at line 193 of file ltree.h.

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

Definition at line 113 of file ltree.h.

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

Definition at line 83 of file ltree.h.

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

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

Definition at line 120 of file ltree.h.

#define LEVEL_HDRSIZE   (offsetof(ltree_level,name))

Definition at line 16 of file ltree.h.

Referenced by lca_inner(), and ltree_in().

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

Definition at line 184 of file ltree.h.

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

Definition at line 67 of file ltree.h.

Referenced by gist_qe().

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

Definition at line 59 of file ltree.h.

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

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

Definition at line 57 of file ltree.h.

Referenced by lquery_in().

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

Definition at line 58 of file ltree.h.

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

#define LQL_NOT   0x10

Definition at line 61 of file ltree.h.

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

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

Definition at line 79 of file ltree.h.

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

#define LQUERY_HASNOT   0x01

Definition at line 81 of file ltree.h.

Referenced by lquery_in(), and ltq_regex().

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

Definition at line 78 of file ltree.h.

Referenced by lquery_in().

#define LTG_ALLTRUE   0x02
#define LTG_GETLNODE (   x)    ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x) )
#define LTG_GETRNODE (   x)    ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x) )
#define LTG_HDRSIZE   MAXALIGN(VARHDRSZ + sizeof(uint32))
#define LTG_ISALLTRUE (   x)    ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE )
#define LTG_ISNORIGHT (   x)    ( ((ltree_gist*)(x))->flag & LTG_NORIGHT )

Definition at line 223 of file ltree.h.

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

Definition at line 221 of file ltree.h.

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

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

Definition at line 224 of file ltree.h.

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

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

Definition at line 220 of file ltree.h.

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

#define LTG_NORIGHT   0x04

Definition at line 216 of file ltree.h.

Referenced by ltree_picksplit(), and ltree_union().

#define LTG_ONENODE   0x01

Definition at line 214 of file ltree.h.

Referenced by ltree_compress().

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

Definition at line 225 of file ltree.h.

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

Definition at line 226 of file ltree.h.

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

#define LTG_SIGN (   x)    ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) )
#define LTREE_HDRSIZE   MAXALIGN( offsetof(ltree, data) )

Definition at line 26 of file ltree.h.

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

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

Definition at line 115 of file ltree.h.

Referenced by queryin().

#define LVAR_ANYEND   0x01

Definition at line 43 of file ltree.h.

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

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

Definition at line 40 of file ltree.h.

Referenced by lquery_in().

#define LVAR_INCASE   0x02

Definition at line 44 of file ltree.h.

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

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

Definition at line 41 of file ltree.h.

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

#define LVAR_SUBLEXEME   0x04

Definition at line 45 of file ltree.h.

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

#define OPEN   4

Definition at line 126 of file ltree.h.

#define OPR   3

Definition at line 125 of file ltree.h.

#define PG_GETARG_LQUERY (   x)    ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))

Definition at line 170 of file ltree.h.

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

#define PG_GETARG_LQUERY_COPY (   x)    ((lquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))

Definition at line 171 of file ltree.h.

#define PG_GETARG_LTREE_COPY (   x)    ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))

Definition at line 169 of file ltree.h.

Referenced by ltree_consistent().

#define PG_GETARG_LTXTQUERY (   x)    ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))

Definition at line 172 of file ltree.h.

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

#define PG_GETARG_LTXTQUERY_COPY (   x)    ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))

Definition at line 173 of file ltree.h.

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

Definition at line 190 of file ltree.h.

#define SIGLEN   ( sizeof(int32)*SIGLENINT )

Definition at line 179 of file ltree.h.

#define SIGLENBIT   (SIGLEN*BITBYTE)

Definition at line 180 of file ltree.h.

#define SIGLENINT   2

Definition at line 178 of file ltree.h.

#define VAL   2

Definition at line 124 of file ltree.h.

#define VALFALSE   7

Definition at line 129 of file ltree.h.

#define VALTRUE   6 /* for stop words */

Definition at line 128 of file ltree.h.

Referenced by findoprnd().

Typedef Documentation

typedef unsigned char ABITVEC[ASIGLEN]

Definition at line 237 of file ltree.h.

typedef unsigned char BITVEC[SIGLEN]

Definition at line 181 of file ltree.h.

typedef unsigned char* BITVECP

Definition at line 182 of file ltree.h.

typedef struct ITEM ITEM

Function Documentation

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, NULL, 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:69
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
int errcode(int sqlerrcode)
Definition: elog.c:575
#define NEXTVAL(x)
Definition: _ltree_op.c:34
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:275
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:303
#define ARR_DATA_PTR(a)
Definition: array.h:303
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define NULL
Definition: c.h:229
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define ARR_NDIM(a)
Definition: array.h:271
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3542
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:233
Datum _lt_q_regex(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:134
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum _ltq_regex ( PG_FUNCTION_ARGS  )

Definition at line 113 of file _ltree_op.c.

References array_iterator(), ltq_regex(), NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LQUERY, and PG_RETURN_BOOL.

Referenced by _ltq_rregex().

114 {
116  lquery *query = PG_GETARG_LQUERY(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:69
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:303
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
#define PG_GETARG_LQUERY(x)
Definition: ltree.h:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define NULL
Definition: c.h:229
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
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:233
Datum _ltq_regex(PG_FUNCTION_ARGS)
Definition: _ltree_op.c:113
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum _ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 71 of file _ltree_op.c.

References array_iterator(), ltree_isparent(), NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE, and PG_RETURN_BOOL.

Referenced by _ltree_r_isparent().

72 {
74  ltree *query = PG_GETARG_LTREE(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(x)
Definition: ltree.h:168
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
Definition: ltree.h:19
Datum ltree_isparent(PG_FUNCTION_ARGS)
Definition: ltree_op.c:160
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define NULL
Definition: c.h:229
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
Datum _ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 92 of file _ltree_op.c.

References array_iterator(), ltree_risparent(), NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTREE, and PG_RETURN_BOOL.

Referenced by _ltree_r_risparent().

93 {
95  ltree *query = PG_GETARG_LTREE(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:172
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
Definition: _ltree_op.c:37
Definition: ltree.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define NULL
Definition: c.h:229
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
Datum _ltxtq_exec ( PG_FUNCTION_ARGS  )

Definition at line 178 of file _ltree_op.c.

References array_iterator(), ltxtq_exec(), NULL, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_LTXTQUERY, and PG_RETURN_BOOL.

Referenced by _ltxtq_rexec().

179 {
181  ltxtquery *query = PG_GETARG_LTXTQUERY(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_LTXTQUERY(x)
Definition: ltree.h:172
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
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:319
#define NULL
Definition: c.h:229
Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:87
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
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:233
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
bool compare_subnode ( ltree_level t,
char *  q,
int  len,
int(*)(const char *, const char *, size_t)  cmpptr,
bool  anyend 
)

Definition at line 53 of file lquery_op.c.

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

Referenced by checkcondition_str(), and checkLevel().

54 {
55  char *endt = t->name + t->len;
56  char *endq = qn + len;
57  char *tn;
58  int lent,
59  lenq;
60  bool isok;
61 
62  while ((qn = getlexeme(qn, endq, &lenq)) != NULL)
63  {
64  tn = t->name;
65  isok = false;
66  while ((tn = getlexeme(tn, endt, &lent)) != NULL)
67  {
68  if (
69  (
70  lent == lenq ||
71  (lent > lenq && anyend)
72  ) &&
73  (*cmpptr) (qn, tn, lenq) == 0)
74  {
75 
76  isok = true;
77  break;
78  }
79  tn += lent;
80  }
81 
82  if (!isok)
83  return false;
84  qn += lenq;
85  }
86 
87  return true;
88 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:13
uint16 len
Definition: ltree.h:12
static char * getlexeme(char *start, char *end, int *len)
Definition: lquery_op.c:33
#define NULL
Definition: c.h:229
bool inner_isparent ( const ltree c,
const ltree p 
)

Definition at line 136 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().

137 {
138  ltree_level *cl = LTREE_FIRST(c);
139  ltree_level *pl = LTREE_FIRST(p);
140  int pn = p->numlevel;
141 
142  if (pn > c->numlevel)
143  return false;
144 
145  while (pn > 0)
146  {
147  if (cl->len != pl->len)
148  return false;
149  if (memcmp(cl->name, pl->name, cl->len))
150  return false;
151 
152  pn--;
153  cl = LEVEL_NEXT(cl);
154  pl = LEVEL_NEXT(pl);
155  }
156  return true;
157 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:13
uint16 len
Definition: ltree.h:12
#define LEVEL_NEXT(x)
Definition: ltree.h:17
uint16 numlevel
Definition: ltree.h:22
#define LTREE_FIRST(x)
Definition: ltree.h:27
ltree* lca_inner ( ltree **  a,
int  len 
)

Definition at line 406 of file ltree_op.c.

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

Referenced by _lca(), and lca().

407 {
408  int tmp,
409  num = ((*a)->numlevel) ? (*a)->numlevel - 1 : 0;
410  ltree **ptr = a + 1;
411  int i,
412  reslen = LTREE_HDRSIZE;
413  ltree_level *l1,
414  *l2;
415  ltree *res;
416 
417 
418  if ((*a)->numlevel == 0)
419  return NULL;
420 
421  while (ptr - a < len)
422  {
423  if ((*ptr)->numlevel == 0)
424  return NULL;
425  else if ((*ptr)->numlevel == 1)
426  num = 0;
427  else
428  {
429  l1 = LTREE_FIRST(*a);
430  l2 = LTREE_FIRST(*ptr);
431  tmp = num;
432  num = 0;
433  for (i = 0; i < Min(tmp, (*ptr)->numlevel - 1); i++)
434  {
435  if (l1->len == l2->len && memcmp(l1->name, l2->name, l1->len) == 0)
436  num = i + 1;
437  else
438  break;
439  l1 = LEVEL_NEXT(l1);
440  l2 = LEVEL_NEXT(l2);
441  }
442  }
443  ptr++;
444  }
445 
446  l1 = LTREE_FIRST(*a);
447  for (i = 0; i < num; i++)
448  {
449  reslen += MAXALIGN(l1->len + LEVEL_HDRSIZE);
450  l1 = LEVEL_NEXT(l1);
451  }
452 
453  res = (ltree *) palloc0(reslen);
454  SET_VARSIZE(res, reslen);
455  res->numlevel = num;
456 
457  l1 = LTREE_FIRST(*a);
458  l2 = LTREE_FIRST(res);
459 
460  for (i = 0; i < num; i++)
461  {
462  memcpy(l2, l1, MAXALIGN(l1->len + LEVEL_HDRSIZE));
463  l1 = LEVEL_NEXT(l1);
464  l2 = LEVEL_NEXT(l2);
465  }
466 
467  return res;
468 }
#define Min(x, y)
Definition: c.h:806
#define LTREE_HDRSIZE
Definition: ltree.h:26
#define LEVEL_NEXT(x)
Definition: ltree.h:17
Definition: ltree.h:19
void * palloc0(Size size)
Definition: mcxt.c:878
#define NULL
Definition: c.h:229
#define MAXALIGN(LEN)
Definition: c.h:588
#define LTREE_FIRST(x)
Definition: ltree.h:27
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define LEVEL_HDRSIZE
Definition: ltree.h:16
Datum lt_q_regex ( PG_FUNCTION_ARGS  )

Definition at line 339 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, PG_RETURN_BOOL, and PointerGetDatum.

Referenced by lt_q_rregex(), and ltree_consistent().

340 {
341  ltree *tree = PG_GETARG_LTREE(0);
342  ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
343  lquery *query = (lquery *) ARR_DATA_PTR(_query);
344  bool res = false;
345  int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
346 
347  if (ARR_NDIM(_query) > 1)
348  ereport(ERROR,
349  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
350  errmsg("array must be one-dimensional")));
351  if (array_contains_nulls(_query))
352  ereport(ERROR,
353  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
354  errmsg("array must not contain nulls")));
355 
356  while (num > 0)
357  {
359  PointerGetDatum(tree), PointerGetDatum(query))))
360  {
361 
362  res = true;
363  break;
364  }
365  num--;
366  query = NEXTVAL(query);
367  }
368 
369  PG_FREE_IF_COPY(tree, 0);
370  PG_FREE_IF_COPY(_query, 1);
371  PG_RETURN_BOOL(res);
372 }
#define PointerGetDatum(X)
Definition: postgres.h:562
Definition: ltree.h:69
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
int errcode(int sqlerrcode)
Definition: elog.c:575
#define NEXTVAL(x)
Definition: lquery_op.c:20
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:275
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:303
#define ARR_DATA_PTR(a)
Definition: array.h:303
#define DatumGetBool(X)
Definition: postgres.h:399
#define ereport(elevel, rest)
Definition: elog.h:122
Definition: ltree.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define ARR_NDIM(a)
Definition: array.h:271
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3542
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum lt_q_rregex ( PG_FUNCTION_ARGS  )

Definition at line 375 of file lquery_op.c.

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

376 {
378  PG_GETARG_DATUM(1),
379  PG_GETARG_DATUM(0)
380  ));
381 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
Datum lt_q_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:339
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum ltq_regex ( PG_FUNCTION_ARGS  )

Definition at line 303 of file lquery_op.c.

References checkCond(), lquery::flag, fn(), LQUERY_FIRST, LQUERY_HASNOT, LTREE_FIRST, NULL, ltree::numlevel, lquery::numlevel, PG_FREE_IF_COPY, PG_GETARG_LQUERY, PG_GETARG_LTREE, PG_RETURN_BOOL, and FieldNot::q.

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

304 {
305  ltree *tree = PG_GETARG_LTREE(0);
306  lquery *query = PG_GETARG_LQUERY(1);
307  bool res = false;
308 
309  if (query->flag & LQUERY_HASNOT)
310  {
311  FieldNot fn;
312 
313  fn.q = NULL;
314 
315  res = checkCond(LQUERY_FIRST(query), query->numlevel,
316  LTREE_FIRST(tree), tree->numlevel, &fn);
317  }
318  else
319  {
320  res = checkCond(LQUERY_FIRST(query), query->numlevel,
321  LTREE_FIRST(tree), tree->numlevel, NULL);
322  }
323 
324  PG_FREE_IF_COPY(tree, 0);
325  PG_FREE_IF_COPY(query, 1);
326  PG_RETURN_BOOL(res);
327 }
#define LQUERY_FIRST(x)
Definition: ltree.h:79
Definition: ltree.h:69
lquery_level * q
Definition: lquery_op.c:24
uint16 flag
Definition: ltree.h:74
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
#define PG_GETARG_LQUERY(x)
Definition: ltree.h:170
Definition: ltree.h:19
uint16 numlevel
Definition: ltree.h:22
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static void * fn(void *arg)
#define NULL
Definition: c.h:229
uint16 numlevel
Definition: ltree.h:72
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
static bool checkCond(lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_numlevel, FieldNot *ptr)
Definition: lquery_op.c:157
#define LTREE_FIRST(x)
Definition: ltree.h:27
#define LQUERY_HASNOT
Definition: ltree.h:81
Datum ltq_rregex ( PG_FUNCTION_ARGS  )

Definition at line 330 of file lquery_op.c.

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

331 {
333  PG_GETARG_DATUM(1),
334  PG_GETARG_DATUM(0)
335  ));
336 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
Datum ltq_regex(PG_FUNCTION_ARGS)
Definition: lquery_op.c:303
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum ltree_addltree ( PG_FUNCTION_ARGS  )

Definition at line 283 of file ltree_op.c.

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

284 {
285  ltree *a = PG_GETARG_LTREE(0);
286  ltree *b = PG_GETARG_LTREE(1);
287  ltree *r;
288 
289  r = ltree_concat(a, b);
290  PG_FREE_IF_COPY(a, 0);
291  PG_FREE_IF_COPY(b, 1);
293 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:267
Definition: ltree.h:19
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
Datum ltree_addtext ( PG_FUNCTION_ARGS  )

Definition at line 296 of file ltree_op.c.

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

297 {
298  ltree *a = PG_GETARG_LTREE(0);
299  text *b = PG_GETARG_TEXT_PP(1);
300  char *s;
301  ltree *r,
302  *tmp;
303 
304  s = text_to_cstring(b);
305 
307  PointerGetDatum(s)));
308 
309  pfree(s);
310 
311  r = ltree_concat(a, tmp);
312 
313  pfree(tmp);
314 
315  PG_FREE_IF_COPY(a, 0);
316  PG_FREE_IF_COPY(b, 1);
318 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
Datum ltree_in(PG_FUNCTION_ARGS)
Definition: ltree_io.c:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
void pfree(void *pointer)
Definition: mcxt.c:950
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:267
Definition: ltree.h:19
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define DatumGetPointer(X)
Definition: postgres.h:555
char * text_to_cstring(const text *t)
Definition: varlena.c:182
Definition: c.h:439
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  int res = 0;
49 
50  while (an > 0 && bn > 0)
51  {
52  if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
53  {
54  if (al->len != bl->len)
55  return (al->len - bl->len) * 10 * (an + 1);
56  }
57  else
58  return res * 10 * (an + 1);
59 
60  an--;
61  bn--;
62  al = LEVEL_NEXT(al);
63  bl = LEVEL_NEXT(bl);
64  }
65 
66  return (a->numlevel - b->numlevel) * 10 * (an + 1);
67 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:13
uint16 len
Definition: ltree.h:12
#define Min(x, y)
Definition: c.h:806
#define LEVEL_NEXT(x)
Definition: ltree.h:17
uint16 numlevel
Definition: ltree.h:22
#define LTREE_FIRST(x)
Definition: ltree.h:27
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:256
int16 type
Definition: _int.h:127
void check_stack_depth(void)
Definition: postgres.c:3098
int32 val
Definition: _int.h:129
int16 left
Definition: _int.h:128
#define VAL
Definition: _int.h:147
bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
Definition: ltxtquery_op.c:20
Datum ltree_in ( PG_FUNCTION_ARGS  )

Definition at line 38 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, MAXALIGN, MaxAllocSize, ltree_level::name, ltree::numlevel, palloc(), palloc0(), pfree(), PG_GETARG_POINTER, pg_mblen(), PG_RETURN_POINTER, result, SET_VARSIZE, nodeitem::start, t_iseq, UNCHAR, and nodeitem::wlen.

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

39 {
40  char *buf = (char *) PG_GETARG_POINTER(0);
41  char *ptr;
42  nodeitem *list,
43  *lptr;
44  int num = 0,
45  totallen = 0;
46  int state = LTPRS_WAITNAME;
47  ltree *result;
48  ltree_level *curlevel;
49  int charlen;
50  int pos = 0;
51 
52  ptr = buf;
53  while (*ptr)
54  {
55  charlen = pg_mblen(ptr);
56  if (charlen == 1 && t_iseq(ptr, '.'))
57  num++;
58  ptr += charlen;
59  }
60 
61  if (num + 1 > MaxAllocSize / sizeof(nodeitem))
62  ereport(ERROR,
63  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
64  errmsg("number of levels (%d) exceeds the maximum allowed (%d)",
65  num + 1, (int) (MaxAllocSize / sizeof(nodeitem)))));
66  list = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (num + 1));
67  ptr = buf;
68  while (*ptr)
69  {
70  charlen = pg_mblen(ptr);
71 
72  if (state == LTPRS_WAITNAME)
73  {
74  if (ISALNUM(ptr))
75  {
76  lptr->start = ptr;
77  lptr->wlen = 0;
78  state = LTPRS_WAITDELIM;
79  }
80  else
81  UNCHAR;
82  }
83  else if (state == LTPRS_WAITDELIM)
84  {
85  if (charlen == 1 && t_iseq(ptr, '.'))
86  {
87  lptr->len = ptr - lptr->start;
88  if (lptr->wlen > 255)
89  ereport(ERROR,
90  (errcode(ERRCODE_NAME_TOO_LONG),
91  errmsg("name of level is too long"),
92  errdetail("Name length is %d, must "
93  "be < 256, in position %d.",
94  lptr->wlen, pos)));
95 
96  totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
97  lptr++;
98  state = LTPRS_WAITNAME;
99  }
100  else if (!ISALNUM(ptr))
101  UNCHAR;
102  }
103  else
104  /* internal error */
105  elog(ERROR, "internal error in parser");
106 
107  ptr += charlen;
108  lptr->wlen++;
109  pos++;
110  }
111 
112  if (state == LTPRS_WAITDELIM)
113  {
114  lptr->len = ptr - lptr->start;
115  if (lptr->wlen > 255)
116  ereport(ERROR,
117  (errcode(ERRCODE_NAME_TOO_LONG),
118  errmsg("name of level is too long"),
119  errdetail("Name length is %d, must "
120  "be < 256, in position %d.",
121  lptr->wlen, pos)));
122 
123  totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
124  lptr++;
125  }
126  else if (!(state == LTPRS_WAITNAME && lptr == list))
127  ereport(ERROR,
128  (errcode(ERRCODE_SYNTAX_ERROR),
129  errmsg("syntax error"),
130  errdetail("Unexpected end of line.")));
131 
132  result = (ltree *) palloc0(LTREE_HDRSIZE + totallen);
133  SET_VARSIZE(result, LTREE_HDRSIZE + totallen);
134  result->numlevel = lptr - list;
135  curlevel = LTREE_FIRST(result);
136  lptr = list;
137  while (lptr - list < result->numlevel)
138  {
139  curlevel->len = (uint16) lptr->len;
140  memcpy(curlevel->name, lptr->start, lptr->len);
141  curlevel = LEVEL_NEXT(curlevel);
142  lptr++;
143  }
144 
145  pfree(list);
146  PG_RETURN_POINTER(result);
147 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:13
char * start
Definition: ltree_io.c:28
#define ISALNUM(x)
Definition: ltree.h:83
uint16 len
Definition: ltree.h:12
int len
Definition: ltree_io.c:29
int wlen
Definition: ltree_io.c:31
#define LTREE_HDRSIZE
Definition: ltree.h:26
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
unsigned short uint16
Definition: c.h:267
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
#define LTPRS_WAITNAME
Definition: ltree_io.c:34
static char * buf
Definition: pg_test_fsync.c:65
#define t_iseq(x, c)
Definition: ts_locale.h:61
#define UNCHAR
Definition: ltree_io.c:20
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define LEVEL_NEXT(x)
Definition: ltree.h:17
#define ereport(elevel, rest)
Definition: elog.h:122
Definition: ltree.h:19
#define MaxAllocSize
Definition: memutils.h:40
uint16 numlevel
Definition: ltree.h:22
void * palloc0(Size size)
Definition: mcxt.c:878
Definition: regguts.h:298
#define LTPRS_WAITDELIM
Definition: ltree_io.c:35
#define MAXALIGN(LEN)
Definition: c.h:588
int pg_mblen(const char *mbstr)
Definition: mbutils.c:771
tuple list
Definition: sort-test.py:11
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define LTREE_FIRST(x)
Definition: ltree.h:27
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define elog
Definition: elog.h:219
#define LEVEL_HDRSIZE
Definition: ltree.h:16
Datum ltree_isparent ( PG_FUNCTION_ARGS  )

Definition at line 160 of file ltree_op.c.

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

Referenced by _ltree_extract_isparent(), and _ltree_isparent().

161 {
162  ltree *c = PG_GETARG_LTREE(1);
163  ltree *p = PG_GETARG_LTREE(0);
164  bool res = inner_isparent(c, p);
165 
166  PG_FREE_IF_COPY(c, 1);
167  PG_FREE_IF_COPY(p, 0);
168  PG_RETURN_BOOL(res);
169 }
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:136
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
char * c
Definition: ltree.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
Datum ltree_risparent ( PG_FUNCTION_ARGS  )

Definition at line 172 of file ltree_op.c.

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

Referenced by _ltree_extract_risparent(), and _ltree_risparent().

173 {
174  ltree *c = PG_GETARG_LTREE(0);
175  ltree *p = PG_GETARG_LTREE(1);
176  bool res = inner_isparent(c, p);
177 
178  PG_FREE_IF_COPY(c, 0);
179  PG_FREE_IF_COPY(p, 1);
180  PG_RETURN_BOOL(res);
181 }
bool inner_isparent(const ltree *c, const ltree *p)
Definition: ltree_op.c:136
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
char * c
Definition: ltree.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
int ltree_strncasecmp ( const char *  a,
const char *  b,
size_t  s 
)

Definition at line 91 of file lquery_op.c.

References DEFAULT_COLLATION_OID, pfree(), and str_tolower().

Referenced by checkcondition_str(), and checkLevel().

92 {
93  char *al = str_tolower(a, s, DEFAULT_COLLATION_OID);
94  char *bl = str_tolower(b, s, DEFAULT_COLLATION_OID);
95  int res;
96 
97  res = strncmp(al, bl, s);
98 
99  pfree(al);
100  pfree(bl);
101 
102  return res;
103 }
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1509
void pfree(void *pointer)
Definition: mcxt.c:950
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:74
Datum ltree_textadd ( PG_FUNCTION_ARGS  )

Definition at line 381 of file ltree_op.c.

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

382 {
383  ltree *a = PG_GETARG_LTREE(1);
384  text *b = PG_GETARG_TEXT_PP(0);
385  char *s;
386  ltree *r,
387  *tmp;
388 
389  s = text_to_cstring(b);
390 
392  PointerGetDatum(s)));
393 
394  pfree(s);
395 
396  r = ltree_concat(tmp, a);
397 
398  pfree(tmp);
399 
400  PG_FREE_IF_COPY(a, 1);
401  PG_FREE_IF_COPY(b, 0);
403 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
Datum ltree_in(PG_FUNCTION_ARGS)
Definition: ltree_io.c:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
void pfree(void *pointer)
Definition: mcxt.c:950
static ltree * ltree_concat(ltree *a, ltree *b)
Definition: ltree_op.c:267
Definition: ltree.h:19
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define DatumGetPointer(X)
Definition: postgres.h:555
char * text_to_cstring(const text *t)
Definition: varlena.c:182
Definition: c.h:439
Datum ltxtq_exec ( PG_FUNCTION_ARGS  )

Definition at line 87 of file ltxtquery_op.c.

References checkcondition_str(), GETOPERAND, GETQUERY, ltree_execute(), CHKVAL::node, CHKVAL::operand, PG_FREE_IF_COPY, PG_GETARG_LTREE, PG_GETARG_LTXTQUERY, PG_RETURN_BOOL, result, and val.

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

88 {
90  ltxtquery *query = PG_GETARG_LTXTQUERY(1);
91  CHKVAL chkval;
92  bool result;
93 
94  chkval.node = val;
95  chkval.operand = GETOPERAND(query);
96 
97  result = ltree_execute(
98  GETQUERY(query),
99  &chkval,
100  true,
102  );
103 
104  PG_FREE_IF_COPY(val, 0);
105  PG_FREE_IF_COPY(query, 1);
106  PG_RETURN_BOOL(result);
107 }
#define PG_GETARG_LTXTQUERY(x)
Definition: ltree.h:172
return result
Definition: formatting.c:1618
#define GETQUERY(x)
Definition: _int.h:142
#define GETOPERAND(x)
Definition: ltree.h:118
#define PG_GETARG_LTREE(x)
Definition: ltree.h:168
static bool checkcondition_str(void *checkval, ITEM *val)
Definition: ltxtquery_op.c:56
char * operand
Definition: ltxtquery_op.c:52
Definition: ltree.h:19
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
ltree * node
Definition: ltxtquery_op.c:51
long val
Definition: informix.c:689
bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))
Definition: ltxtquery_op.c:20
Datum ltxtq_rexec ( PG_FUNCTION_ARGS  )

Definition at line 110 of file ltxtquery_op.c.

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

111 {
113  PG_GETARG_DATUM(1),
114  PG_GETARG_DATUM(0)
115  ));
116 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
Datum ltxtq_exec(PG_FUNCTION_ARGS)
Definition: ltxtquery_op.c:87
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586