mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-14 00:22:38 +03:00
Fix a problem with "EXPLAIN QUERY PLAN SELECT count(*) FROM tbl".
FossilOrigin-Name: 9f9f32882501ac9b6e60f81195a64bdbf6e4497b
This commit is contained in:
27
src/select.c
27
src/select.c
@@ -3618,6 +3618,32 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){
|
||||
sqlite3ExprCacheClear(pParse);
|
||||
}
|
||||
|
||||
/*
|
||||
** Add a single OP_Explain instruction to the VDBE to explain a simple
|
||||
** count(*) query ("SELECT count(*) FROM pTab").
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
static void explainSimpleCount(
|
||||
Parse *pParse, /* Parse context */
|
||||
Table *pTab, /* Table being queried */
|
||||
Index *pIdx /* Index used to optimize scan, or NULL */
|
||||
){
|
||||
if( pParse->explain==2 ){
|
||||
char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s %s%s(~%d rows)",
|
||||
pTab->zName,
|
||||
pIdx ? "USING COVERING INDEX " : "",
|
||||
pIdx ? pIdx->zName : "",
|
||||
pTab->nRowEst
|
||||
);
|
||||
sqlite3VdbeAddOp4(
|
||||
pParse->pVdbe, OP_Explain, pParse->iSelectId, 0, 0, zEqp, P4_DYNAMIC
|
||||
);
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define explainSimpleCount(a,b,c)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Generate code for the SELECT statement given in the p argument.
|
||||
**
|
||||
@@ -4229,6 +4255,7 @@ int sqlite3Select(
|
||||
}
|
||||
sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
|
||||
sqlite3VdbeAddOp1(v, OP_Close, iCsr);
|
||||
explainSimpleCount(pParse, pTab, pBest);
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_BTREECOUNT */
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user