19 #define WAITENDOPERAND 2
20 #define WAITOPERATOR 3
59 if (innn >=
sizeof(nnn))
65 if ((*(
state->buf) >=
'0' && *(
state->buf) <=
'9') ||
69 nnn[innn++] = *(
state->buf);
71 else if (*(
state->buf) ==
'!')
77 else if (*(
state->buf) ==
'(')
83 else if (*(
state->buf) !=
' ')
87 if (*(
state->buf) >=
'0' && *(
state->buf) <=
'9')
89 nnn[innn++] = *(
state->buf);
97 lval = strtol(nnn, NULL, 0);
99 if (errno != 0 || (
long) *
val != lval)
102 return (
state->count && *(
state->buf) ==
'\0')
107 if (*(
state->buf) ==
'&' || *(
state->buf) ==
'|')
114 else if (*(
state->buf) ==
')')
120 else if (*(
state->buf) ==
'\0')
122 else if (*(
state->buf) !=
' ')
148 #define STACKDEPTH 16
170 while (lenstack && (stack[lenstack - 1] == (
int32)
'&' ||
171 stack[lenstack - 1] == (
int32)
'!'))
184 (
errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
185 errmsg(
"statement too complex")));
186 stack[lenstack] =
val;
193 while (lenstack && (stack[lenstack - 1] == (
int32)
'&' ||
194 stack[lenstack - 1] == (
int32)
'!'))
211 (
errcode(ERRCODE_SYNTAX_ERROR),
242 while (StopLow < StopHigh)
244 StopMiddle = StopLow + (StopHigh - StopLow) / 2;
245 if (*StopMiddle == item->
val)
247 else if (*StopMiddle < item->
val)
248 StopLow = StopMiddle + 1;
250 StopHigh = StopMiddle;
266 bool (*chkcond) (
void *checkval,
ITEM *item,
void *
options))
272 return (*chkcond) (checkval, curitem,
options);
273 else if (curitem->val == (
int32)
'!')
276 ((
execute(curitem - 1, checkval,
options, calcnot, chkcond)) ?
false :
true)
279 else if (curitem->val == (
int32)
'&')
281 if (
execute(curitem + curitem->left, checkval,
options, calcnot, chkcond))
288 if (
execute(curitem + curitem->left, checkval,
options, calcnot, chkcond))
302 (
void *)
sign, (
void *) (intptr_t) siglen, calcnot,
316 (
void *) &chkval, NULL, calcnot,
342 if (query->
size <= 0)
351 for (
i = 0;
i < query->
size;
i++)
358 (
void *) &gcv, NULL,
true,
370 else if (curitem->
val == (
int32)
'!')
379 else if (curitem->
val == (
int32)
'&')
400 if (query->
size <= 0)
446 "%d %c" :
"%d %d", *pos, ptr[*pos].
val);
453 else if (ptr[*pos].
val == (
int32)
'!')
461 ITEM *curitem = &ptr[*pos];
466 curitem->
left = *pos - tmp;
486 struct Node *escontext = fcinfo->context;
497 state.escontext = escontext;
504 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
509 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
510 errmsg(
"number of query items (%d) exceeds the maximum allowed (%d)",
519 for (
i =
state.num - 1;
i >= 0;
i--)
528 pos = query->
size - 1;
532 for (
i = 0;
i < query->
size;
i++)
558 #define RESIZEBUF(inf,addsize) while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) { \
559 int32 len = inf->cur - inf->buf; \
561 inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
562 inf->cur = inf->buf + len; \
575 in->
cur = strchr(in->
cur,
'\0');
592 in->
cur = strchr(in->
cur,
'\0');
599 in->
cur = strchr(in->
cur,
'\0');
608 if (op == (
int32)
'|' && !first)
612 in->
cur = strchr(in->
cur,
'\0');
629 in->
cur = strchr(in->
cur,
'\0');
632 if (op == (
int32)
'|' && !first)
636 in->
cur = strchr(in->
cur,
'\0');
648 if (query->
size == 0)
650 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
668 elog(
ERROR,
"querytree is no longer implemented");
#define COMPUTESIZE(size)
#define QUERYTYPEMAXITEMS
#define PG_GETARG_QUERYTYPE_P(n)
PG_FUNCTION_INFO_V1(bqarr_in)
Datum querytree(PG_FUNCTION_ARGS)
Datum rboolop(PG_FUNCTION_ARGS)
static bool checkcondition_arr(void *checkval, ITEM *item, void *options)
bool signconsistent(QUERYTYPE *query, BITVECP sign, int siglen, bool calcnot)
static void pushquery(WORKSTATE *state, int32 type, int32 val)
static bool contains_required_value(ITEM *curitem)
static bool checkcondition_bit(void *checkval, ITEM *item, void *siglen)
#define RESIZEBUF(inf, addsize)
static void findoprnd(ITEM *ptr, int32 *pos)
static int32 makepol(WORKSTATE *state)
bool query_has_required_values(QUERYTYPE *query)
static int32 gettoken(WORKSTATE *state, int32 *val)
Datum bqarr_out(PG_FUNCTION_ARGS)
static void infix(INFIX *in, bool first)
bool execconsistent(QUERYTYPE *query, ArrayType *array, bool calcnot)
Datum boolop(PG_FUNCTION_ARGS)
Datum bqarr_in(PG_FUNCTION_ARGS)
static bool checkcondition_gin(void *checkval, ITEM *item, void *options)
static bool execute(ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
bool gin_bool_consistent(QUERYTYPE *query, bool *check)
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define PG_FREE_IF_COPY(ptr, n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_DATUM(n)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
#define HASHVAL(val, siglen)
void pfree(void *pointer)
void check_stack_depth(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void initStringInfo(StringInfo str)
#define SET_VARSIZE(PTR, len)