PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeBitmapAnd.c File Reference
#include "postgres.h"
#include "executor/execdebug.h"
#include "executor/nodeBitmapAnd.h"
Include dependency graph for nodeBitmapAnd.c:

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 164 of file nodeBitmapAnd.c.

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

Referenced by ExecEndNode().

165 {
166  PlanState **bitmapplans;
167  int nplans;
168  int i;
169 
170  /*
171  * get information from the node
172  */
173  bitmapplans = node->bitmapplans;
174  nplans = node->nplans;
175 
176  /*
177  * shut down each of the subscans (that we've initialized)
178  */
179  for (i = 0; i < nplans; i++)
180  {
181  if (bitmapplans[i])
182  ExecEndNode(bitmapplans[i]);
183  }
184 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:654
PlanState ** bitmapplans
Definition: execnodes.h:1011
int i
BitmapAndState* ExecInitBitmapAnd ( BitmapAnd node,
EState estate,
int  eflags 
)

Definition at line 42 of file nodeBitmapAnd.c.

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

Referenced by ExecInitNode().

43 {
44  BitmapAndState *bitmapandstate = makeNode(BitmapAndState);
45  PlanState **bitmapplanstates;
46  int nplans;
47  int i;
48  ListCell *l;
49  Plan *initNode;
50 
51  /* check for unsupported flags */
52  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
53 
54  /*
55  * Set up empty vector of subplan states
56  */
57  nplans = list_length(node->bitmapplans);
58 
59  bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *));
60 
61  /*
62  * create new BitmapAndState for our BitmapAnd node
63  */
64  bitmapandstate->ps.plan = (Plan *) node;
65  bitmapandstate->ps.state = estate;
66  bitmapandstate->bitmapplans = bitmapplanstates;
67  bitmapandstate->nplans = nplans;
68 
69  /*
70  * Miscellaneous initialization
71  *
72  * BitmapAnd plans don't have expression contexts because they never call
73  * ExecQual or ExecProject. They don't need any tuple slots either.
74  */
75 
76  /*
77  * call ExecInitNode on each of the plans to be executed and save the
78  * results into the array "bitmapplanstates".
79  */
80  i = 0;
81  foreach(l, node->bitmapplans)
82  {
83  initNode = (Plan *) lfirst(l);
84  bitmapplanstates[i] = ExecInitNode(initNode, estate, eflags);
85  i++;
86  }
87 
88  return bitmapandstate;
89 }
List * bitmapplans
Definition: plannodes.h:292
PlanState ** bitmapplans
Definition: execnodes.h:1011
EState * state
Definition: execnodes.h:805
PlanState ps
Definition: execnodes.h:1010
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
void * palloc0(Size size)
Definition: mcxt.c:878
Plan * plan
Definition: execnodes.h:803
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:675
#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
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:140
void ExecReScanBitmapAnd ( BitmapAndState node)

Definition at line 187 of file nodeBitmapAnd.c.

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

Referenced by ExecReScan().

188 {
189  int i;
190 
191  for (i = 0; i < node->nplans; i++)
192  {
193  PlanState *subnode = node->bitmapplans[i];
194 
195  /*
196  * ExecReScan doesn't know about my subplans, so I have to do
197  * changed-parameter signaling myself.
198  */
199  if (node->ps.chgParam != NULL)
200  UpdateChangedParamSet(subnode, node->ps.chgParam);
201 
202  /*
203  * If chgParam of subnode is not null then plan will be re-scanned by
204  * first ExecProcNode.
205  */
206  if (subnode->chgParam == NULL)
207  ExecReScan(subnode);
208  }
209 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
PlanState ** bitmapplans
Definition: execnodes.h:1011
PlanState ps
Definition: execnodes.h:1010
Bitmapset * chgParam
Definition: execnodes.h:827
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:671
#define NULL
Definition: c.h:229
int i
Node* MultiExecBitmapAnd ( BitmapAndState node)

Definition at line 96 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().

97 {
98  PlanState **bitmapplans;
99  int nplans;
100  int i;
101  TIDBitmap *result = NULL;
102 
103  /* must provide our own instrumentation support */
104  if (node->ps.instrument)
106 
107  /*
108  * get information from the node
109  */
110  bitmapplans = node->bitmapplans;
111  nplans = node->nplans;
112 
113  /*
114  * Scan all the subplans and AND their result bitmaps
115  */
116  for (i = 0; i < nplans; i++)
117  {
118  PlanState *subnode = bitmapplans[i];
119  TIDBitmap *subresult;
120 
121  subresult = (TIDBitmap *) MultiExecProcNode(subnode);
122 
123  if (!subresult || !IsA(subresult, TIDBitmap))
124  elog(ERROR, "unrecognized result from subplan");
125 
126  if (result == NULL)
127  result = subresult; /* first subplan */
128  else
129  {
130  tbm_intersect(result, subresult);
131  tbm_free(subresult);
132  }
133 
134  /*
135  * If at any stage we have a completely empty bitmap, we can fall out
136  * without evaluating the remaining subplans, since ANDing them can no
137  * longer change the result. (Note: the fact that indxpath.c orders
138  * the subplans by selectivity should make this case more likely to
139  * occur.)
140  */
141  if (tbm_is_empty(result))
142  break;
143  }
144 
145  if (result == NULL)
146  elog(ERROR, "BitmapAnd doesn't support zero inputs");
147 
148  /* must provide our own instrumentation support */
149  if (node->ps.instrument)
150  InstrStopNode(node->ps.instrument, 0 /* XXX */ );
151 
152  return (Node *) result;
153 }
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:809
Definition: nodes.h:509
return result
Definition: formatting.c:1618
PlanState ** bitmapplans
Definition: execnodes.h:1011
PlanState ps
Definition: execnodes.h:1010
#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:601
int i
#define elog
Definition: elog.h:219