PostgreSQL Source Code  git master
_int_bool.c File Reference
#include "postgres.h"
#include "_int.h"
#include "miscadmin.h"
#include "utils/builtins.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, void *options)
 
static bool checkcondition_bit (void *checkval, ITEM *item, void *siglen)
 
static bool execute (ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
 
bool signconsistent (QUERYTYPE *query, BITVECP sign, int siglen, bool calcnot)
 
bool execconsistent (QUERYTYPE *query, ArrayType *array, bool calcnot)
 
static bool checkcondition_gin (void *checkval, ITEM *item, void *options)
 
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

◆ RESIZEBUF

#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
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1540
const void size_t len
static char * buf
Definition: pg_test_fsync.c:73

Definition at line 558 of file _int_bool.c.

◆ STACKDEPTH

#define STACKDEPTH   16

Definition at line 148 of file _int_bool.c.

◆ WAITENDOPERAND

#define WAITENDOPERAND   2

Definition at line 19 of file _int_bool.c.

◆ WAITOPERAND

#define WAITOPERAND   1

Definition at line 18 of file _int_bool.c.

◆ WAITOPERATOR

#define WAITOPERATOR   3

Definition at line 20 of file _int_bool.c.

Typedef Documentation

◆ NODE

typedef struct NODE NODE

Function Documentation

◆ boolop()

Datum boolop ( PG_FUNCTION_ARGS  )

Definition at line 418 of file _int_bool.c.

419 {
421  QUERYTYPE *query = PG_GETARG_QUERYTYPE_P(1);
422  CHKVAL chkval;
423  bool result;
424 
426  PREPAREARR(val);
427  chkval.arrb = ARRPTR(val);
428  chkval.arre = chkval.arrb + ARRNELEMS(val);
429  result = execute(GETQUERY(query) + query->size - 1,
430  &chkval, NULL, true,
432  pfree(val);
433 
434  PG_FREE_IF_COPY(query, 1);
435  PG_RETURN_BOOL(result);
436 }
#define PREPAREARR(x)
Definition: _int.h:49
#define CHECKARRVALID(x)
Definition: _int.h:30
#define GETQUERY(x)
Definition: _int.h:157
#define PG_GETARG_QUERYTYPE_P(n)
Definition: _int.h:170
static bool checkcondition_arr(void *checkval, ITEM *item, void *options)
Definition: _int_bool.c:234
static bool execute(ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
Definition: _int_bool.c:265
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:264
#define ARRNELEMS(x)
Definition: cube.c:26
#define ARRPTR(x)
Definition: cube.c:25
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
long val
Definition: informix.c:670
void pfree(void *pointer)
Definition: mcxt.c:1520
int32 * arrb
Definition: _int_bool.c:226
int32 * arre
Definition: _int_bool.c:227
int32 size
Definition: _int.h:150

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, QUERYTYPE::size, and val.

Referenced by is_andclause(), is_notclause(), is_orclause(), makeBoolExpr(), and rboolop().

◆ bqarr_in()

Datum bqarr_in ( PG_FUNCTION_ARGS  )

Definition at line 476 of file _int_bool.c.

477 {
478  char *buf = (char *) PG_GETARG_POINTER(0);
480  int32 i;
481  QUERYTYPE *query;
482  int32 commonlen;
483  ITEM *ptr;
484  NODE *tmp;
485  int32 pos = 0;
486  struct Node *escontext = fcinfo->context;
487 
488 #ifdef BS_DEBUG
489  StringInfoData pbuf;
490 #endif
491 
492  state.buf = buf;
493  state.state = WAITOPERAND;
494  state.count = 0;
495  state.num = 0;
496  state.str = NULL;
497  state.escontext = escontext;
498 
499  /* make polish notation (postfix, but in reverse order) */
500  if (makepol(&state) == ERR)
501  PG_RETURN_NULL();
502  if (!state.num)
503  ereturn(escontext, (Datum) 0,
504  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
505  errmsg("empty query")));
506 
507  if (state.num > QUERYTYPEMAXITEMS)
508  ereturn(escontext, (Datum) 0,
509  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
510  errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
511  state.num, (int) QUERYTYPEMAXITEMS)));
512  commonlen = COMPUTESIZE(state.num);
513 
514  query = (QUERYTYPE *) palloc(commonlen);
515  SET_VARSIZE(query, commonlen);
516  query->size = state.num;
517  ptr = GETQUERY(query);
518 
519  for (i = state.num - 1; i >= 0; i--)
520  {
521  ptr[i].type = state.str->type;
522  ptr[i].val = state.str->val;
523  tmp = state.str->next;
524  pfree(state.str);
525  state.str = tmp;
526  }
527 
528  pos = query->size - 1;
529  findoprnd(ptr, &pos);
530 #ifdef BS_DEBUG
531  initStringInfo(&pbuf);
532  for (i = 0; i < query->size; i++)
533  {
534  if (ptr[i].type == OPR)
535  appendStringInfo(&pbuf, "%c(%d) ", ptr[i].val, ptr[i].left);
536  else
537  appendStringInfo(&pbuf, "%d ", ptr[i].val);
538  }
539  elog(DEBUG3, "POR: %s", pbuf.data);
540  pfree(pbuf.data);
541 #endif
542 
543  PG_RETURN_POINTER(query);
544 }
#define COMPUTESIZE(size)
Definition: _int.h:155
#define OPR
Definition: _int.h:163
#define ERR
Definition: _int.h:161
#define QUERYTYPEMAXITEMS
Definition: _int.h:156
static void findoprnd(ITEM *ptr, int32 *pos)
Definition: _int_bool.c:439
static int32 makepol(WORKSTATE *state)
Definition: _int_bool.c:154
#define WAITOPERAND
Definition: _int_bool.c:18
signed int int32
Definition: c.h:494
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ereturn(context, dummy_value,...)
Definition: elog.h:276
#define DEBUG3
Definition: elog.h:28
#define elog(elevel,...)
Definition: elog.h:224
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1316
uintptr_t Datum
Definition: postgres.h:64
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Definition: _int.h:141
int32 val
Definition: _int.h:144
int16 type
Definition: _int.h:142
Definition: _int_bool.c:27
Definition: nodes.h:129
Definition: regguts.h:323
struct state * next
Definition: regguts.h:332
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
const char * type

