|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* nodeBitmapOr.c
|
|
|
|
|
* routines to handle BitmapOr nodes.
|
|
|
|
|
*
|
|
|
|
|
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* IDENTIFICATION
|
|
|
|
|
* src/backend/executor/nodeBitmapOr.c
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
/* INTERFACE ROUTINES
|
|
|
|
|
* ExecInitBitmapOr - initialize the BitmapOr node
|
|
|
|
|
* MultiExecBitmapOr - retrieve the result bitmap from the node
|
|
|
|
|
* ExecEndBitmapOr - shut down the BitmapOr node
|
|
|
|
|
* ExecReScanBitmapOr - rescan the BitmapOr node
|
|
|
|
|
*
|
|
|
|
|
* NOTES
|
|
|
|
|
* BitmapOr nodes don't make use of their left and right
|
|
|
|
|
* subtrees, rather they maintain a list of subplans,
|
|
|
|
|
* much like Append nodes. The logic is much simpler than
|
|
|
|
|
* Append, however, since we needn't cope with forward/backward
|
|
|
|
|
* execution.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
|
|
#include "executor/execdebug.h"
|
|
|
|
|
#include "executor/nodeBitmapOr.h"
|
|
|
|
|
#include "miscadmin.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
|
* ExecBitmapOr
|
|
|
|
|
*
|
|
|
|
|
* stub for pro forma compliance
|
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static TupleTableSlot *
|
|
|
|
|
ExecBitmapOr(PlanState *pstate)
|
|
|
|
|
{
|
|
|
|
|
elog(ERROR, "BitmapOr node does not support ExecProcNode call convention");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
|
* ExecInitBitmapOr
|
|
|
|
|
*
|
|
|
|
|
* Begin all of the subscans of the BitmapOr node.
|
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
BitmapOrState *
|
|
|
|
|
ExecInitBitmapOr(BitmapOr *node, EState *estate, int eflags)
|
|
|
|
|
{
|
|
|
|
|
BitmapOrState *bitmaporstate = makeNode(BitmapOrState);
|
|
|
|
|
PlanState **bitmapplanstates;
|
|
|
|
|
int nplans;
|
|
|
|
|
int i;
|
|
|
|
|
ListCell *l;
|
|
|
|
|
Plan *initNode;
|
|
|
|
|
|
|
|
|
|
/* check for unsupported flags */
|
|
|
|
|
Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set up empty vector of subplan states
|
|
|
|
|
*/
|
|
|
|
|
nplans = list_length(node->bitmapplans);
|
|
|
|
|
|
|
|
|
|
bitmapplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* create new BitmapOrState for our BitmapOr node
|
|
|
|
|
*/
|
|
|
|
|
bitmaporstate->ps.plan = (Plan *) node;
|
|
|
|
|
bitmaporstate->ps.state = estate;
|
|
|
|
|
bitmaporstate->ps.ExecProcNode = ExecBitmapOr;
|
|
|
|
|
bitmaporstate->bitmapplans = bitmapplanstates;
|
|
|
|
|
bitmaporstate->nplans = nplans;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* call ExecInitNode on each of the plans to be executed and save the
|
|
|
|
|
* results into the array "bitmapplanstates".
|
|
|
|
|
*/
|
|
|
|
|
i = 0;
|
|
|
|
|
foreach(l, node->bitmapplans)
|
|
|
|
|
{
|
|
|
|
|
initNode = (Plan *) lfirst(l);
|
|
|
|
|
bitmapplanstates[i] = ExecInitNode(initNode, estate, eflags);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Miscellaneous initialization
|
|
|
|
|
*
|
|
|
|
|
* BitmapOr plans don't have expression contexts because they never call
|
|
|
|
|
* ExecQual or ExecProject. They don't need any tuple slots either.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return bitmaporstate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
|
* MultiExecBitmapOr
|
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
Node *
|
|
|
|
|
MultiExecBitmapOr(BitmapOrState *node)
|
|
|
|
|
{
|
|
|
|
|
PlanState **bitmapplans;
|
|
|
|
|
int nplans;
|
|
|
|
|
int i;
|
|
|
|
|
TIDBitmap *result = NULL;
|
|
|
|
|
|
|
|
|
|
/* must provide our own instrumentation support */
|
|
|
|
|
if (node->ps.instrument)
|
|
|
|
|
InstrStartNode(node->ps.instrument);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* get information from the node
|
|
|
|
|
*/
|
|
|
|
|
bitmapplans = node->bitmapplans;
|
|
|
|
|
nplans = node->nplans;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Scan all the subplans and OR their result bitmaps
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < nplans; i++)
|
|
|
|
|
{
|
|
|
|
|
PlanState *subnode = bitmapplans[i];
|
|
|
|
|
TIDBitmap *subresult;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We can special-case BitmapIndexScan children to avoid an explicit
|
|
|
|
|
* tbm_union step for each child: just pass down the current result
|
|
|
|
|
* bitmap and let the child OR directly into it.
|
|
|
|
|
*/
|
|
|
|
|
if (IsA(subnode, BitmapIndexScanState))
|
|
|
|
|
{
|
|
|
|
|
if (result == NULL) /* first subplan */
|
|
|
|
|
{
|
|
|
|
|
/* XXX should we use less than work_mem for this? */
|
Support parallel bitmap heap scans.
The index is scanned by a single process, but then all cooperating
processes can iterate jointly over the resulting set of heap blocks.
In the future, we might also want to support using a parallel bitmap
index scan to set up for a parallel bitmap heap scan, but that's a
job for another day.
Dilip Kumar, with some corrections and cosmetic changes by me. The
larger patch set of which this is a part has been reviewed and tested
by (at least) Andres Freund, Amit Khandekar, Tushar Ahuja, Rafia
Sabih, Haribabu Kommi, Thomas Munro, and me.
Discussion: http://postgr.es/m/CAFiTN-uc4=0WxRGfCzs-xfkMYcSEWUC-Fon6thkJGjkh9i=13A@mail.gmail.com
9 years ago
|
|
|
result = tbm_create(work_mem * 1024L,
|
|
|
|
|
((BitmapOr *) node->ps.plan)->isshared ?
|
|
|
|
|
node->ps.state->es_query_dsa : NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
((BitmapIndexScanState *) subnode)->biss_result = result;
|
|
|
|
|
|
|
|
|
|
subresult = (TIDBitmap *) MultiExecProcNode(subnode);
|
|
|
|
|
|
|
|
|
|
if (subresult != result)
|
|
|
|
|
elog(ERROR, "unrecognized result from subplan");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* standard implementation */
|
|
|
|
|
subresult = (TIDBitmap *) MultiExecProcNode(subnode);
|
|
|
|
|
|
|
|
|
|
if (!subresult || !IsA(subresult, TIDBitmap))
|
|
|
|
|
elog(ERROR, "unrecognized result from subplan");
|
|
|
|
|
|
|
|
|
|
if (result == NULL)
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
9 years ago
|
|
|
result = subresult; /* first subplan */
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tbm_union(result, subresult);
|
|
|
|
|
tbm_free(subresult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We could return an empty result set here? */
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
elog(ERROR, "BitmapOr doesn't support zero inputs");
|
|
|
|
|
|
|
|
|
|
/* must provide our own instrumentation support */
|
|
|
|
|
if (node->ps.instrument)
|
|
|
|
|
InstrStopNode(node->ps.instrument, 0 /* XXX */ );
|
|
|
|
|
|
|
|
|
|
return (Node *) result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
|
* ExecEndBitmapOr
|
|
|
|
|
*
|
|
|
|
|
* Shuts down the subscans of the BitmapOr node.
|
|
|
|
|
*
|
|
|
|
|
* Returns nothing of interest.
|
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
ExecEndBitmapOr(BitmapOrState *node)
|
|
|
|
|
{
|
|
|
|
|
PlanState **bitmapplans;
|
|
|
|
|
int nplans;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* get information from the node
|
|
|
|
|
*/
|
|
|
|
|
bitmapplans = node->bitmapplans;
|
|
|
|
|
nplans = node->nplans;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* shut down each of the subscans (that we've initialized)
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < nplans; i++)
|
|
|
|
|
{
|
|
|
|
|
if (bitmapplans[i])
|
|
|
|
|
ExecEndNode(bitmapplans[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ExecReScanBitmapOr(BitmapOrState *node)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < node->nplans; i++)
|
|
|
|
|
{
|
|
|
|
|
PlanState *subnode = node->bitmapplans[i];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ExecReScan doesn't know about my subplans, so I have to do
|
|
|
|
|
* changed-parameter signaling myself.
|
|
|
|
|
*/
|
|
|
|
|
if (node->ps.chgParam != NULL)
|
|
|
|
|
UpdateChangedParamSet(subnode, node->ps.chgParam);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If chgParam of subnode is not null then plan will be re-scanned by
|
|
|
|
|
* first ExecProcNode.
|
|
|
|
|
*/
|
|
|
|
|
if (subnode->chgParam == NULL)
|
|
|
|
|
ExecReScan(subnode);
|
|
|
|
|
}
|
|
|
|
|
}
|