PostgreSQL Source Code git master
Loading...
Searching...
No Matches
_int_bool.c File Reference
#include "postgres.h"
#include "_int.h"
#include "miscadmin.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 bool findoprnd (WORKSTATE *state, 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; \
}
int32_t int32
Definition c.h:620
struct cursor * cur
Definition ecpg.c:29
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1635
const void size_t len
static char buf[DEFAULT_XLOG_SEG_SIZE]
static int fb(int x)

Definition at line 603 of file _int_bool.c.

603 { \
604 int32 len = inf->cur - inf->buf; \
605 inf->buflen *= 2; \
606 inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
607 inf->cur = inf->buf + len; \
608}

◆ STACKDEPTH

#define STACKDEPTH   16

Definition at line 147 of file _int_bool.c.

◆ WAITENDOPERAND

#define WAITENDOPERAND   2

Definition at line 18 of file _int_bool.c.

◆ WAITOPERAND

#define WAITOPERAND   1

Definition at line 17 of file _int_bool.c.

◆ WAITOPERATOR

#define WAITOPERATOR   3

Definition at line 19 of file _int_bool.c.

Typedef Documentation

◆ NODE

typedef struct NODE NODE

Function Documentation

◆ boolop()

Datum boolop ( PG_FUNCTION_ARGS  )

Definition at line 417 of file _int_bool.c.

418{
422 bool result;
423
426 chkval.arrb = ARRPTR(val);
427 chkval.arre = chkval.arrb + ARRNELEMS(val);
428 result = execute(GETQUERY(query) + query->size - 1,
429 &chkval, NULL, true,
431 pfree(val);
432
433 PG_FREE_IF_COPY(query, 1);
435}
#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:233
static bool execute(ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
Definition _int_bool.c:264
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition array.h:264
uint32 result
#define ARRNELEMS(x)
Definition cube.c:29
#define ARRPTR(x)
Definition cube.c:28
#define PG_FREE_IF_COPY(ptr, n)
Definition fmgr.h:260
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
long val
Definition informix.c:689
void pfree(void *pointer)
Definition mcxt.c:1619
int32 size
Definition _int.h:150

References ARRNELEMS, ARRPTR, CHECKARRVALID, checkcondition_arr(), execute(), fb(), 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 is_andclause(), is_notclause(), is_orclause(), makeBoolExpr(), and rboolop().

◆ bqarr_in()

Datum bqarr_in ( PG_FUNCTION_ARGS  )

Definition at line 515 of file _int_bool.c.

516{
517 char *buf = (char *) PG_GETARG_POINTER(0);
519 int32 i;
520 QUERYTYPE *query;
522 ITEM *ptr;
523 NODE *tmp;
524 int32 pos = 0;
525 struct Node *escontext = fcinfo->context;
526
527#ifdef BS_DEBUG
529#endif
530
531 state.buf = buf;
532 state.state = WAITOPERAND;
533 state.count = 0;
534 state.num = 0;
535 state.str = NULL;
536 state.escontext = escontext;
537
538 /* make polish notation (postfix, but in reverse order) */
539 if (makepol(&state) == ERR)
541 if (!state.num)
542 ereturn(escontext, (Datum) 0,
544 errmsg("empty query")));
545
546 if (state.num > QUERYTYPEMAXITEMS)
547 ereturn(escontext, (Datum) 0,
549 errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
550 state.num, (int) QUERYTYPEMAXITEMS)));
552
553 query = (QUERYTYPE *) palloc(commonlen);
554 SET_VARSIZE(query, commonlen);
555 query->size = state.num;
556 ptr = GETQUERY(query);
557
558 /* fill the query array from the data makepol constructed */
559 for (i = state.num - 1; i >= 0; i--)
560 {
561 ptr[i].type = state.str->type;
562 ptr[i].val = state.str->val;
563 tmp = state.str->next;
564 pfree(state.str);
565 state.str = tmp;
566 }
567
568 /* now fill the "left" fields */
569 pos = query->size - 1;
570 if (!findoprnd(&state, ptr, &pos))
572 /* if successful, findoprnd should have scanned the whole array */
573 Assert(pos == -1);
574
575#ifdef BS_DEBUG
577 for (i = 0; i < query->size; i++)
578 {
579 if (ptr[i].type == OPR)
580 appendStringInfo(&pbuf, "%c(%d) ", ptr[i].val, ptr[i].left);
581 else
582 appendStringInfo(&pbuf, "%d ", ptr[i].val);
583 }
584 elog(DEBUG3, "POR: %s", pbuf.data);
585 pfree(pbuf.data);
586#endif
587
588 PG_RETURN_POINTER(query);
589}
#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 int32 makepol(WORKSTATE *state)
Definition _int_bool.c:153
#define WAITOPERAND
Definition _int_bool.c:17
static bool findoprnd(WORKSTATE *state, ITEM *ptr, int32 *pos)
Definition _int_bool.c:452
#define Assert(condition)
Definition c.h:943
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereturn(context, dummy_value,...)
Definition elog.h:280
#define DEBUG3
Definition elog.h:29
#define elog(elevel,...)
Definition elog.h:228
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
int i
Definition isn.c:77
void * palloc(Size size)
Definition mcxt.c:1390
static char * errmsg
uint64_t Datum
Definition postgres.h:70
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
Definition _int.h:141
int32 val
Definition _int.h:144
int16 type
Definition _int.h:142
Definition nodes.h:135
struct state * next
Definition regguts.h:340
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432
const char * type