References appendStringInfo(), buf, COMPUTESIZE, StringInfoData::data, DEBUG3, elog, ereturn, ERR, errcode(), errmsg(), findoprnd(), GETQUERY, i, initStringInfo(), makepol(), state::next, OPR, palloc(), pfree(), PG_GETARG_POINTER, PG_RETURN_NULL, PG_RETURN_POINTER, QUERYTYPEMAXITEMS, SET_VARSIZE, QUERYTYPE::size, ITEM::type, type, ITEM::val, val, and WAITOPERAND.

◆ bqarr_out()

Datum bqarr_out ( PG_FUNCTION_ARGS  )

Definition at line 643 of file _int_bool.c.

644 {
645  QUERYTYPE *query = PG_GETARG_QUERYTYPE_P(0);
646  INFIX nrm;
647 
648  if (query->size == 0)
649  ereport(ERROR,
650  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
651  errmsg("empty query")));
652 
653  nrm.curpol = GETQUERY(query) + query->size - 1;
654  nrm.buflen = 32;
655  nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
656  *(nrm.cur) = '\0';
657  infix(&nrm, true);
658 
659  PG_FREE_IF_COPY(query, 0);
660  PG_RETURN_POINTER(nrm.buf);
661 }
static void infix(INFIX *in, bool first)
Definition: _int_bool.c:566
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
char * buf
Definition: _int_bool.c:553
char * cur
Definition: _int_bool.c:554
int32 buflen
Definition: _int_bool.c:555
ITEM * curpol
Definition: _int_bool.c:552

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.

◆ checkcondition_arr()

static bool checkcondition_arr ( void *  checkval,
ITEM item,
void *  options 
)
static

Definition at line 234 of file _int_bool.c.

235 {
236  int32 *StopLow = ((CHKVAL *) checkval)->arrb;
237  int32 *StopHigh = ((CHKVAL *) checkval)->arre;
238  int32 *StopMiddle;
239 
240  /* Loop invariant: StopLow <= val < StopHigh */
241 
242  while (StopLow < StopHigh)
243  {
244  StopMiddle = StopLow + (StopHigh - StopLow) / 2;
245  if (*StopMiddle == item->val)
246  return true;
247  else if (*StopMiddle < item->val)
248  StopLow = StopMiddle + 1;
249  else
250  StopHigh = StopMiddle;
251  }
252  return false;
253 }

References ITEM::val, and val.

Referenced by boolop(), and execconsistent().

◆ checkcondition_bit()

static bool checkcondition_bit ( void *  checkval,
ITEM item,
void *  siglen 
)
static

Definition at line 256 of file _int_bool.c.

