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/nodeBitmapAnd.h"
00033
00034
00035
00036
00037
00038
00039
00040
00041 BitmapAndState *
00042 ExecInitBitmapAnd(BitmapAnd *node, EState *estate, int eflags)
00043 {
00044 BitmapAndState *bitmapandstate = makeNode(BitmapAndState);
00045 PlanState **bitmapplanstates;
00046 int nplans;
00047 int i;
00048 ListCell *l;
00049 Plan *initNode;
00050
00051
00052 Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
00053
00054
00055
00056
00057 nplans = list_length(node->bitmapplans);
00058
00059 bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *));
00060
00061
00062
00063
00064 bitmapandstate->ps.plan = (Plan *) node;
00065 bitmapandstate->ps.state = estate;
00066 bitmapandstate->bitmapplans = bitmapplanstates;
00067 bitmapandstate->nplans = nplans;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 i = 0;
00081 foreach(l, node->bitmapplans)
00082 {
00083 initNode = (Plan *) lfirst(l);
00084 bitmapplanstates[i] = ExecInitNode(initNode, estate, eflags);
00085 i++;
00086 }
00087
00088 return bitmapandstate;
00089 }
00090
00091
00092
00093
00094
00095 Node *
00096 MultiExecBitmapAnd(BitmapAndState *node)
00097 {
00098 PlanState **bitmapplans;
00099 int nplans;
00100 int i;
00101 TIDBitmap *result = NULL;
00102
00103
00104 if (node->ps.instrument)
00105 InstrStartNode(node->ps.instrument);
00106
00107
00108
00109
00110 bitmapplans = node->bitmapplans;
00111 nplans = node->nplans;
00112
00113
00114
00115
00116 for (i = 0; i < nplans; i++)
00117 {
00118 PlanState *subnode = bitmapplans[i];
00119 TIDBitmap *subresult;
00120
00121 subresult = (TIDBitmap *) MultiExecProcNode(subnode);
00122
00123 if (!subresult || !IsA(subresult, TIDBitmap))
00124 elog(ERROR, "unrecognized result from subplan");
00125
00126 if (result == NULL)
00127 result = subresult;
00128 else
00129 {
00130 tbm_intersect(result, subresult);
00131 tbm_free(subresult);
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141 if (tbm_is_empty(result))
00142 break;
00143 }
00144
00145 if (result == NULL)
00146 elog(ERROR, "BitmapAnd doesn't support zero inputs");
00147
00148
00149 if (node->ps.instrument)
00150 InstrStopNode(node->ps.instrument, 0 );
00151
00152 return (Node *) result;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 void
00164 ExecEndBitmapAnd(BitmapAndState *node)
00165 {
00166 PlanState **bitmapplans;
00167 int nplans;
00168 int i;
00169
00170
00171
00172
00173 bitmapplans = node->bitmapplans;
00174 nplans = node->nplans;
00175
00176
00177
00178
00179 for (i = 0; i < nplans; i++)
00180 {
00181 if (bitmapplans[i])
00182 ExecEndNode(bitmapplans[i]);
00183 }
00184 }
00185
00186 void
00187 ExecReScanBitmapAnd(BitmapAndState *node)
00188 {
00189 int i;
00190
00191 for (i = 0; i < node->nplans; i++)
00192 {
00193 PlanState *subnode = node->bitmapplans[i];
00194
00195
00196
00197
00198
00199 if (node->ps.chgParam != NULL)
00200 UpdateChangedParamSet(subnode, node->ps.chgParam);
00201
00202
00203
00204
00205
00206 if (subnode->chgParam == NULL)
00207 ExecReScan(subnode);
00208 }
00209 }