mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Provide an estimated row count to stat_init() for STAT1 analysis.
FossilOrigin-Name: 714419fe85cfdad22979183a94e4569c87740652758ab76b646753cf2b013b54
This commit is contained in:
18
src/vdbe.c
18
src/vdbe.c
@@ -3187,11 +3187,15 @@ case OP_MakeRecord: {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: Count P1 P2 * * *
|
||||
/* Opcode: Count P1 P2 p3 * *
|
||||
** Synopsis: r[P2]=count()
|
||||
**
|
||||
** Store the number of entries (an integer value) in the table or index
|
||||
** opened by cursor P1 in register P2
|
||||
** opened by cursor P1 in register P2.
|
||||
**
|
||||
** If P3==0, then an exact count is obtained, which involves visiting
|
||||
** every btree page of the table. But if P3 is non-zero, an estimate
|
||||
** is returned based on the current cursor position.
|
||||
*/
|
||||
case OP_Count: { /* out2 */
|
||||
i64 nEntry;
|
||||
@@ -3200,9 +3204,13 @@ case OP_Count: { /* out2 */
|
||||
assert( p->apCsr[pOp->p1]->eCurType==CURTYPE_BTREE );
|
||||
pCrsr = p->apCsr[pOp->p1]->uc.pCursor;
|
||||
assert( pCrsr );
|
||||
nEntry = 0; /* Not needed. Only used to silence a warning. */
|
||||
rc = sqlite3BtreeCount(db, pCrsr, &nEntry);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
if( pOp->p3 ){
|
||||
nEntry = sqlite3BtreeRowCountEst(pCrsr);
|
||||
}else{
|
||||
nEntry = 0; /* Not needed. Only used to silence a warning. */
|
||||
rc = sqlite3BtreeCount(db, pCrsr, &nEntry);
|
||||
if( rc ) goto abort_due_to_error;
|
||||
}
|
||||
pOut = out2Prerelease(p, pOp);
|
||||
pOut->u.i = nEntry;
|
||||
goto check_for_interrupt;
|
||||
|
Reference in New Issue
Block a user