PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
_int_bool.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "_int.h"
Include dependency graph for _int_bool.c:

Go to the source code of this file.

Data Structures

struct  NODE
 
struct  WORKSTATE
 
struct  CHKVAL
 
struct  GinChkVal
 
struct  INFIX
 

Macros

#define WAITOPERAND   1
 
#define WAITENDOPERAND   2
 
#define WAITOPERATOR   3
 
#define STACKDEPTH   16
 
#define RESIZEBUF(inf, addsize)
 

Typedefs

typedef struct NODE NODE
 

Functions

 PG_FUNCTION_INFO_V1 (bqarr_in)
 
 PG_FUNCTION_INFO_V1 (bqarr_out)
 
 PG_FUNCTION_INFO_V1 (boolop)
 
 PG_FUNCTION_INFO_V1 (rboolop)
 
 PG_FUNCTION_INFO_V1 (querytree)
 
static int32 gettoken (WORKSTATE *state, int32 *val)
 
static void pushquery (WORKSTATE *state, int32 type, int32 val)
 
static int32 makepol (WORKSTATE *state)
 
static bool checkcondition_arr (void *checkval, ITEM *item)
 
static bool checkcondition_bit (void *checkval, ITEM *item)
 
static bool execute (ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
 
bool signconsistent (QUERYTYPE *query, BITVEC sign, bool calcnot)
 
bool execconsistent (QUERYTYPE *query, ArrayType *array, bool calcnot)
 
static bool checkcondition_gin (void *checkval, ITEM *item)
 
bool gin_bool_consistent (QUERYTYPE *query, bool *check)
 
static bool contains_required_value (ITEM *curitem)
 
bool query_has_required_values (QUERYTYPE *query)
 
Datum rboolop (PG_FUNCTION_ARGS)
 
Datum boolop (PG_FUNCTION_ARGS)
 
static void findoprnd (ITEM *ptr, int32 *pos)
 
Datum bqarr_in (PG_FUNCTION_ARGS)
 
static void infix (INFIX *in, bool first)
 
Datum bqarr_out (PG_FUNCTION_ARGS)
 
Datum querytree (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

#define RESIZEBUF (   inf,
  addsize 
)
Value:
while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) { \
int32 len = inf->cur - inf->buf; \
inf->buflen *= 2; \
inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
inf->cur = inf->buf + len; \
}
struct cursor * cur
Definition: ecpg.c:28
signed int int32
Definition: c.h:256
static char * buf
Definition: pg_test_fsync.c:66
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:963

Definition at line 557 of file _int_bool.c.

Referenced by infix().

#define STACKDEPTH   16

Definition at line 148 of file _int_bool.c.

Referenced by makepol().

#define WAITENDOPERAND   2

Definition at line 20 of file _int_bool.c.

Referenced by gettoken().

#define WAITOPERAND   1

Definition at line 19 of file _int_bool.c.

Referenced by bqarr_in(), and gettoken().

#define WAITOPERATOR   3

Definition at line 21 of file _int_bool.c.

Referenced by gettoken().

Typedef Documentation

typedef struct NODE NODE

Function Documentation

Datum boolop ( PG_FUNCTION_ARGS  )

Definition at line 420 of file _int_bool.c.