References appendStringInfo(), Assert, buf, COMPUTESIZE, DEBUG3, elog, ereturn, ERR, errcode(), errmsg, fb(), 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 688 of file _int_bool.c.

689{
691 INFIX nrm;
692
693 if (query->size == 0)
696 errmsg("empty query")));
697
698 nrm.curpol = GETQUERY(query) + query->size - 1;
699 nrm.buflen = 32;
700 nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
701 *(nrm.cur) = '\0';
702 infix(&nrm, true);
703
704 PG_FREE_IF_COPY(query, 0);
706}
static void infix(INFIX *in, bool first)
Definition _int_bool.c:611
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
#define palloc_array(type, count)
Definition fe_memutils.h:91

References ereport, errcode(), errmsg, ERROR, fb(), GETQUERY, infix(), palloc_array, 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 233 of file _int_bool.c.

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

References CHKVAL::arrb, fb(), 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 255 of file _int_bool.c.

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

References fb(), GETBIT, HASHVAL, and ITEM::val.

Referenced by signconsistent().

◆ checkcondition_gin()

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

Definition at line 326 of file _int_bool.c.

327{
329
330 return gcv->mapped_check[item - gcv->first];
331}
bool * mapped_check
Definition _int_bool.c:322

References fb(), and GinChkVal::mapped_check.

Referenced by gin_bool_consistent().

◆ contains_required_value()

static bool contains_required_value ( ITEM curitem)
static

Definition at line 362 of file _int_bool.c.

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

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

Referenced by contains_required_value(), and query_has_required_values().

◆ execconsistent()

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

Definition at line 307 of file _int_bool.c.

