Fossil SCM

When compiled with FOSSIL_DEBUG, print warnings if any SQLite queries fail to use indices.

drh 2010-03-31 14:35 UTC trunk
Commit e95e87c1edf4b1ef85bcaf3d1bab7d90d882215d
1 file changed +22 -1
+22 -1
--- src/db.c
+++ src/db.c
@@ -274,21 +274,42 @@
274274
int db_step(Stmt *pStmt){
275275
int rc;
276276
rc = sqlite3_step(pStmt->pStmt);
277277
return rc;
278278
}
279
+
280
+/*
281
+** Print warnings if a query is inefficient.
282
+*/
283
+static void db_stats(Stmt *pStmt){
284
+#ifdef FOSSIL_DEBUG
285
+ int c1, c2;
286
+ c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
287
+ c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
288
+ /* printf("**** steps=%d & sorts=%d in [%s]\n", c1, c2,
289
+ sqlite3_sql(pStmt->pStmt)); */
290
+ if( c1>5 ){
291
+ fossil_warning("%d scan steps in [%s]", c1, sqlite3_sql(pStmt->pStmt));
292
+ }else if( c2 ){
293
+ fossil_warning("sort w/o index in [%s]", sqlite3_sql(pStmt->pStmt));
294
+ }
295
+#endif
296
+}
279297
280298
/*
281299
** Reset or finalize a statement.
282300
*/
283301
int db_reset(Stmt *pStmt){
284
- int rc = sqlite3_reset(pStmt->pStmt);
302
+ int rc;
303
+ db_stats(pStmt);
304
+ rc = sqlite3_reset(pStmt->pStmt);
285305
db_check_result(rc);
286306
return rc;
287307
}
288308
int db_finalize(Stmt *pStmt){
289309
int rc;
310
+ db_stats(pStmt);
290311
blob_reset(&pStmt->sql);
291312
rc = sqlite3_finalize(pStmt->pStmt);
292313
db_check_result(rc);
293314
pStmt->pStmt = 0;
294315
if( pStmt->pNext ){
295316
--- src/db.c
+++ src/db.c
@@ -274,21 +274,42 @@
274 int db_step(Stmt *pStmt){
275 int rc;
276 rc = sqlite3_step(pStmt->pStmt);
277 return rc;
278 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
280 /*
281 ** Reset or finalize a statement.
282 */
283 int db_reset(Stmt *pStmt){
284 int rc = sqlite3_reset(pStmt->pStmt);
 
 
285 db_check_result(rc);
286 return rc;
287 }
288 int db_finalize(Stmt *pStmt){
289 int rc;
 
290 blob_reset(&pStmt->sql);
291 rc = sqlite3_finalize(pStmt->pStmt);
292 db_check_result(rc);
293 pStmt->pStmt = 0;
294 if( pStmt->pNext ){
295
--- src/db.c
+++ src/db.c
@@ -274,21 +274,42 @@
274 int db_step(Stmt *pStmt){
275 int rc;
276 rc = sqlite3_step(pStmt->pStmt);
277 return rc;
278 }
279
280 /*
281 ** Print warnings if a query is inefficient.
282 */
283 static void db_stats(Stmt *pStmt){
284 #ifdef FOSSIL_DEBUG
285 int c1, c2;
286 c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
287 c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
288 /* printf("**** steps=%d & sorts=%d in [%s]\n", c1, c2,
289 sqlite3_sql(pStmt->pStmt)); */
290 if( c1>5 ){
291 fossil_warning("%d scan steps in [%s]", c1, sqlite3_sql(pStmt->pStmt));
292 }else if( c2 ){
293 fossil_warning("sort w/o index in [%s]", sqlite3_sql(pStmt->pStmt));
294 }
295 #endif
296 }
297
298 /*
299 ** Reset or finalize a statement.
300 */
301 int db_reset(Stmt *pStmt){
302 int rc;
303 db_stats(pStmt);
304 rc = sqlite3_reset(pStmt->pStmt);
305 db_check_result(rc);
306 return rc;
307 }
308 int db_finalize(Stmt *pStmt){
309 int rc;
310 db_stats(pStmt);
311 blob_reset(&pStmt->sql);
312 rc = sqlite3_finalize(pStmt->pStmt);
313 db_check_result(rc);
314 pStmt->pStmt = 0;
315 if( pStmt->pNext ){
316

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button