References CHKVAL::arrb, CHKVAL::arre, ARRNELEMS, ARRPTR, CHECKARRVALID, checkcondition_arr(), execute(), GETQUERY, pfree(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P_COPY, PG_GETARG_QUERYTYPE_P, PG_RETURN_BOOL, PREPAREARR, result, QUERYTYPE::size, and val.

Referenced by _copyBoolExpr(), _equalBoolExpr(), and_clause(), makeBoolExpr(), not_clause(), or_clause(), and rboolop().

421 {
423  QUERYTYPE *query = PG_GETARG_QUERYTYPE_P(1);
424  CHKVAL chkval;
425  bool result;
426 
427  CHECKARRVALID(val);
428  PREPAREARR(val);
429  chkval.arrb = ARRPTR(val);
430  chkval.arre = chkval.arrb + ARRNELEMS(val);
431  result = execute(GETQUERY(query) + query->size - 1,
432  &chkval, true,
434  pfree(val);
435 
436  PG_FREE_IF_COPY(query, 1);
437  PG_RETURN_BOOL(result);
438 }
#define PG_GETARG_QUERYTYPE_P(n)
Definition: _int.h:155
static bool checkcondition_arr(void *checkval, ITEM *item)
Definition: _int_bool.c:236
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
#define PREPAREARR(x)
Definition: _int.h:37
return result
Definition: formatting.c:1618
#define GETQUERY(x)
Definition: _int.h:142
int32 * arrb
Definition: _int_bool.c:228
void pfree(void *pointer)
Definition: mcxt.c:950
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define ARRNELEMS(x)
Definition: cube.c:27
int32 * arre
Definition: _int_bool.c:229
#define ARRPTR(x)
Definition: cube.c:26
int32 size
Definition: _int.h:135
long val
Definition: informix.c:689
Datum bqarr_in ( PG_FUNCTION_ARGS  )

Definition at line 478 of file _int_bool.c.

References appendStringInfo(), WORKSTATE::buf, buf, COMPUTESIZE, WORKSTATE::count, StringInfoData::data, DEBUG3, elog, ereport, errcode(), errmsg(), ERROR, findoprnd(), GETQUERY, i, initStringInfo(), NODE::left, makepol(), NODE::next, NULL, WORKSTATE::num, OPR, palloc(), pfree(), PG_GETARG_POINTER, PG_RETURN_POINTER, QUERYTYPEMAXITEMS, SET_VARSIZE, QUERYTYPE::size, WORKSTATE::state, WORKSTATE::str, NODE::type, ITEM::type, NODE::val, ITEM::val, val, and WAITOPERAND.

479 {
480  char *buf = (char *) PG_GETARG_POINTER(0);
482  int32 i;
483  QUERYTYPE *query;
484  int32 commonlen;
485  ITEM *ptr;
486  NODE *tmp;
487  int32 pos = 0;
488 
489 #ifdef BS_DEBUG
490  StringInfoData pbuf;
491 #endif
492 
493  state.buf = buf;
494  state.state = WAITOPERAND;
495  state.count = 0;
496  state.num = 0;
497  state.str = NULL;
498 
499  /* make polish notation (postfix, but in reverse order) */
500  makepol(&state);
501  if (!state.num)
502  ereport(ERROR,
503  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
504  errmsg("empty query")));
505 
506  if (state.num > QUERYTYPEMAXITEMS)
507  ereport(ERROR,
508  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
509  errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
510  state.num, (int) QUERYTYPEMAXITEMS)));
511  commonlen = COMPUTESIZE(state.num);
512 
513  query = (QUERYTYPE *) palloc(commonlen);
514  SET_VARSIZE(query, commonlen);
515  query->size = state.num;
516  ptr = GETQUERY(query);
517 
518  for (i = state.num - 1; i >= 0; i--)
519  {
520  ptr[i].type = state.str->type;
521  ptr[i].val = state.str->val;
522  tmp = state.str->next;
523  pfree(state.str);
524  state.str = tmp;
525  }
526 
527  pos = query->size - 1;
528  findoprnd(ptr, &pos);
529 #ifdef BS_DEBUG
530  initStringInfo(&pbuf);
531  for (i = 0; i < query->size; i++)
532  {
533  if (ptr[i].type == OPR)
534  appendStringInfo(&pbuf, "%c(%d) ", ptr[i].val, ptr[i].left);
535  else
536  appendStringInfo(&pbuf, "%d ", ptr[i].val);
537  }
538  elog(DEBUG3, "POR: %s", pbuf.data);
539  pfree(pbuf.data);
540 #endif
541 
542  PG_RETURN_POINTER(query);
543 }
Definition: _int.h:125
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Definition: _int_bool.c:27
#define WAITOPERAND
Definition: _int_bool.c:19
#define DEBUG3
Definition: elog.h:23
int32 val
Definition: _int_bool.c:30
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define GETQUERY(x)
Definition: _int.h:142
struct NODE * next
Definition: _int_bool.c:31
int32 count
Definition: _int_bool.c:38
int32 state
Definition: _int_bool.c:37
signed int int32
Definition: c.h:256
static void findoprnd(ITEM *ptr, int32 *pos)
Definition: _int_bool.c:441
int16 type
Definition: _int.h:127
void pfree(void *pointer)
Definition: mcxt.c:950
NODE * str
Definition: _int_bool.c:40
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:66
int32 val
Definition: _int.h:129
char * buf
Definition: _int_bool.c:36
#define ereport(elevel, rest)
Definition: elog.h:122
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
#define COMPUTESIZE(size)
Definition: _int.h:140
#define NULL
Definition: c.h:229
#define OPR
Definition: _int.h:148
Definition: regguts.h:298
int32 num
Definition: _int_bool.c:42
static int32 makepol(WORKSTATE *state)
Definition: _int_bool.c:154
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define elog
Definition: elog.h:219
int32 size
Definition: _int.h:135
long val
Definition: informix.c:689
#define QUERYTYPEMAXITEMS
Definition: _int.h:141
int32 type
Definition: _int_bool.c:29
Datum bqarr_out ( PG_FUNCTION_ARGS  )

