Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "postgres.h"
00030
00031 #include "executor/execdebug.h"
00032 #include "executor/nodeBitmapOr.h"
00033 #include "miscadmin.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042 BitmapOrState *
00043 ExecInitBitmapOr(BitmapOr *node, EState *estate, int eflags)
00044 {
00045 BitmapOrState *bitmaporstate = makeNode(BitmapOrState);
00046 PlanState **bitmapplanstates;
00047 int nplans;
00048 int i;
00049 ListCell *l;
00050 Plan *initNode;
00051
00052
00053 Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
00054
00055
00056
00057
00058 nplans = list_length(node->bitmapplans);
00059
00060 bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *));
00061
00062
00063
00064
00065 bitmaporstate->ps.plan = (Plan *) node;
00066 bitmaporstate->ps.state = estate;
00067 bitmaporstate->bitmapplans = bitmapplanstates;
00068 bitmaporstate->nplans = nplans;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 i = 0;
00082 foreach(l, node->bitmapplans)
00083 {
00084 initNode = (Plan *) lfirst(l);
00085 bitmapplanstates[i] = ExecInitNode(initNode, estate, eflags);
00086 i++;
00087 }
00088
00089 return bitmaporstate;
00090 }
00091
00092
00093
00094
00095
00096 Node *
00097 MultiExecBitmapOr(BitmapOrState *node)
00098 {
00099 PlanState **bitmapplans;
00100 int nplans;
00101 int i;
00102 TIDBitmap *result = NULL;
00103
00104
00105 if (node->ps.instrument)
00106 InstrStartNode(node->ps.instrument);
00107
00108
00109
00110
00111 bitmapplans = node->bitmapplans;
00112 nplans = node->nplans;
00113
00114
00115
00116
00117 for (i = 0; i < nplans; i++)
00118 {
00119 PlanState *subnode = bitmapplans[i];
00120 TIDBitmap *subresult;
00121
00122
00123
00124
00125
00126
00127 if (IsA(subnode, BitmapIndexScanState))
00128 {
00129 if (result == NULL)
00130 {
00131
00132 result = tbm_create(work_mem * 1024L);
00133 }
00134
00135 ((BitmapIndexScanState *) subnode)->biss_result = result;
00136
00137 subresult = (TIDBitmap *) MultiExecProcNode(subnode);
00138
00139 if (subresult != result)
00140 elog(ERROR, "unrecognized result from subplan");
00141 }
00142 else
00143 {
00144
00145 subresult = (TIDBitmap *) MultiExecProcNode(subnode);
00146
00147 if (!subresult || !IsA(subresult, TIDBitmap))
00148 elog(ERROR, "unrecognized result from subplan");
00149
00150 if (result == NULL)
00151 result = subresult;
00152 else
00153 {
00154 tbm_union(result, subresult);
00155 tbm_free(subresult);
00156 }
00157 }
00158 }
00159
00160
00161 if (result == NULL)
00162 elog(ERROR, "BitmapOr doesn't support zero inputs");
00163
00164
00165 if (node->ps.instrument)
00166 InstrStopNode(node->ps.instrument, 0 );
00167
00168 return (Node *) result;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 void
00180 ExecEndBitmapOr(BitmapOrState *node)
00181 {
00182 PlanState **bitmapplans;
00183 int nplans;
00184 int i;
00185
00186
00187
00188
00189 bitmapplans = node->bitmapplans;
00190 nplans = node->nplans;
00191
00192
00193
00194
00195 for (i = 0; i < nplans; i++)
00196 {
00197 if (bitmapplans[i])
00198 ExecEndNode(bitmapplans[i]);
00199 }
00200 }
00201
00202 void
00203 ExecReScanBitmapOr(BitmapOrState *node)
00204 {
00205 int i;
00206
00207 for (i = 0; i < node->nplans; i++)
00208 {
00209 PlanState *subnode = node->bitmapplans[i];
00210
00211
00212
00213
00214
00215 if (node->ps.chgParam != NULL)
00216 UpdateChangedParamSet(subnode, node->ps.chgParam);
00217
00218
00219
00220
00221
00222 if (subnode->chgParam == NULL)
00223 ExecReScan(subnode);
00224 }
00225 }