Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

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().

{
    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]);
    }
}

BitmapAndState* ExecInitBitmapAnd ( BitmapAnd node,
EState estate,
int  eflags 
)

Definition at line 42 of file nodeBitmapAnd.c.

References Assert, BitmapAndState::bitmapplans, BitmapAnd::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().

{
    BitmapAndState *bitmapandstate = makeNode(BitmapAndState);
    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 BitmapAndState for our BitmapAnd node
     */
    bitmapandstate->ps.plan = (Plan *) node;
    bitmapandstate->ps.state = estate;
    bitmapandstate->bitmapplans = bitmapplanstates;
    bitmapandstate->nplans = nplans;

    /*
     * Miscellaneous initialization
     *
     * BitmapAnd plans don't have expression contexts because they never call
     * ExecQual or ExecProject.  They don't need any tuple slots either.
     */

    /*
     * 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++;
    }

    return bitmapandstate;
}

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().

{
    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);
    }
}

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, tbm_free(), tbm_intersect(), and tbm_is_empty().

Referenced by MultiExecProcNode().

{
    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 AND their result bitmaps
     */
    for (i = 0; i < nplans; i++)
    {
        PlanState  *subnode = bitmapplans[i];
        TIDBitmap  *subresult;

        subresult = (TIDBitmap *) MultiExecProcNode(subnode);

        if (!subresult || !IsA(subresult, TIDBitmap))
            elog(ERROR, "unrecognized result from subplan");

        if (result == NULL)
            result = subresult; /* first subplan */
        else
        {
            tbm_intersect(result, subresult);
            tbm_free(subresult);
        }

        /*
         * If at any stage we have a completely empty bitmap, we can fall out
         * without evaluating the remaining subplans, since ANDing them can no
         * longer change the result.  (Note: the fact that indxpath.c orders
         * the subplans by selectivity should make this case more likely to
         * occur.)
         */
        if (tbm_is_empty(result))
            break;
    }

    if (result == NULL)
        elog(ERROR, "BitmapAnd doesn't support zero inputs");

    /* must provide our own instrumentation support */
    if (node->ps.instrument)
        InstrStopNode(node->ps.instrument, 0 /* XXX */ );

    return (Node *) result;
}