PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nodeBitmapOr.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/instrument.h"
#include "executor/nodeBitmapOr.h"
#include "nodes/tidbitmap.h"
#include "miscadmin.h"
Include dependency graph for nodeBitmapOr.c:

Go to the source code of this file.

Functions

static TupleTableSlotExecBitmapOr (PlanState *pstate)
 
BitmapOrStateExecInitBitmapOr (BitmapOr *node, EState *estate, int eflags)
 
NodeMultiExecBitmapOr (BitmapOrState *node)
 
void ExecEndBitmapOr (BitmapOrState *node)
 
void ExecReScanBitmapOr (BitmapOrState *node)
 

Function Documentation

◆ ExecBitmapOr()

static TupleTableSlot * ExecBitmapOr ( PlanState pstate)
static

Definition at line 45 of file nodeBitmapOr.c.

46{
47 elog(ERROR, "BitmapOr node does not support ExecProcNode call convention");
48 return NULL;
49}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
static int fb(int x)

References elog, ERROR, and fb().

Referenced by ExecInitBitmapOr().

◆ ExecEndBitmapOr()

void ExecEndBitmapOr ( BitmapOrState node)

Definition at line 198 of file nodeBitmapOr.c.

199{
200 PlanState **bitmapplans;
201 int nplans;
202 int i;
203
204 /*
205 * get information from the node
206 */
207 bitmapplans = node->bitmapplans;
208 nplans = node->nplans;
209
210 /*
211 * shut down each of the subscans (that we've initialized)
212 */
213 for (i = 0; i < nplans; i++)
214 {
215 if (bitmapplans[i])
216 ExecEndNode(bitmapplans[i]);
217 }
218}
void ExecEndNode(PlanState *node)
int i
Definition isn.c:77
PlanState ** bitmapplans
Definition execnodes.h:1608

References BitmapOrState::bitmapplans, ExecEndNode(), i, and BitmapOrState::nplans.

Referenced by ExecEndNode().

◆ ExecInitBitmapOr()

BitmapOrState * ExecInitBitmapOr ( BitmapOr node,
EState estate,
int  eflags 
)

Definition at line 58 of file nodeBitmapOr.c.

59{
62 int nplans;
63 int i;
64 ListCell *l;
66
67 /* check for unsupported flags */
69
70 /*
71 * Set up empty vector of subplan states
72 */
73 nplans = list_length(node->bitmapplans);
74
75 bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *));
76
77 /*
78 * create new BitmapOrState for our BitmapOr node
79 */
80 bitmaporstate->ps.plan = (Plan *) node;
81 bitmaporstate->ps.state = estate;
82 bitmaporstate->ps.ExecProcNode = ExecBitmapOr;
83 bitmaporstate->bitmapplans = bitmapplanstates;
84 bitmaporstate->nplans = nplans;
85
86 /*
87 * call ExecInitNode on each of the plans to be executed and save the
88 * results into the array "bitmapplanstates".
89 */
90 i = 0;
91 foreach(l, node->bitmapplans)
92 {
93 initNode = (Plan *) lfirst(l);
94 bitmapplanstates[i] = ExecInitNode(initNode, estate, eflags);
95 i++;
96 }
97
98 /*
99 * Miscellaneous initialization
100 *
101 * BitmapOr plans don't have expression contexts because they never call
102 * ExecQual or ExecProject. They don't need any tuple slots either.
103 */
104
105 return bitmaporstate;
106}
#define Assert(condition)
Definition c.h:945
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
#define EXEC_FLAG_BACKWARD
Definition executor.h:70
#define EXEC_FLAG_MARK
Definition executor.h:71
void * palloc0(Size size)
Definition mcxt.c:1417
static TupleTableSlot * ExecBitmapOr(PlanState *pstate)
#define makeNode(_type_)
Definition nodes.h:161
#define lfirst(lc)
Definition pg_list.h:172
static int list_length(const List *l)
Definition pg_list.h:152
List * bitmapplans
Definition plannodes.h:524

References Assert, BitmapOr::bitmapplans, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecBitmapOr(), ExecInitNode(), fb(), i, lfirst, list_length(), makeNode, and palloc0().

Referenced by ExecInitNode().

◆ ExecReScanBitmapOr()

void ExecReScanBitmapOr ( BitmapOrState node)

Definition at line 221 of file nodeBitmapOr.c.