308{
310
311 CHECKARRVALID(array);
312 chkval.arrb = ARRPTR(array);
313 chkval.arre = chkval.arrb + ARRNELEMS(array);
314 return execute(GETQUERY(query) + query->size - 1,
317}

References ARRNELEMS, ARRPTR, CHECKARRVALID, checkcondition_arr(), execute(), fb(), 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 264 of file _int_bool.c.

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

References check_stack_depth(), execute(), fb(), ITEM::type, and VAL.

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

◆ findoprnd()

static bool findoprnd ( WORKSTATE state,
ITEM ptr,
int32 pos 
)
static

Definition at line 452 of file _int_bool.c.

453{
454 int32 mypos;
455
456 /* since this function recurses, it could be driven to stack overflow. */
458
459 /* get the position this call is supposed to update */
460 mypos = *pos;
461 Assert(mypos >= 0);
462
463 /* in all cases, we should decrement *pos to advance over this item */
464 (*pos)--;
465
466#ifdef BS_DEBUG
467 elog(DEBUG3, (ptr[mypos].type == OPR) ?
468 "%d %c" : "%d %d", mypos, ptr[mypos].val);
469#endif
470
471 if (ptr[mypos].type == VAL)
472 {
473 /* base case: a VAL has no operand, so just set its left to zero */
474 ptr[mypos].left = 0;
475 }
476 else if (ptr[mypos].val == (int32) '!')
477 {
478 /* unary operator, likewise easy: operand is just before it */
479 ptr[mypos].left = -1;
480 /* recurse to scan operand */
481 if (!findoprnd(state, ptr, pos))
482 return false;
483 }
484 else
485 {
486 /* binary operator */
487 int32 delta;
488
489 /* recurse to scan right operand */
490 if (!findoprnd(state, ptr, pos))
491 return false;
492 /* we must fill left with offset to left operand's top */
493 /* abs(delta) < QUERYTYPEMAXITEMS, so it can't overflow ... */
494 delta = *pos - mypos;
495 /* ... but it might be too large to fit in the 16-bit left field */
496 Assert(delta < 0);
497 if (unlikely(delta < PG_INT16_MIN))
498 ereturn(state->escontext, false,
500 errmsg("query_int expression is too complex")));
501 ptr[mypos].left = (int16) delta;
502 /* recurse to scan left operand */
503 if (!findoprnd(state, ptr, pos))
504 return false;
505 }
506
507 return true;
508}
int16_t int16
Definition c.h:619
#define PG_INT16_MIN
Definition c.h:669
#define unlikely(x)
Definition c.h:438

References Assert, check_stack_depth(), DEBUG3, elog, ereturn, errcode(), errmsg, fb(), findoprnd(), ITEM::left, OPR, PG_INT16_MIN, type, unlikely, ITEM::val, VAL, and val.

Referenced by bqarr_in(), and findoprnd().

◆ gettoken()

static int32 gettoken ( WORKSTATE state,
int32 val 
)
static

Definition at line 48 of file _int_bool.c.

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

References CLOSE, END, ERR, fb(), 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 334 of file _int_bool.c.

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

References checkcondition_gin(), execute(), fb(), GETQUERY, i, items, j, palloc_array, QUERYTYPE::size, type, and VAL.

Referenced by ginint4_consistent().

◆ infix()

static void infix ( INFIX in,
bool  first 
)
static

Definition at line 611 of file _int_bool.c.

612{
613 /* since this function recurses, it could be driven to stack overflow. */
615
616 if (in->curpol->type == VAL)
617 {
618 RESIZEBUF(in, 11);
619 sprintf(in->cur, "%d", in->curpol->val);
620 in->cur = strchr(in->cur, '\0');
621 in->curpol--;
622 }
623 else if (in->curpol->val == (int32) '!')
624 {
625 bool isopr = false;
626
627 RESIZEBUF(in, 1);
628 *(in->cur) = '!';
629 in->cur++;
630 *(in->cur) = '\0';
631 in->curpol--;
632 if (in->curpol->type == OPR)
633 {
634 isopr = true;
635 RESIZEBUF(in, 2);
636 sprintf(in->cur, "( ");
637 in->cur = strchr(in->cur, '\0');
638 }
639 infix(in, isopr);
640 if (isopr)
641 {
642 RESIZEBUF(in, 2);
643 sprintf(in->cur, " )");
644 in->cur = strchr(in->cur, '\0');
645 }
646 }
647 else
648 {
649 int32 op = in->curpol->val;
650 INFIX nrm;
651
652 in->curpol--;
653 if (op == (int32) '|' && !first)
654 {
655 RESIZEBUF(in, 2);
656 sprintf(in->cur, "( ");
657 in->cur = strchr(in->cur, '\0');
658 }
659
660 nrm.curpol = in->curpol;
661 nrm.buflen = 16;
662 nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
663
664 /* get right operand */
665 infix(&nrm, false);
666
667 /* get & print left operand */
668 in->curpol = nrm.curpol;
669 infix(in, false);
670
671 /* print operator & right operand */
672 RESIZEBUF(in, 3 + (nrm.cur - nrm.buf));
673 sprintf(in->cur, " %c %s", op, nrm.buf);
674 in->cur = strchr(in->cur, '\0');
675 pfree(nrm.buf);
676
677 if (op == (int32) '|' && !first)
678 {
679 RESIZEBUF(in, 2);
680 sprintf(in->cur, " )");
681 in->cur = strchr(in->cur, '\0');
682 }
683 }
684}
#define RESIZEBUF(inf, addsize)
Definition _int_bool.c:603
#define sprintf
Definition port.h:263
char * cur
Definition _int_bool.c:599
ITEM * curpol
Definition _int_bool.c:597

