mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 16:01:23 +02:00
Adjust nodeBitmapIndexscan to keep the target index opened from plan
startup to end, rather than re-opening it in each MultiExecBitmapIndexScan call. I had foolishly thought that opening/closing wouldn't be much more expensive than a rescan call, but that was sheer brain fade. This seems to fix about half of the performance lossage reported by Sergey Koposov. I'm still not sure where the other half went.
This commit is contained in:
parent
e6e7e64345
commit
db70a31294
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.7 2005/04/25 01:30:12 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.8 2005/05/05 03:37:23 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -38,8 +38,6 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
|
|||||||
{
|
{
|
||||||
#define MAX_TIDS 1024
|
#define MAX_TIDS 1024
|
||||||
TIDBitmap *tbm;
|
TIDBitmap *tbm;
|
||||||
Oid indexid;
|
|
||||||
Relation indexRelation;
|
|
||||||
IndexScanDesc scandesc;
|
IndexScanDesc scandesc;
|
||||||
ItemPointerData tids[MAX_TIDS];
|
ItemPointerData tids[MAX_TIDS];
|
||||||
int32 ntids;
|
int32 ntids;
|
||||||
@ -49,6 +47,11 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
|
|||||||
if (node->ss.ps.instrument)
|
if (node->ss.ps.instrument)
|
||||||
InstrStartNode(node->ss.ps.instrument);
|
InstrStartNode(node->ss.ps.instrument);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extract necessary information from index scan node
|
||||||
|
*/
|
||||||
|
scandesc = node->biss_ScanDesc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have runtime keys and they've not already been set up, do it
|
* If we have runtime keys and they've not already been set up, do it
|
||||||
* now.
|
* now.
|
||||||
@ -56,24 +59,6 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
|
|||||||
if (node->biss_RuntimeKeyInfo && !node->biss_RuntimeKeysReady)
|
if (node->biss_RuntimeKeyInfo && !node->biss_RuntimeKeysReady)
|
||||||
ExecReScan((PlanState *) node, NULL);
|
ExecReScan((PlanState *) node, NULL);
|
||||||
|
|
||||||
/*
|
|
||||||
* We do not open or lock the base relation here. We assume that an
|
|
||||||
* ancestor BitmapHeapScan node is holding AccessShareLock on the
|
|
||||||
* heap relation throughout the execution of the plan tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* open the index relation and initialize relation and scan
|
|
||||||
* descriptors. Note we acquire no locks here; the index machinery
|
|
||||||
* does its own locks and unlocks.
|
|
||||||
*/
|
|
||||||
indexid = ((BitmapIndexScan *) node->ss.ps.plan)->indexid;
|
|
||||||
indexRelation = index_open(indexid);
|
|
||||||
scandesc = index_beginscan_multi(indexRelation,
|
|
||||||
node->ss.ps.state->es_snapshot,
|
|
||||||
node->biss_NumScanKeys,
|
|
||||||
node->biss_ScanKeys);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare the result bitmap. Normally we just create a new one to pass
|
* Prepare the result bitmap. Normally we just create a new one to pass
|
||||||
* back; however, our parent node is allowed to store a pre-made one
|
* back; however, our parent node is allowed to store a pre-made one
|
||||||
@ -110,12 +95,6 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
|
|||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* close the index relation
|
|
||||||
*/
|
|
||||||
index_endscan(scandesc);
|
|
||||||
index_close(indexRelation);
|
|
||||||
|
|
||||||
/* must provide our own instrumentation support */
|
/* must provide our own instrumentation support */
|
||||||
if (node->ss.ps.instrument)
|
if (node->ss.ps.instrument)
|
||||||
InstrStopNodeMulti(node->ss.ps.instrument, nTuples);
|
InstrStopNodeMulti(node->ss.ps.instrument, nTuples);
|
||||||
@ -127,7 +106,7 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
|
|||||||
* ExecBitmapIndexReScan(node)
|
* ExecBitmapIndexReScan(node)
|
||||||
*
|
*
|
||||||
* Recalculates the value of the scan keys whose value depends on
|
* Recalculates the value of the scan keys whose value depends on
|
||||||
* information known at runtime.
|
* information known at runtime and rescans the indexed relation.
|
||||||
* ----------------------------------------------------------------
|
* ----------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
@ -169,6 +148,9 @@ ExecBitmapIndexReScan(BitmapIndexScanState *node, ExprContext *exprCtxt)
|
|||||||
node->biss_NumScanKeys);
|
node->biss_NumScanKeys);
|
||||||
node->biss_RuntimeKeysReady = true;
|
node->biss_RuntimeKeysReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reset index scan */
|
||||||
|
index_rescan(node->biss_ScanDesc, node->biss_ScanKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
@ -178,6 +160,15 @@ ExecBitmapIndexReScan(BitmapIndexScanState *node, ExprContext *exprCtxt)
|
|||||||
void
|
void
|
||||||
ExecEndBitmapIndexScan(BitmapIndexScanState *node)
|
ExecEndBitmapIndexScan(BitmapIndexScanState *node)
|
||||||
{
|
{
|
||||||
|
Relation indexRelationDesc;
|
||||||
|
IndexScanDesc indexScanDesc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extract information from the node
|
||||||
|
*/
|
||||||
|
indexRelationDesc = node->biss_RelationDesc;
|
||||||
|
indexScanDesc = node->biss_ScanDesc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free the exprcontext ... now dead code, see ExecFreeExprContext
|
* Free the exprcontext ... now dead code, see ExecFreeExprContext
|
||||||
*/
|
*/
|
||||||
@ -185,6 +176,12 @@ ExecEndBitmapIndexScan(BitmapIndexScanState *node)
|
|||||||
if (node->biss_RuntimeContext)
|
if (node->biss_RuntimeContext)
|
||||||
FreeExprContext(node->biss_RuntimeContext);
|
FreeExprContext(node->biss_RuntimeContext);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* close the index relation
|
||||||
|
*/
|
||||||
|
index_endscan(indexScanDesc);
|
||||||
|
index_close(indexRelationDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
@ -272,10 +269,27 @@ ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate)
|
|||||||
indexstate->biss_RuntimeContext = NULL;
|
indexstate->biss_RuntimeContext = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We don't keep the table or index open across calls */
|
/*
|
||||||
|
* We do not open or lock the base relation here. We assume that an
|
||||||
|
* ancestor BitmapHeapScan node is holding AccessShareLock on the
|
||||||
|
* heap relation throughout the execution of the plan tree.
|
||||||
|
*/
|
||||||
|
|
||||||
indexstate->ss.ss_currentRelation = NULL;
|
indexstate->ss.ss_currentRelation = NULL;
|
||||||
indexstate->ss.ss_currentScanDesc = NULL;
|
indexstate->ss.ss_currentScanDesc = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* open the index relation and initialize relation and scan
|
||||||
|
* descriptors. Note we acquire no locks here; the index machinery
|
||||||
|
* does its own locks and unlocks.
|
||||||
|
*/
|
||||||
|
indexstate->biss_RelationDesc = index_open(node->indexid);
|
||||||
|
indexstate->biss_ScanDesc =
|
||||||
|
index_beginscan_multi(indexstate->biss_RelationDesc,
|
||||||
|
estate->es_snapshot,
|
||||||
|
numScanKeys,
|
||||||
|
scanKeys);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* all done.
|
* all done.
|
||||||
*/
|
*/
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.130 2005/04/28 21:47:17 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.131 2005/05/05 03:37:23 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -897,6 +897,8 @@ typedef struct IndexScanState
|
|||||||
* that will be evaluated at runtime
|
* that will be evaluated at runtime
|
||||||
* RuntimeContext expr context for evaling runtime Skeys
|
* RuntimeContext expr context for evaling runtime Skeys
|
||||||
* RuntimeKeysReady true if runtime Skeys have been computed
|
* RuntimeKeysReady true if runtime Skeys have been computed
|
||||||
|
* RelationDesc index relation descriptor
|
||||||
|
* ScanDesc index scan descriptor
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
typedef struct BitmapIndexScanState
|
typedef struct BitmapIndexScanState
|
||||||
@ -908,6 +910,8 @@ typedef struct BitmapIndexScanState
|
|||||||
ExprState **biss_RuntimeKeyInfo;
|
ExprState **biss_RuntimeKeyInfo;
|
||||||
ExprContext *biss_RuntimeContext;
|
ExprContext *biss_RuntimeContext;
|
||||||
bool biss_RuntimeKeysReady;
|
bool biss_RuntimeKeysReady;
|
||||||
|
Relation biss_RelationDesc;
|
||||||
|
IndexScanDesc biss_ScanDesc;
|
||||||
} BitmapIndexScanState;
|
} BitmapIndexScanState;
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
|
Loading…
Reference in New Issue
Block a user