PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nodeBitmapOr.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeBitmapOr.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 43 of file nodeBitmapOr.c.

44{
45 elog(ERROR, "BitmapOr node does not support ExecProcNode call convention");
46 return NULL;
47}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225

References elog, and ERROR.

Referenced by ExecInitBitmapOr().

◆ ExecEndBitmapOr()

void ExecEndBitmapOr ( BitmapOrState node)

Definition at line 196 of file nodeBitmapOr.c.

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

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

Referenced by ExecEndNode().

◆ ExecInitBitmapOr()

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

Definition at line 56 of file nodeBitmapOr.c.

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

References Assert, BitmapOrState::bitmapplans, BitmapOr::bitmapplans, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecBitmapOr(), ExecInitNode(), PlanState::ExecProcNode, i, lfirst, list_length(), makeNode, BitmapOrState::nplans, palloc0(), PlanState::plan, BitmapOrState::ps, and PlanState::state.

Referenced by ExecInitNode().

◆ ExecReScanBitmapOr()

void ExecReScanBitmapOr ( BitmapOrState node)

Definition at line 219 of file nodeBitmapOr.c.

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

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

Referenced by ExecReScan().

◆ MultiExecBitmapOr()

Node * MultiExecBitmapOr ( BitmapOrState node)

Definition at line 111 of file nodeBitmapOr.c.

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

References BitmapOrState::bitmapplans, elog, ERROR, EState::es_query_dsa, 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().