PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeBitmapAnd.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeBitmapAnd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BitmapAndStateExecInitBitmapAnd (BitmapAnd *node, EState *estate, int eflags)
 
NodeMultiExecBitmapAnd (BitmapAndState *node)
 
void ExecEndBitmapAnd (BitmapAndState *node)
 
void ExecReScanBitmapAnd (BitmapAndState *node)
 

Function Documentation

void ExecEndBitmapAnd ( BitmapAndState node)

Definition at line 178 of file nodeBitmapAnd.c.

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

Referenced by ExecEndNode().

179 {
180  PlanState **bitmapplans;
181  int nplans;
182  int i;
183 
184  /*
185  * get information from the node
186  */
187  bitmapplans = node->bitmapplans;
188  nplans = node->nplans;
189 
190  /*
191  * shut down each of the subscans (that we've initialized)
192  */
193  for (i = 0; i < nplans; i++)
194  {
195  if (bitmapplans[i])
196  ExecEndNode(bitmapplans[i]);
197  }
198 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
PlanState ** bitmapplans
Definition: execnodes.h:1062
int i
BitmapAndState* ExecInitBitmapAnd ( BitmapAnd node,
EState estate,
int  eflags 
)

Definition at line 55 of file nodeBitmapAnd.c.

References Assert, BitmapAnd::bitmapplans, BitmapAndState::bitmapplans, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecBitmapAnd(), ExecInitNode(), PlanState::ExecProcNode, i, lfirst, list_length(), makeNode, BitmapAndState::nplans, palloc0(), PlanState::plan, BitmapAndState::ps, and PlanState::state.

Referenced by ExecInitNode().

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

Definition at line 201 of file nodeBitmapAnd.c.

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

Referenced by ExecReScan().

202 {
203  int i;
204 
205  for (i = 0; i < node->nplans; i++)
206  {
207  PlanState *subnode = node->bitmapplans[i];
208 
209  /*
210  * ExecReScan doesn't know about my subplans, so I have to do
211  * changed-parameter signaling myself.
212  */
213  if (node->ps.chgParam != NULL)
214  UpdateChangedParamSet(subnode, node->ps.chgParam);
215 
216  /*
217  * If chgParam of subnode is not null then plan will be re-scanned by
218  * first ExecProcNode.
219  */
220  if (subnode->chgParam == NULL)
221  ExecReScan(subnode);
222  }
223 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
PlanState ** bitmapplans
Definition: execnodes.h:1062
PlanState ps
Definition: execnodes.h:1061
Bitmapset * chgParam
Definition: execnodes.h:875
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:676
#define NULL
Definition: c.h:229
int i
Node* MultiExecBitmapAnd ( BitmapAndState node)

Definition at line 110 of file nodeBitmapAnd.c.

References BitmapAndState::bitmapplans, elog, ERROR, i, InstrStartNode(), InstrStopNode(), PlanState::instrument, IsA, MultiExecProcNode(), BitmapAndState::nplans, NULL, BitmapAndState::ps, result, tbm_free(), tbm_intersect(), and tbm_is_empty().

Referenced by MultiExecProcNode().

111 {
112  PlanState **bitmapplans;
113  int nplans;
114  int i;
115  TIDBitmap *result = NULL;
116 
117  /* must provide our own instrumentation support */
118  if (node->ps.instrument)
120 
121  /*
122  * get information from the node
123  */
124  bitmapplans = node->bitmapplans;
125  nplans = node->nplans;
126 
127  /*
128  * Scan all the subplans and AND their result bitmaps
129  */
130  for (i = 0; i < nplans; i++)
131  {
132  PlanState *subnode = bitmapplans[i];
133  TIDBitmap *subresult;
134 
135  subresult = (TIDBitmap *) MultiExecProcNode(subnode);
136 
137  if (!subresult || !IsA(subresult, TIDBitmap))
138  elog(ERROR, "unrecognized result from subplan");
139 
140  if (result == NULL)
141  result = subresult; /* first subplan */
142  else
143  {
144  tbm_intersect(result, subresult);
145  tbm_free(subresult);
146  }
147 
148  /*
149  * If at any stage we have a completely empty bitmap, we can fall out
150  * without evaluating the remaining subplans, since ANDing them can no
151  * longer change the result. (Note: the fact that indxpath.c orders
152  * the subplans by selectivity should make this case more likely to
153  * occur.)
154  */
155  if (tbm_is_empty(result))
156  break;
157  }
158 
159  if (result == NULL)
160  elog(ERROR, "BitmapAnd doesn't support zero inputs");
161 
162  /* must provide our own instrumentation support */
163  if (node->ps.instrument)
164  InstrStopNode(node->ps.instrument, 0 /* XXX */ );
165 
166  return (Node *) result;
167 }
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition: instrument.c:80
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
void tbm_intersect(TIDBitmap *a, const TIDBitmap *b)
Definition: tidbitmap.c:566
Instrumentation * instrument
Definition: execnodes.h:857
Definition: nodes.h:509
return result
Definition: formatting.c:1633
PlanState ** bitmapplans
Definition: execnodes.h:1062
PlanState ps
Definition: execnodes.h:1061
#define ERROR
Definition: elog.h:43
void InstrStartNode(Instrumentation *instr)
Definition: instrument.c:63
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:348
bool tbm_is_empty(const TIDBitmap *tbm)
Definition: tidbitmap.c:696
#define NULL
Definition: c.h:229
Node * MultiExecProcNode(PlanState *node)
Definition: execProcnode.c:468
int i
#define elog
Definition: elog.h:219