Definition at line 642 of file _int_bool.c.

References INFIX::buf, INFIX::buflen, INFIX::cur, INFIX::curpol, ereport, errcode(), errmsg(), ERROR, GETQUERY, infix(), palloc(), PG_FREE_IF_COPY, PG_GETARG_QUERYTYPE_P, PG_RETURN_POINTER, and QUERYTYPE::size.

643 {
644  QUERYTYPE *query = PG_GETARG_QUERYTYPE_P(0);
645  INFIX nrm;
646 
647  if (query->size == 0)
648  ereport(ERROR,
649  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
650  errmsg("empty query")));
651 
652  nrm.curpol = GETQUERY(query) + query->size - 1;
653  nrm.buflen = 32;
654  nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
655  *(nrm.cur) = '\0';
656  infix(&nrm, true);
657 
658  PG_FREE_IF_COPY(query, 0);
659  PG_RETURN_POINTER(nrm.buf);
660 }
#define PG_GETARG_QUERYTYPE_P(n)
Definition: _int.h:155
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
ITEM * curpol
Definition: _int_bool.c:551
int errcode(int sqlerrcode)
Definition: elog.c:575
#define GETQUERY(x)
Definition: _int.h:142
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static void infix(INFIX *in, bool first)
Definition: _int_bool.c:565
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
char * cur
Definition: _int_bool.c:553
void * palloc(Size size)
Definition: mcxt.c:849
int32 buflen
Definition: _int_bool.c:554
int errmsg(const char *fmt,...)
Definition: elog.c:797
int32 size
Definition: _int.h:135
char * buf
Definition: _int_bool.c:552
static bool checkcondition_arr ( void *  checkval,
ITEM item 
)
static

Definition at line 236 of file _int_bool.c.

References ITEM::val, and val.

Referenced by boolop(), and execconsistent().

237 {
238  int32 *StopLow = ((CHKVAL *) checkval)->arrb;
239  int32 *StopHigh = ((CHKVAL *) checkval)->arre;
240  int32 *StopMiddle;
241 
242  /* Loop invariant: StopLow <= val < StopHigh */
243 
244  while (StopLow < StopHigh)
245  {
246  StopMiddle = StopLow + (StopHigh - StopLow) / 2;
247  if (*StopMiddle == item->val)
248  return (true);
249  else if (*StopMiddle < item->val)
250  StopLow = StopMiddle + 1;
251  else
252  StopHigh = StopMiddle;
253  }
254  return false;
255 }
signed int int32
Definition: c.h:256
int32 val
Definition: _int.h:129
long val
Definition: informix.c:689
static bool checkcondition_bit ( void *  checkval,
ITEM item 
)
static

Definition at line 258 of file _int_bool.c.

References GETBIT, HASHVAL, and ITEM::val.

Referenced by signconsistent().