References check_stack_depth(), INFIX::cur, INFIX::curpol, fb(), infix(), OPR, palloc_array, pfree(), RESIZEBUF, sprintf, ITEM::type, ITEM::val, and VAL.

Referenced by bqarr_out(), and infix().

◆ makepol()

static int32 makepol ( WORKSTATE state)
static

Definition at line 153 of file _int_bool.c.

154{
155 int32 val,
156 type;
157 int32 stack[STACKDEPTH];
158 int32 lenstack = 0;
159
160 /* since this function recurses, it could be driven to stack overflow */
162
163 while ((type = gettoken(state, &val)) != END)
164 {
165 switch (type)
166 {
167 case VAL:
169 while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
170 stack[lenstack - 1] == (int32) '!'))
171 {
172 lenstack--;
173 pushquery(state, OPR, stack[lenstack]);
174 }
175 break;
176 case OPR:
177 if (lenstack && val == (int32) '|')
179 else
180 {
181 if (lenstack == STACKDEPTH)
182 ereturn(state->escontext, ERR,
184 errmsg("statement too complex")));
185 stack[lenstack] = val;
186 lenstack++;
187 }
188 break;
189 case OPEN:
190 if (makepol(state) == ERR)
191 return ERR;
192 while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
193 stack[lenstack - 1] == (int32) '!'))
194 {
195 lenstack--;
196 pushquery(state, OPR, stack[lenstack]);
197 }
198 break;
199 case CLOSE:
200 while (lenstack)
201 {
202 lenstack--;
203 pushquery(state, OPR, stack[lenstack]);
204 };
205 return END;
206 break;
207 case ERR:
208 default:
209 ereturn(state->escontext, ERR,
211 errmsg("syntax error")));
212 }
213 }
214
215 while (lenstack)
216 {
217 lenstack--;
218 pushquery(state, OPR, stack[lenstack]);
219 };
220 return END;
221}
static void pushquery(WORKSTATE *state, int32 type, int32 val)
Definition _int_bool.c:136
static int32 gettoken(WORKSTATE *state, int32 *val)
Definition _int_bool.c:48
#define STACKDEPTH
Definition _int_bool.c:147

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

Referenced by bqarr_in(), and makepol().

◆ 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 136 of file _int_bool.c.

137{
138 NODE *tmp = palloc_object(NODE);
139
140 tmp->type = type;
141 tmp->val = val;
142 tmp->next = state->str;
143 state->str = tmp;
144 state->num++;
145}
#define palloc_object(type)
Definition fe_memutils.h:89
struct NODE * next
Definition _int_bool.c:29
int32 val
Definition _int_bool.c:28
int32 type
Definition _int_bool.c:27

References NODE::next, palloc_object, NODE::type, type, NODE::val, and val.

Referenced by makepol().

◆ query_has_required_values()

bool query_has_required_values ( QUERYTYPE query)

Definition at line 397 of file _int_bool.c.

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

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

Referenced by ginint4_queryextract().

◆ querytree()

Datum querytree ( PG_FUNCTION_ARGS  )

Definition at line 711 of file _int_bool.c.

712{
713 elog(ERROR, "querytree is no longer implemented");
715}

References elog, ERROR, and PG_RETURN_NULL.

Referenced by inline_function(), inline_function_in_from(), inline_sql_function_in_from(), pg_plan_query(), and test_inline_in_from_support_func().

◆ rboolop()

Datum rboolop ( PG_FUNCTION_ARGS  )

Definition at line 408 of file _int_bool.c.

409{
410 /* just reverse the operands */
413 PG_GETARG_DATUM(0));
414}
Datum boolop(PG_FUNCTION_ARGS)
Definition _int_bool.c:417
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:690
#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 298 of file _int_bool.c.

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

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

Referenced by g_intbig_consistent().