257 {
258  return GETBIT(checkval, HASHVAL(item->val, (int) (intptr_t) siglen));
259 }
#define GETBIT(x, i)
Definition: blutils.c:33
#define HASHVAL(val, siglen)
Definition: hstore_gist.c:45

References GETBIT, HASHVAL, and ITEM::val.

Referenced by signconsistent().

◆ checkcondition_gin()

static bool checkcondition_gin ( void *  checkval,
ITEM item,
void *  options 
)
static

Definition at line 327 of file _int_bool.c.

328 {
329  GinChkVal *gcv = (GinChkVal *) checkval;
330 
331  return gcv->mapped_check[item - gcv->first];
332 }
ITEM * first
Definition: _int_bool.c:322
bool * mapped_check
Definition: _int_bool.c:323

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

Referenced by gin_bool_consistent().

◆ contains_required_value()

static bool contains_required_value ( ITEM curitem)
static

Definition at line 363 of file _int_bool.c.

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

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

Referenced by query_has_required_values().

◆ execconsistent()

bool execconsistent ( QUERYTYPE query,
ArrayType array,
bool  calcnot 
)

Definition at line 308 of file _int_bool.c.

309 {
310  CHKVAL chkval;
311 
312  CHECKARRVALID(array);
313  chkval.arrb = ARRPTR(array);
314  chkval.arre = chkval.arrb + ARRNELEMS(array);
315  return execute(GETQUERY(query) + query->size - 1,
316  (void *) &chkval, NULL, calcnot,
318 }

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

Referenced by g_int_consistent().

◆ execute()

static bool execute ( ITEM curitem,
void *  checkval,
void *  options,
bool  calcnot,
bool(*)(void *checkval, ITEM *item, void *options chkcond 
)
static

Definition at line 265 of file _int_bool.c.

267 {
268  /* since this function recurses, it could be driven to stack overflow */
270 
271  if (curitem->type == VAL)
272  return (*chkcond) (checkval, curitem, options);
273  else if (curitem->val == (int32) '!')
274  {
275  return calcnot ?
276  ((execute(curitem - 1, checkval, options, calcnot, chkcond)) ? false : true)
277  : true;
278  }
279  else if (curitem->val == (int32) '&')
280  {
281  if (execute(curitem + curitem->left, checkval, options, calcnot, chkcond))
282  return execute(curitem - 1, checkval, options, calcnot, chkcond);
283  else
284  return false;
285  }
286  else
287  { /* |-operator */
288  if (execute(curitem + curitem->left, checkval, options, calcnot, chkcond))
289  return true;
290  else
291  return execute(curitem - 1, checkval, options, calcnot, chkcond);
292  }
293 }
return true
Definition: isn.c:126
static char ** options

References check_stack_depth(), options, ITEM::type, and VAL.

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

◆ findoprnd()

static void findoprnd ( ITEM ptr,
int32 pos 
)
static

Definition at line 439 of file _int_bool.c.

440 {
441  /* since this function recurses, it could be driven to stack overflow. */
443 
444 #ifdef BS_DEBUG
445  elog(DEBUG3, (ptr[*pos].type == OPR) ?
446  "%d %c" : "%d %d", *pos, ptr[*pos].val);
447 #endif
448  if (ptr[*pos].type == VAL)
449  {
450  ptr[*pos].left = 0;
451  (*pos)--;
452  }
453  else if (ptr[*pos].val == (int32) '!')
454  {
455  ptr[*pos].left = -1;
456  (*pos)--;
457  findoprnd(ptr, pos);
458  }
459  else
460  {
461  ITEM *curitem = &ptr[*pos];
462  int32 tmp = *pos;
463 
464  (*pos)--;
465  findoprnd(ptr, pos);
466  curitem->left = *pos - tmp;
467  findoprnd(ptr, pos);
468  }
469 }

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

Referenced by bqarr_in().

◆ gettoken()

static int32 gettoken ( WORKSTATE state,
int32 val 
)
static

Definition at line 49 of file _int_bool.c.

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 CLOSE
Definition: _int.h:165
#define OPEN
Definition: _int.h:164
#define END
Definition: _int.h:160
#define WAITENDOPERAND
Definition: _int_bool.c:19
#define WAITOPERATOR
Definition: _int_bool.c:20

References CLOSE, END, ERR, OPEN, OPR, VAL, val, WAITENDOPERAND, WAITOPERAND, and WAITOPERATOR.

Referenced by makepol().

◆ gin_bool_consistent()

bool gin_bool_consistent ( QUERYTYPE query,
bool check 
)

Definition at line 335 of file _int_bool.c.

336 {
337  GinChkVal gcv;
338  ITEM *items = GETQUERY(query);
339  int i,
340  j = 0;
341 
342  if (query->size <= 0)
343  return false;
344 
345  /*
346  * Set up data for checkcondition_gin. This must agree with the query
347  * extraction code in ginint4_queryextract.
348  */
349  gcv.first = items;
350  gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
351  for (i = 0; i < query->size; i++)
352  {
353  if (items[i].type == VAL)
354  gcv.mapped_check[i] = check[j++];
355  }
356 
357  return execute(GETQUERY(query) + query->size - 1,
358  (void *) &gcv, NULL, true,
360 }
static bool checkcondition_gin(void *checkval, ITEM *item, void *options)
Definition: _int_bool.c:327
int j
Definition: isn.c:74
static ItemArray items
Definition: test_tidstore.c:49

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

Referenced by ginint4_consistent().

◆ infix()

static void infix ( INFIX in,
bool  first 
)
static

Definition at line 566 of file _int_bool.c.

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

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

Referenced by bqarr_out().

◆ makepol()

static int32 makepol ( WORKSTATE state)
static

Definition at line 154 of file _int_bool.c.

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  ereturn(state->escontext, ERR,
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  ereturn(state->escontext, ERR,
211  (errcode(ERRCODE_SYNTAX_ERROR),
212  errmsg("syntax error")));
213  }
214  }
215 
216  while (lenstack)
217  {
218  lenstack--;
219  pushquery(state, OPR, stack[lenstack]);
220  };
221  return END;
222 }
static void pushquery(WORKSTATE *state, int32 type, int32 val)
Definition: _int_bool.c:137
static int32 gettoken(WORKSTATE *state, int32 *val)
Definition: _int_bool.c:49
#define STACKDEPTH
Definition: _int_bool.c:148

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

Referenced by bqarr_in().

◆ PG_FUNCTION_INFO_V1() [1/5]

PG_FUNCTION_INFO_V1 ( boolop  )

◆ PG_FUNCTION_INFO_V1() [2/5]

PG_FUNCTION_INFO_V1 ( bqarr_in  )

◆ PG_FUNCTION_INFO_V1() [3/5]

PG_FUNCTION_INFO_V1 ( bqarr_out  )

◆ PG_FUNCTION_INFO_V1() [4/5]

PG_FUNCTION_INFO_V1 ( querytree  )

◆ PG_FUNCTION_INFO_V1() [5/5]

PG_FUNCTION_INFO_V1 ( rboolop  )

◆ pushquery()

static void pushquery ( WORKSTATE state,
int32  type,
int32  val 
)
static

Definition at line 137 of file _int_bool.c.

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 }
struct NODE * next
Definition: _int_bool.c:30
int32 val
Definition: _int_bool.c:29
int32 type
Definition: _int_bool.c:28

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