259 {
260  return GETBIT(checkval, HASHVAL(item->val));
261 }
#define GETBIT(x, i)
Definition: blutils.c:34
int32 val
Definition: _int.h:129
#define HASHVAL(val)
Definition: hstore_gist.c:37
static bool checkcondition_gin ( void *  checkval,
ITEM item 
)
static

Definition at line 329 of file _int_bool.c.

References GinChkVal::first, and GinChkVal::mapped_check.

Referenced by gin_bool_consistent().

330 {
331  GinChkVal *gcv = (GinChkVal *) checkval;
332 
333  return gcv->mapped_check[item - gcv->first];
334 }
bool * mapped_check
Definition: _int_bool.c:325
ITEM * first
Definition: _int_bool.c:324
static bool contains_required_value ( ITEM curitem)
static

Definition at line 365 of file _int_bool.c.

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

Referenced by query_has_required_values().

366 {
367  /* since this function recurses, it could be driven to stack overflow */
369 
370  if (curitem->type == VAL)
371  return true;
372  else if (curitem->val == (int32) '!')
373  {
374  /*
375  * Assume anything under a NOT is non-required. For some cases with
376  * nested NOTs, we could prove there's a required value, but it seems
377  * unlikely to be worth the trouble.
378  */
379  return false;
380  }
381  else if (curitem->val == (int32) '&')
382  {
383  /* If either side has a required value, we're good */
384  if (contains_required_value(curitem + curitem->left))
385  return true;
386  else
387  return contains_required_value(curitem - 1);
388  }
389  else
390  { /* |-operator */
391  /* Both sides must have required values */
392  if (contains_required_value(curitem + curitem->left))
393  return contains_required_value(curitem - 1);
394  else
395  return false;
396  }
397 }
static bool contains_required_value(ITEM *curitem)
Definition: _int_bool.c:365
signed int int32
Definition: c.h:256
int16 type
Definition: _int.h:127
void check_stack_depth(void)
Definition: postgres.c:3102
int32 val
Definition: _int.h:129
int16 left
Definition: _int.h:128
#define VAL
Definition: _int.h:147
bool execconsistent ( QUERYTYPE query,
ArrayType array,
bool  calcnot 
)

Definition at line 310 of file _int_bool.c.

References CHKVAL::arrb, CHKVAL::arre, ARRNELEMS, ARRPTR, CHECKARRVALID, checkcondition_arr(), execute(), GETQUERY, and QUERYTYPE::size.

Referenced by g_int_consistent().

