mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Add CYCLES scanstat measurement to "USE TEMP B-TREE FOR ORDER BY" lines.
FossilOrigin-Name: 365011ae8b7e3fcaa2c4ea9601231a3ef2223e60d7a53ec33013109dca22ad58
This commit is contained in:
27
src/select.c
27
src/select.c
@@ -65,6 +65,10 @@ struct SortCtx {
|
||||
} aDefer[4];
|
||||
#endif
|
||||
struct RowLoadInfo *pDeferredRowLoad; /* Deferred row loading info or NULL */
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
int addrPushStart; /* First instruction to push data into sorter */
|
||||
int addrPushEnd; /* Last instruction that pushes data into sorter */
|
||||
#endif
|
||||
};
|
||||
#define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
|
||||
|
||||
@@ -721,6 +725,10 @@ static void pushOntoSorter(
|
||||
*/
|
||||
assert( nData==1 || regData==regOrigData || regOrigData==0 );
|
||||
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
pSort->addrPushStart = sqlite3VdbeCurrentAddr(v);
|
||||
#endif
|
||||
|
||||
if( nPrefixReg ){
|
||||
assert( nPrefixReg==nExpr+bSeq );
|
||||
regBase = regData - nPrefixReg;
|
||||
@@ -821,6 +829,9 @@ static void pushOntoSorter(
|
||||
sqlite3VdbeChangeP2(v, iSkip,
|
||||
pSort->labelOBLopt ? pSort->labelOBLopt : sqlite3VdbeCurrentAddr(v));
|
||||
}
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
pSort->addrPushEnd = sqlite3VdbeCurrentAddr(v)-1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1647,6 +1658,16 @@ static void generateSortTail(
|
||||
int bSeq; /* True if sorter record includes seq. no. */
|
||||
int nRefKey = 0;
|
||||
struct ExprList_item *aOutEx = p->pEList->a;
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
int addrExplain; /* Address of OP_Explain instruction */
|
||||
#endif
|
||||
|
||||
ExplainQueryPlan2(addrExplain, (pParse, 0,
|
||||
"USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat>0?"RIGHT PART OF ":"")
|
||||
);
|
||||
sqlite3VdbeScanStatusRange(
|
||||
v, addrExplain, pSort->addrPushStart, pSort->addrPushEnd
|
||||
);
|
||||
|
||||
assert( addrBreak<0 );
|
||||
if( pSort->labelBkOut ){
|
||||
@@ -1759,6 +1780,7 @@ static void generateSortTail(
|
||||
VdbeComment((v, "%s", aOutEx[i].zEName));
|
||||
}
|
||||
}
|
||||
sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
|
||||
switch( eDest ){
|
||||
case SRT_Table:
|
||||
case SRT_EphemTab: {
|
||||
@@ -1820,6 +1842,7 @@ static void generateSortTail(
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
|
||||
}
|
||||
sqlite3VdbeScanStatusRange(v, addrExplain, sqlite3VdbeCurrentAddr(v)-1, -1);
|
||||
if( pSort->regReturn ) sqlite3VdbeAddOp1(v, OP_Return, pSort->regReturn);
|
||||
sqlite3VdbeResolveLabel(v, addrBreak);
|
||||
}
|
||||
@@ -7305,7 +7328,7 @@ int sqlite3Select(
|
||||
if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
|
||||
sqlite3VdbeAddOp2(v, OP_Return, pItem->regReturn, topAddr+1);
|
||||
VdbeComment((v, "end %!S", pItem));
|
||||
sqlite3VdbeScanStatusEnd(v, addrExplain);
|
||||
sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
|
||||
sqlite3VdbeJumpHere(v, topAddr);
|
||||
sqlite3ClearTempRegCache(pParse);
|
||||
if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
|
||||
@@ -8060,8 +8083,6 @@ int sqlite3Select(
|
||||
** and send them to the callback one by one.
|
||||
*/
|
||||
if( sSort.pOrderBy ){
|
||||
explainTempTable(pParse,
|
||||
sSort.nOBSat>0 ? "RIGHT PART OF ORDER BY":"ORDER BY");
|
||||
assert( p->pEList==pEList );
|
||||
generateSortTail(pParse, p, &sSort, pEList->nExpr, pDest);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user