Fossil SCM
When compiled with FOSSIL_DEBUG, print warnings if any SQLite queries fail to use indices.
Commit
e95e87c1edf4b1ef85bcaf3d1bab7d90d882215d
Parent
61c52dd6aa3641d…
1 file changed
+22
-1
M
src/db.c
+22
-1
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -274,21 +274,42 @@ | ||
| 274 | 274 | int db_step(Stmt *pStmt){ |
| 275 | 275 | int rc; |
| 276 | 276 | rc = sqlite3_step(pStmt->pStmt); |
| 277 | 277 | return rc; |
| 278 | 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 | +} | |
| 279 | 297 | |
| 280 | 298 | /* |
| 281 | 299 | ** Reset or finalize a statement. |
| 282 | 300 | */ |
| 283 | 301 | 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); | |
| 285 | 305 | db_check_result(rc); |
| 286 | 306 | return rc; |
| 287 | 307 | } |
| 288 | 308 | int db_finalize(Stmt *pStmt){ |
| 289 | 309 | int rc; |
| 310 | + db_stats(pStmt); | |
| 290 | 311 | blob_reset(&pStmt->sql); |
| 291 | 312 | rc = sqlite3_finalize(pStmt->pStmt); |
| 292 | 313 | db_check_result(rc); |
| 293 | 314 | pStmt->pStmt = 0; |
| 294 | 315 | if( pStmt->pNext ){ |
| 295 | 316 |
| --- 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 |