Referenced by makepol().

◆ query_has_required_values()

bool query_has_required_values ( QUERYTYPE query)

Definition at line 398 of file _int_bool.c.

399 {
400  if (query->size <= 0)
401  return false;
402  return contains_required_value(GETQUERY(query) + query->size - 1);
403 }

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

Referenced by ginint4_queryextract().

◆ querytree()

Datum querytree ( PG_FUNCTION_ARGS  )

Definition at line 666 of file _int_bool.c.

667 {
668  elog(ERROR, "querytree is no longer implemented");
669  PG_RETURN_NULL();
670 }

References elog, ERROR, and PG_RETURN_NULL.

Referenced by inline_function(), inline_set_returning_function(), and pg_plan_query().

◆ rboolop()

Datum rboolop ( PG_FUNCTION_ARGS  )

Definition at line 409 of file _int_bool.c.

410 {
411  /* just reverse the operands */
413  PG_GETARG_DATUM(1),
414  PG_GETARG_DATUM(0));
415 }
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:418
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:644
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268

References boolop(), DirectFunctionCall2, and PG_GETARG_DATUM.

◆ signconsistent()

bool signconsistent ( QUERYTYPE query,
BITVECP  sign,
int  siglen,
bool  calcnot 
)

Definition at line 299 of file _int_bool.c.

300 {
301  return execute(GETQUERY(query) + query->size - 1,
302  (void *) sign, (void *) (intptr_t) siglen, calcnot,
304 }
static bool checkcondition_bit(void *checkval, ITEM *item, void *siglen)
Definition: _int_bool.c:256
char sign
Definition: informix.c:674

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

Referenced by g_intbig_consistent().