311 {
312  CHKVAL chkval;
313 
314  CHECKARRVALID(array);
315  chkval.arrb = ARRPTR(array);
316  chkval.arre = chkval.arrb + ARRNELEMS(array);
317  return execute(GETQUERY(query) + query->size - 1,
318  (void *) &chkval, calcnot,
320 }
static bool checkcondition_arr(void *checkval, ITEM *item)
Definition: _int_bool.c:236
#define CHECKARRVALID(x)
Definition: _int.h:18
#define GETQUERY(x)
Definition: _int.h:142
int32 * arrb
Definition: _int_bool.c:228
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
#define ARRNELEMS(x)
Definition: cube.c:27
int32 * arre
Definition: _int_bool.c:229
#define ARRPTR(x)
Definition: cube.c:26
int32 size
Definition: _int.h:135
static bool execute ( ITEM curitem,
void *  checkval,
bool  calcnot,
bool(*)(void *checkval, ITEM *item)  chkcond 
)
static

Definition at line 267 of file _int_bool.c.

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

Referenced by boolop(), execconsistent(), gin_bool_consistent(), and signconsistent().

269 {
270  /* since this function recurses, it could be driven to stack overflow */
272 
273  if (curitem->type == VAL)
274  return (*chkcond) (checkval, curitem);
275  else if (curitem->val == (int32) '!')
276  {
277  return (calcnot) ?
278  ((execute(curitem - 1, checkval, calcnot, chkcond)) ? false : true)
279  : true;
280  }
281  else if (curitem->val == (int32) '&')
282  {
283  if (execute(curitem + curitem->left, checkval, calcnot, chkcond))
284  return execute(curitem - 1, checkval, calcnot, chkcond);
285  else
286  return false;
287  }
288  else
289  { /* |-operator */
290  if (execute(curitem + curitem->left, checkval, calcnot, chkcond))
291  return true;
292  else
293  return execute(curitem - 1, checkval, calcnot, chkcond);
294  }
295 }
signed int int32
Definition: c.h:256
int16 type
Definition: _int.h:127
void check_stack_depth(void)
Definition: postgres.c:3102
int32 val
Definition: _int.h:129
int16 left
Definition: _int.h:128
#define VAL
Definition: _int.h:147
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
static void findoprnd ( ITEM ptr,
int32 pos 
)
static

Definition at line 441 of file _int_bool.c.

References check_stack_depth(), DEBUG3, elog, ITEM::left, OPR, NODE::type, VAL, and val.

Referenced by bqarr_in().

442 {
443  /* since this function recurses, it could be driven to stack overflow. */
445 
446 #ifdef BS_DEBUG
447  elog(DEBUG3, (ptr[*pos].type == OPR) ?
448  "%d %c" : "%d %d", *pos, ptr[*pos].val);
449 #endif
450  if (ptr[*pos].type == VAL)
451  {
452  ptr[*pos].left = 0;
453  (*pos)--;
454  }
455  else if (ptr[*pos].val == (int32) '!')
456  {
457  ptr[*pos].left = -1;
458  (*pos)--;
459  findoprnd(ptr, pos);
460  }
461  else
462  {
463  ITEM *curitem = &ptr[*pos];
464  int32 tmp = *pos;
465 
466  (*pos)--;
467  findoprnd(ptr, pos);
468  curitem->left = *pos - tmp;
469  findoprnd(ptr, pos);
470  }
471 }
Definition: _int.h:125
#define DEBUG3
Definition: elog.h:23
signed int int32
Definition: c.h:256
static void findoprnd(ITEM *ptr, int32 *pos)
Definition: _int_bool.c:441
void check_stack_depth(void)
Definition: postgres.c:3102
int16 left
Definition: _int.h:128
#define VAL
Definition: _int.h:147
#define OPR
Definition: _int.h:148
#define elog
Definition: elog.h:219
long val
Definition: informix.c:689
static int32 gettoken ( WORKSTATE state,
int32 val 
)
static

Definition at line 49 of file _int_bool.c.

References WORKSTATE::buf, CLOSE, WORKSTATE::count, END, ERR, NULL, OPEN, OPR, WORKSTATE::state, VAL, WAITENDOPERAND, WAITOPERAND, and WAITOPERATOR.

Referenced by makepol().

50 {
51  char nnn[16];
52  int innn;
53 
54  *val = 0; /* default result */
55 
56  innn = 0;
57  while (1)
58  {
59  if (innn >= sizeof(nnn))
60  return ERR; /* buffer overrun => syntax error */
61  switch (state->state)
62  {
63  case WAITOPERAND:
64  innn = 0;
65  if ((*(state->buf) >= '0' && *(state->buf) <= '9') ||
66  *(state->buf) == '-')
67  {
68  state->state = WAITENDOPERAND;
69  nnn[innn++] = *(state->buf);
70  }
71  else if (*(state->buf) == '!')
72  {
73  (state->buf)++;
74  *val = (int32) '!';
75  return OPR;
76  }
77  else if (*(state->buf) == '(')
78  {
79  state->count++;
80  (state->buf)++;
81  return OPEN;
82  }
83  else if (*(state->buf) != ' ')
84  return ERR;
85  break;
86  case WAITENDOPERAND:
87  if (*(state->buf) >= '0' && *(state->buf) <= '9')
88  {
89  nnn[innn++] = *(state->buf);
90  }
91  else
92  {
93  long lval;
94 
95  nnn[innn] = '\0';
96  errno = 0;
97  lval = strtol(nnn, NULL, 0);
98  *val = (int32) lval;
99  if (errno != 0 || (long) *val != lval)
100  return ERR;
101  state->state = WAITOPERATOR;
102  return (state->count && *(state->buf) == '\0')
103  ? ERR : VAL;
104  }
105  break;
106  case WAITOPERATOR:
107  if (*(state->buf) == '&' || *(state->buf) == '|')
108  {
109  state->state = WAITOPERAND;
110  *val = (int32) *(state->buf);
111  (state->buf)++;
112  return OPR;
113  }
114  else if (*(state->buf) == ')')
115  {
116  (state->buf)++;
117  state->count--;
118  return (state->count < 0) ? ERR : CLOSE;
119  }
120  else if (*(state->buf) == '\0')
121  return (state->count) ? ERR : END;
122  else if (*(state->buf) != ' ')
123  return ERR;
124  break;
125  default:
126  return ERR;
127  break;
128  }
129  (state->buf)++;
130  }
131 }
#define ERR
Definition: _int.h:146
#define WAITOPERAND
Definition: _int_bool.c:19
#define WAITOPERATOR
Definition: _int_bool.c:21
int32 count
Definition: _int_bool.c:38
int32 state
Definition: _int_bool.c:37
signed int int32
Definition: c.h:256
#define END
Definition: _int.h:145
#define CLOSE
Definition: _int.h:150
char * buf
Definition: _int_bool.c:36
#define OPEN
Definition: _int.h:149
#define VAL
Definition: _int.h:147
#define WAITENDOPERAND
Definition: _int_bool.c:20
#define NULL
Definition: c.h:229
#define OPR
Definition: _int.h:148
long val
Definition: informix.c:689
bool gin_bool_consistent ( QUERYTYPE query,
bool check 
)

Definition at line 337 of file _int_bool.c.

References checkcondition_gin(), execute(), FALSE, GinChkVal::first, GETQUERY, i, GinChkVal::mapped_check, palloc(), QUERYTYPE::size, NODE::type, and VAL.

Referenced by ginint4_consistent().

338 {
339  GinChkVal gcv;
340  ITEM *items = GETQUERY(query);
341  int i,
342  j = 0;
343 
344  if (query->size <= 0)
345  return FALSE;
346 
347  /*
348  * Set up data for checkcondition_gin. This must agree with the query
349  * extraction code in ginint4_queryextract.
350  */
351  gcv.first = items;
352  gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
353  for (i = 0; i < query->size; i++)
354  {
355  if (items[i].type == VAL)
356  gcv.mapped_check[i] = check[j++];
357  }
358 
359  return execute(GETQUERY(query) + query->size - 1,
360  (void *) &gcv, true,
362 }
Definition: _int.h:125
bool * mapped_check
Definition: _int_bool.c:325
#define GETQUERY(x)
Definition: _int.h:142
#define FALSE
Definition: c.h:221
#define VAL
Definition: _int.h:147
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
void * palloc(Size size)
Definition: mcxt.c:849
int i
ITEM * first
Definition: _int_bool.c:324
int32 size
Definition: _int.h:135
static bool checkcondition_gin(void *checkval, ITEM *item)
Definition: _int_bool.c:329
static void infix ( INFIX in,
bool  first 
)
static

Definition at line 565 of file _int_bool.c.

References INFIX::buf, INFIX::buflen, check_stack_depth(), INFIX::cur, INFIX::curpol, OPR, palloc(), pfree(), RESIZEBUF, ITEM::type, ITEM::val, and VAL.

Referenced by bqarr_out().

566 {
567  /* since this function recurses, it could be driven to stack overflow. */
569 
570  if (in->curpol->type == VAL)
571  {
572  RESIZEBUF(in, 11);
573  sprintf(in->cur, "%d", in->curpol->val);
574  in->cur = strchr(in->cur, '\0');
575  in->curpol--;
576  }
577  else if (in->curpol->val == (int32) '!')
578  {
579  bool isopr = false;
580 
581  RESIZEBUF(in, 1);
582  *(in->cur) = '!';
583  in->cur++;
584  *(in->cur) = '\0';
585  in->curpol--;
586  if (in->curpol->type == OPR)
587  {
588  isopr = true;
589  RESIZEBUF(in, 2);
590  sprintf(in->cur, "( ");
591  in->cur = strchr(in->cur, '\0');
592  }
593  infix(in, isopr);
594  if (isopr)
595  {
596  RESIZEBUF(in, 2);
597  sprintf(in->cur, " )");
598  in->cur = strchr(in->cur, '\0');
599  }
600  }
601  else
602  {
603  int32 op = in->curpol->val;
604  INFIX nrm;
605 
606  in->curpol--;
607  if (op == (int32) '|' && !first)
608  {
609  RESIZEBUF(in, 2);
610  sprintf(in->cur, "( ");
611  in->cur = strchr(in->cur, '\0');
612  }
613 
614  nrm.curpol = in->curpol;
615  nrm.buflen = 16;
616  nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
617 
618  /* get right operand */
619  infix(&nrm, false);
620 
621  /* get & print left operand */
622  in->curpol = nrm.curpol;
623  infix(in, false);
624 
625  /* print operator & right operand */
626  RESIZEBUF(in, 3 + (nrm.cur - nrm.buf));
627  sprintf(in->cur, " %c %s", op, nrm.buf);
628  in->cur = strchr(in->cur, '\0');
629  pfree(nrm.buf);
630 
631  if (op == (int32) '|' && !first)
632  {
633  RESIZEBUF(in, 2);
634  sprintf(in->cur, " )");
635  in->cur = strchr(in->cur, '\0');
636  }
637  }
638 }
ITEM * curpol
Definition: _int_bool.c:551
signed int int32
Definition: c.h:256
int16 type
Definition: _int.h:127
void pfree(void *pointer)
Definition: mcxt.c:950
void check_stack_depth(void)
Definition: postgres.c:3102
int32 val
Definition: _int.h:129
static void infix(INFIX *in, bool first)
Definition: _int_bool.c:565
#define VAL
Definition: _int.h:147
#define OPR
Definition: _int.h:148
#define RESIZEBUF(inf, addsize)
Definition: _int_bool.c:557
char * cur
Definition: _int_bool.c:553
void * palloc(Size size)
Definition: mcxt.c:849
int32 buflen
Definition: _int_bool.c:554
char * buf
Definition: _int_bool.c:552
static int32 makepol ( WORKSTATE state)
static

Definition at line 154 of file _int_bool.c.

References check_stack_depth(), CLOSE, END, ereport, ERR, errcode(), errmsg(), ERROR, gettoken(), OPEN, OPR, pushquery(), STACKDEPTH, NODE::type, VAL, and val.

Referenced by bqarr_in().

155 {
156  int32 val,
157  type;
158  int32 stack[STACKDEPTH];
159  int32 lenstack = 0;
160 
161  /* since this function recurses, it could be driven to stack overflow */
163 
164  while ((type = gettoken(state, &val)) != END)
165  {
166  switch (type)
167  {
168  case VAL:
169  pushquery(state, type, val);
170  while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
171  stack[lenstack - 1] == (int32) '!'))
172  {
173  lenstack--;
174  pushquery(state, OPR, stack[lenstack]);
175  }
176  break;
177  case OPR:
178  if (lenstack && val == (int32) '|')
179  pushquery(state, OPR, val);
180  else
181  {
182  if (lenstack == STACKDEPTH)
183  ereport(ERROR,
184  (errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
185  errmsg("statement too complex")));
186  stack[lenstack] = val;
187  lenstack++;
188  }
189  break;
190  case OPEN:
191  if (makepol(state) == ERR)
192  return ERR;
193  while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
194  stack[lenstack - 1] == (int32) '!'))
195  {
196  lenstack--;
197  pushquery(state, OPR, stack[lenstack]);
198  }
199  break;
200  case CLOSE:
201  while (lenstack)
202  {
203  lenstack--;
204  pushquery(state, OPR, stack[lenstack]);
205  };
206  return END;
207  break;
208  case ERR:
209  default:
210  ereport(ERROR,
211  (errcode(ERRCODE_SYNTAX_ERROR),
212  errmsg("syntax error")));
213  return ERR;
214 
215  }
216  }
217 
218  while (lenstack)
219  {
220  lenstack--;
221  pushquery(state, OPR, stack[lenstack]);
222  };
223  return END;
224 }
#define ERR
Definition: _int.h:146
static int32 gettoken(WORKSTATE *state, int32 *val)
Definition: _int_bool.c:49
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:256
#define END
Definition: _int.h:145
#define CLOSE
Definition: _int.h:150
#define ERROR
Definition: elog.h:43
void check_stack_depth(void)
Definition: postgres.c:3102
#define ereport(elevel, rest)
Definition: elog.h:122
#define OPEN
Definition: _int.h:149
#define VAL
Definition: _int.h:147
#define OPR
Definition: _int.h:148
static int32 makepol(WORKSTATE *state)
Definition: _int_bool.c:154
int errmsg(const char *fmt,...)
Definition: elog.c:797
static void pushquery(WORKSTATE *state, int32 type, int32 val)
Definition: _int_bool.c:137
#define STACKDEPTH
Definition: _int_bool.c:148
long val
Definition: informix.c:689
PG_FUNCTION_INFO_V1 ( bqarr_in  )
PG_FUNCTION_INFO_V1 ( bqarr_out  )
PG_FUNCTION_INFO_V1 ( boolop  )
PG_FUNCTION_INFO_V1 ( rboolop  )
PG_FUNCTION_INFO_V1 ( querytree  )
static void pushquery ( WORKSTATE state,
int32  type,
int32  val 
)
static

