276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
rc = sqlite3_step(pStmt->pStmt);
return rc;
}
/*
** Print warnings if a query is inefficient.
*/
static void db_stats(Stmt *pStmt){
#ifdef FOSSIL_DEBUG
int c1, c2;
c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
/* printf("**** steps=%d & sorts=%d in [%s]\n", c1, c2,
sqlite3_sql(pStmt->pStmt)); */
if( c1>5 ){
fossil_warning("%d scan steps in [%s]", c1, sqlite3_sql(pStmt->pStmt));
}else if( c2 ){
fossil_warning("sort w/o index in [%s]", sqlite3_sql(pStmt->pStmt));
}
#endif
}
/*
** Reset or finalize a statement.
*/
int db_reset(Stmt *pStmt){
int rc;
db_stats(pStmt);
rc = sqlite3_reset(pStmt->pStmt);
db_check_result(rc);
return rc;
}
int db_finalize(Stmt *pStmt){
int rc;
db_stats(pStmt);
blob_reset(&pStmt->sql);
rc = sqlite3_finalize(pStmt->pStmt);
db_check_result(rc);
pStmt->pStmt = 0;
if( pStmt->pNext ){
pStmt->pNext->pPrev = pStmt->pPrev;
}
|
|
>
>
|
|
<
<
|
|
|
|
|
|
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
rc = sqlite3_step(pStmt->pStmt);
return rc;
}
/*
** Print warnings if a query is inefficient.
*/
static void db_stats(sqlite3_stmt *pStmt){
#ifdef FOSSIL_DEBUG
int c1, c2;
const char *zSql = sqlite3_sql(pStmt);
if( zSql==0 ) return;
c1 = sqlite3_stmt_status(pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
c2 = sqlite3_stmt_status(pStmt, SQLITE_STMTSTATUS_SORT, 1);
if( c1>5 && strstr(zSql,"/*scan*/")==0 ){
fossil_warning("%d scan steps in [%s]", c1, zSql);
}else if( c2 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
fossil_warning("sort w/o index in [%s]", zSql);
}
#endif
}
/*
** Reset or finalize a statement.
*/
int db_reset(Stmt *pStmt){
int rc;
db_stats(pStmt->pStmt);
rc = sqlite3_reset(pStmt->pStmt);
db_check_result(rc);
return rc;
}
int db_finalize(Stmt *pStmt){
int rc;
db_stats(pStmt->pStmt);
blob_reset(&pStmt->sql);
rc = sqlite3_finalize(pStmt->pStmt);
db_check_result(rc);
pStmt->pStmt = 0;
if( pStmt->pNext ){
pStmt->pNext->pPrev = pStmt->pPrev;
}
|