18#define WAITENDOPERAND 2
58 if (innn >=
sizeof(nnn))
64 if ((*(
state->buf) >=
'0' && *(
state->buf) <=
'9') ||
68 nnn[innn++] = *(
state->buf);
70 else if (*(
state->buf) ==
'!')
76 else if (*(
state->buf) ==
'(')
82 else if (*(
state->buf) !=
' ')
86 if (*(
state->buf) >=
'0' && *(
state->buf) <=
'9')
88 nnn[innn++] = *(
state->buf);
96 lval = strtol(nnn, NULL, 0);
98 if (errno != 0 || (
long) *
val != lval)
101 return (
state->count && *(
state->buf) ==
'\0')
106 if (*(
state->buf) ==
'&' || *(
state->buf) ==
'|')
113 else if (*(
state->buf) ==
')')
119 else if (*(
state->buf) ==
'\0')
121 else if (*(
state->buf) !=
' ')
169 while (lenstack && (stack[lenstack - 1] == (
int32)
'&' ||
170 stack[lenstack - 1] == (
int32)
'!'))
183 (
errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
184 errmsg(
"statement too complex")));
185 stack[lenstack] =
val;
192 while (lenstack && (stack[lenstack - 1] == (
int32)
'&' ||
193 stack[lenstack - 1] == (
int32)
'!'))
210 (
errcode(ERRCODE_SYNTAX_ERROR),
241 while (StopLow < StopHigh)
243 StopMiddle = StopLow + (StopHigh - StopLow) / 2;
244 if (*StopMiddle == item->
val)
246 else if (*StopMiddle < item->
val)
247 StopLow = StopMiddle + 1;
249 StopHigh = StopMiddle;
265 bool (*chkcond) (
void *checkval,
ITEM *item,
void *
options))
271 return (*chkcond) (checkval, curitem,
options);
272 else if (curitem->val == (
int32)
'!')
275 ((
execute(curitem - 1, checkval,
options, calcnot, chkcond)) ?
false :
true)
278 else if (curitem->val == (
int32)
'&')
280 if (
execute(curitem + curitem->left, checkval,
options, calcnot, chkcond))
287 if (
execute(curitem + curitem->left, checkval,
options, calcnot, chkcond))
301 sign, (
void *) (intptr_t) siglen, calcnot,
315 &chkval, NULL, calcnot,
341 if (query->
size <= 0)
350 for (
i = 0;
i < query->
size;
i++)
369 else if (curitem->
val == (
int32)
'!')
378 else if (curitem->
val == (
int32)
'&')
399 if (query->
size <= 0)
445 "%d %c" :
"%d %d", *pos, ptr[*pos].
val);
452 else if (ptr[*pos].
val == (
int32)
'!')
460 ITEM *curitem = &ptr[*pos];
465 curitem->
left = *pos - tmp;
485 struct Node *escontext = fcinfo->context;
496 state.escontext = escontext;
503 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
508 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
509 errmsg(
"number of query items (%d) exceeds the maximum allowed (%d)",
518 for (
i =
state.num - 1;
i >= 0;
i--)
527 pos = query->
size - 1;
531 for (
i = 0;
i < query->
size;
i++)
557#define RESIZEBUF(inf,addsize) while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) { \
558 int32 len = inf->cur - inf->buf; \
560 inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
561 inf->cur = inf->buf + len; \
574 in->
cur = strchr(in->
cur,
'\0');
591 in->
cur = strchr(in->
cur,
'\0');
598 in->
cur = strchr(in->
cur,
'\0');
607 if (op == (
int32)
'|' && !first)
611 in->
cur = strchr(in->
cur,
'\0');
628 in->
cur = strchr(in->
cur,
'\0');
631 if (op == (
int32)
'|' && !first)
635 in->
cur = strchr(in->
cur,
'\0');
647 if (query->
size == 0)
649 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
667 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)