diff options
author | drh <> | 2021-12-06 21:45:31 +0000 |
---|---|---|
committer | drh <> | 2021-12-06 21:45:31 +0000 |
commit | 23d41e63f2e4560728e13cefabb4fd411c687672 (patch) | |
tree | b1f361f9497cb7b10ce348af8bee86df5f6cbc8b /src | |
parent | 50fb7e09b4247ce34a0b0266614303d00f929def (diff) | |
download | sqlite-23d41e63f2e4560728e13cefabb4fd411c687672.tar.gz sqlite-23d41e63f2e4560728e13cefabb4fd411c687672.zip |
Add SQLITE_STMTSTATUS_FILTER_HIT and _MISS for tracking the effectiveness
of Bloom filters.
FossilOrigin-Name: 24ba535d200fc8a99dd8e66c6d100b5f6ae442098bafb152008429398eefe3e7
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 7 | ||||
-rw-r--r-- | src/sqlite.h.in | 9 | ||||
-rw-r--r-- | src/vdbe.c | 2 | ||||
-rw-r--r-- | src/vdbeInt.h | 2 |
4 files changed, 19 insertions, 1 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index 543141c9e..c46eaffd6 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2790,6 +2790,7 @@ static int display_stats( } if( pArg->pStmt ){ + int iHit, iMiss; iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset); raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur); @@ -2797,6 +2798,12 @@ static int display_stats( raw_printf(pArg->out, "Sort Operations: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset); raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur); + iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT, bReset); + iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS, bReset); + if( iHit || iMiss ){ + raw_printf(pArg->out, "Bloom filter bypass taken: %d/%d\n", + iHit, iHit+iMiss); + } iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset); raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_REPREPARE,bReset); diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 98a028b0b..4125122e1 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8467,6 +8467,13 @@ int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); ** The counter is incremented on the first [sqlite3_step()] call of each ** cycle. ** +** [[SQLITE_STMTSTATUS_FILTER HIT]] <dt>SQLITE_STMTSTATUS_FILTER_HIT</dt> +** <dd>^This is the number of times that a join step was bypassed because +** a Bloom filtered returned non-found. The corresponding +** SQLITE_STMTSTATUS_FILTER_MISS value is the number of times that the +** Bloom filter returned a find, and thus the join step had to be processed +** as normal. +** ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt> ** <dd>^This is the approximate number of bytes of heap memory ** used to store the prepared statement. ^This value is not actually @@ -8481,6 +8488,8 @@ int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); #define SQLITE_STMTSTATUS_VM_STEP 4 #define SQLITE_STMTSTATUS_REPREPARE 5 #define SQLITE_STMTSTATUS_RUN 6 +#define SQLITE_STMTSTATUS_FILTER_MISS 7 +#define SQLITE_STMTSTATUS_FILTER_HIT 8 #define SQLITE_STMTSTATUS_MEMUSED 99 /* diff --git a/src/vdbe.c b/src/vdbe.c index c2281e70a..0abe64a71 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -8239,8 +8239,10 @@ case OP_Filter: { /* jump */ h %= pIn1->n; if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){ VdbeBranchTaken(1, 2); + p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++; goto jump_to_p2; }else{ + p->aCounter[SQLITE_STMTSTATUS_FILTER_MISS]++; VdbeBranchTaken(0, 2); } break; diff --git a/src/vdbeInt.h b/src/vdbeInt.h index c76cdbfdb..38863f6d6 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -430,7 +430,7 @@ struct Vdbe { bft bIsReader:1; /* True for statements that read */ yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ yDbMask lockMask; /* Subset of btreeMask that requires a lock */ - u32 aCounter[7]; /* Counters used by sqlite3_stmt_status() */ + u32 aCounter[9]; /* Counters used by sqlite3_stmt_status() */ char *zSql; /* Text of the SQL statement that generated this */ #ifdef SQLITE_ENABLE_NORMALIZE char *zNormSql; /* Normalization of the associated SQL statement */ |