Definition at line 137 of file _int_bool.c.

References NODE::next, WORKSTATE::num, palloc(), WORKSTATE::str, NODE::type, NODE::val, and val.

Referenced by makepol().

138 {
139  NODE *tmp = (NODE *) palloc(sizeof(NODE));
140 
141  tmp->type = type;
142  tmp->val = val;
143  tmp->next = state->str;
144  state->str = tmp;
145  state->num++;
146 }
Definition: _int_bool.c:27
int32 val
Definition: _int_bool.c:30
struct NODE * next
Definition: _int_bool.c:31
NODE * str
Definition: _int_bool.c:40
int32 num
Definition: _int_bool.c:42
void * palloc(Size size)
Definition: mcxt.c:849
long val
Definition: informix.c:689
int32 type
Definition: _int_bool.c:29
bool query_has_required_values ( QUERYTYPE query)

Definition at line 400 of file _int_bool.c.

References contains_required_value(), GETQUERY, and QUERYTYPE::size.

Referenced by ginint4_queryextract().

401 {
402  if (query->size <= 0)
403  return false;
404  return contains_required_value(GETQUERY(query) + query->size - 1);
405 }
static bool contains_required_value(ITEM *curitem)
Definition: _int_bool.c:365
#define GETQUERY(x)
Definition: _int.h:142
int32 size
Definition: _int.h:135
Datum querytree ( PG_FUNCTION_ARGS  )

Definition at line 665 of file _int_bool.c.

References elog, ERROR, and PG_RETURN_NULL.

Referenced by inline_function(), and inline_set_returning_function().

666 {
667  elog(ERROR, "querytree is no longer implemented");
668  PG_RETURN_NULL();
669 }
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum rboolop ( PG_FUNCTION_ARGS  )

Definition at line 411 of file _int_bool.c.

References boolop(), DirectFunctionCall2, and PG_GETARG_DATUM.

412 {
413  /* just reverse the operands */
415  PG_GETARG_DATUM(1),
416  PG_GETARG_DATUM(0));
417 }
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:420
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
bool signconsistent ( QUERYTYPE query,
BITVEC  sign,
bool  calcnot 
)

Definition at line 301 of file _int_bool.c.

References checkcondition_bit(), execute(), GETQUERY, and QUERYTYPE::size.

Referenced by g_intbig_consistent().

302 {
303  return execute(GETQUERY(query) + query->size - 1,
304  (void *) sign, calcnot,
306 }
#define GETQUERY(x)
Definition: _int.h:142
char sign
Definition: informix.c:693
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
static bool checkcondition_bit(void *checkval, ITEM *item)
Definition: _int_bool.c:258
int32 size
Definition: _int.h:135