222{
223 int i;
224
225 for (i = 0; i < node->nplans; i++)
226 {
227 PlanState *subnode = node->bitmapplans[i];
228
229 /*
230 * ExecReScan doesn't know about my subplans, so I have to do
231 * changed-parameter signaling myself.
232 */
233 if (node->ps.chgParam != NULL)
235
236 /*
237 * If chgParam of subnode is not null then plan will be re-scanned by
238 * first ExecProcNode.
239 */
240 if (subnode->chgParam == NULL)
242 }
243}
void ExecReScan(PlanState *node)
Definition execAmi.c:78
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition execUtils.c:915
PlanState ps
Definition execnodes.h:1607
Bitmapset * chgParam
Definition execnodes.h:1209

References BitmapOrState::bitmapplans, PlanState::chgParam, ExecReScan(), fb(), i, BitmapOrState::nplans, BitmapOrState::ps, and UpdateChangedParamSet().

Referenced by ExecReScan().

◆ MultiExecBitmapOr()

Node * MultiExecBitmapOr ( BitmapOrState node)

Definition at line 113 of file nodeBitmapOr.c.

114{
115 PlanState **bitmapplans;
116 int nplans;
117 int i;
118 TIDBitmap *result = NULL;
119
120 /* must provide our own instrumentation support */
121 if (node->ps.instrument)
123
124 /*
125 * get information from the node
126 */
127 bitmapplans = node->bitmapplans;
128 nplans = node->nplans;
129
130 /*
131 * Scan all the subplans and OR their result bitmaps
132 */
133 for (i = 0; i < nplans; i++)
134 {
135 PlanState *subnode = bitmapplans[i];
137
138 /*
139 * We can special-case BitmapIndexScan children to avoid an explicit
140 * tbm_union step for each child: just pass down the current result
141 * bitmap and let the child OR directly into it.
142 */
144 {
145 if (result == NULL) /* first subplan */
146 {
147 /* XXX should we use less than work_mem for this? */
148 result = tbm_create(work_mem * (Size) 1024,
149 ((BitmapOr *) node->ps.plan)->isshared ?
150 node->ps.state->es_query_dsa : NULL);
151 }
152
153 ((BitmapIndexScanState *) subnode)->biss_result = result;
154
156
157 if (subresult != result)
158 elog(ERROR, "unrecognized result from subplan");
159 }
160 else
161 {
162 /* standard implementation */
164
165 if (!subresult || !IsA(subresult, TIDBitmap))
166 elog(ERROR, "unrecognized result from subplan");
167
168 if (result == NULL)
169 result = subresult; /* first subplan */
170 else
171 {
172 tbm_union(result, subresult);
174 }
175 }
176 }
177
178 /* We could return an empty result set here? */
179 if (result == NULL)
180 elog(ERROR, "BitmapOr doesn't support zero inputs");
181
182 /* must provide our own instrumentation support */
183 if (node->ps.instrument)
184 InstrStopNode(node->ps.instrument, 0 /* XXX */ );
185
186 return (Node *) result;
187}
size_t Size
Definition c.h:691
Node * MultiExecProcNode(PlanState *node)
int work_mem
Definition globals.c:131
void InstrStartNode(Instrumentation *instr)
Definition instrument.c:68
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition instrument.c:88
#define IsA(nodeptr, _type_)
Definition nodes.h:164
struct dsa_area * es_query_dsa
Definition execnodes.h:764
Definition nodes.h:135
Instrumentation * instrument
Definition execnodes.h:1187
Plan * plan
Definition execnodes.h:1177
EState * state
Definition execnodes.h:1179
void tbm_free(TIDBitmap *tbm)
Definition tidbitmap.c:312
void tbm_union(TIDBitmap *a, const TIDBitmap *b)
Definition tidbitmap.c:447
TIDBitmap * tbm_create(Size maxbytes, dsa_area *dsa)
Definition tidbitmap.c:256

References BitmapOrState::bitmapplans, elog, ERROR, EState::es_query_dsa, fb(), i, InstrStartNode(), InstrStopNode(), PlanState::instrument, IsA, MultiExecProcNode(), BitmapOrState::nplans, PlanState::plan, BitmapOrState::ps, PlanState::state, tbm_create(), tbm_free(), tbm_union(), and work_mem.

Referenced by MultiExecProcNode().