diff options
author | dan <dan@noemail.net> | 2009-10-19 18:11:09 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2009-10-19 18:11:09 +0000 |
commit | 1d2ce4f80422b0d8720817b057f834102e1738e3 (patch) | |
tree | 0242dfefd86f20e21877d9d9d037c5a3140cb0b6 /src | |
parent | f7b0b0ad5fb083c194f0f69e75747dccf71427ed (diff) | |
download | sqlite-1d2ce4f80422b0d8720817b057f834102e1738e3.tar.gz sqlite-1d2ce4f80422b0d8720817b057f834102e1738e3.zip |
Remove the sqlite3_reoptimize() API. The same functionality is now provided automatically to queries prepared using prepare_v2().
FossilOrigin-Name: 2c50b3d5aab7cd8cc841d61f8c3b2b34d2f0b54b
Diffstat (limited to 'src')
-rw-r--r-- | src/sqlite.h.in | 31 | ||||
-rw-r--r-- | src/tclsqlite.c | 9 | ||||
-rw-r--r-- | src/test1.c | 29 | ||||
-rw-r--r-- | src/vdbe.h | 2 | ||||
-rw-r--r-- | src/vdbeInt.h | 2 | ||||
-rw-r--r-- | src/vdbeapi.c | 36 | ||||
-rw-r--r-- | src/vdbeaux.c | 10 | ||||
-rw-r--r-- | src/where.c | 6 |
8 files changed, 13 insertions, 112 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in index a2e0382f5..877c2c7f2 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5744,37 +5744,6 @@ int sqlite3_unlock_notify( int sqlite3_strnicmp(const char *, const char *, int); /* -** CAPI3REF: Optimizing for Bound Parameters -** EXPERIMENTAL -** -** If possible, optimize the SQL statement passed as the only argument -** for the values currently bound to the statements SQL variables. -** -** SQLite currently contains two optimizations that depend upon the values -** of SQL literals specified as part of a query: -** -** <ul> -** <li> The [range query optimization], and -** <li> The [LIKE optimization]. -** </ul> -** -** Normally, queries that use an SQL [parameter] in the relevant expression -** or expressions may not benefit from either of the above optimizations. -** This function may be used to overcome this limitation. -** -** Calling sqlite3_reoptimize() on a statement handle after values have been -** bound to its SQL parameters causes SQLite to inspect the query and the -** bound values to determine if either of the above optimizations may be -** applied to it. If so, a new query plan is formulated to take advantage -** of the optimizations. -** -** If it is determined that neither of the above optimizations may be -** profitably applied to the query based on the values bound to SQL -** parameters, this function is a no-op. -*/ -int sqlite3_reoptimize(sqlite3_stmt *pStmt); - -/* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support. */ diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 3e7a513e7..76e0ee09f 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1129,15 +1129,6 @@ static int dbPrepareAndBind( pPreStmt->nParm = iParm; *ppPreStmt = pPreStmt; - /* Call sqlite3_reoptimize() to optimize the statement according to - ** the values just bound to it. If SQLITE_ENABLE_STAT2 is not defined - ** or the statement will not benefit from re-optimization, this - ** call is a no-op. */ - if( SQLITE_OK!=sqlite3_reoptimize(pPreStmt->pStmt) ){ - Tcl_SetObjResult(interp, dbTextToObj(sqlite3_errmsg(pDb->db))); - return TCL_ERROR; - } - return TCL_OK; } diff --git a/src/test1.c b/src/test1.c index 7c0b2ad3d..6ea48e671 100644 --- a/src/test1.c +++ b/src/test1.c @@ -2050,34 +2050,6 @@ static int test_stmt_status( } /* -** Usage: sqlite3_reoptimize STMT -** -** Call sqlite3_reoptimize() on the statement handle passed as the -** only parameter. Return a string representing the value returned by -** sqlite3_reoptimize - "SQLITE_OK", "SQLITE_MISUSE" etc. -*/ -static int test_reoptimize( - void * clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *CONST objv[] -){ - sqlite3_stmt *pStmt; - int rc; - - if( objc!=2 ){ - Tcl_AppendResult(interp, "wrong # args: should be \"", - Tcl_GetString(objv[0]), " STMT", 0); - return TCL_ERROR; - } - if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; - rc = sqlite3_reoptimize(pStmt); - Tcl_ResetResult(interp); - Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); - return TCL_OK; -} - -/* ** Usage: sqlite3_next_stmt DB STMT ** ** Return the next statment in sequence after STMT. @@ -5031,7 +5003,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3_step", test_step ,0 }, { "sqlite3_sql", test_sql ,0 }, { "sqlite3_next_stmt", test_next_stmt ,0 }, - { "sqlite3_reoptimize", test_reoptimize ,0 }, { "sqlite3_release_memory", test_release_memory, 0}, { "sqlite3_soft_heap_limit", test_soft_heap_limit, 0}, diff --git a/src/vdbe.h b/src/vdbe.h index 1ff4d610a..23d8458d0 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -203,7 +203,7 @@ void sqlite3VdbeSwap(Vdbe*,Vdbe*); VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*); void sqlite3VdbeProgramDelete(sqlite3 *, SubProgram *, int); sqlite3_value *sqlite3VdbeGetValue(Vdbe*, int, u8); -void sqlite3VdbeSetVarmask(Vdbe*,int,int); +void sqlite3VdbeSetVarmask(Vdbe*, int); #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT int sqlite3VdbeReleaseMemory(int); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index fabd78606..2b8bb5927 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -323,8 +323,6 @@ struct Vdbe { #endif VdbeFrame *pFrame; /* Parent frame */ int nFrame; /* Number of frames in pFrame list */ - u8 optimizable; /* True if VM may benefit from sqlite3_reoptimize() */ - u32 optmask; /* Bitmask of vars that may be used by reoptimize() */ u32 expmask; /* Binding to these vars invalidates VM */ }; diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 107c1eb6c..12d7349ac 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -915,17 +915,10 @@ static int vdbeUnbind(Vdbe *p, int i){ pVar->flags = MEM_Null; sqlite3Error(p->db, SQLITE_OK, 0); - /* If the bit corresponding to this variable is set in Vdbe.opmask, set - ** the optimizable flag before returning. This tells the sqlite3_reoptimize() - ** function that the VM program may benefit from recompilation. - ** - ** If the bit in Vdbe.expmask is set, then binding a new value to this - ** variable invalidates the current query plan. This comes about when the - ** variable is the RHS of a LIKE or GLOB operator and the LIKE/GLOB is - ** able to use an index. */ - if( (i<32 && p->optmask & ((u32)1 << i)) || p->optmask==0xffffffff ){ - p->optimizable = 1; - } + /* If the bit corresponding to this variable in Vdbe.expmask is set, then + ** binding a new value to this variable invalidates the current query plan. + */ + assert( p->isPrepareV2 || p->expmask==0 ); if( (i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff ){ p->expired = 1; } @@ -1221,24 +1214,3 @@ int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ return v; } -/* -** If possible, optimize the statement for the current bindings. -*/ -int sqlite3_reoptimize(sqlite3_stmt *pStmt){ - int rc = SQLITE_OK; - Vdbe *v = (Vdbe *)pStmt; - sqlite3 *db = v->db; - - sqlite3_mutex_enter(db->mutex); - if( v->isPrepareV2==0 || v->pc>0 ){ - rc = SQLITE_MISUSE; - }else if( v->optimizable ){ - rc = sqlite3Reprepare(v); - rc = sqlite3ApiExit(db, rc); - } - assert( rc!=SQLITE_OK || v->optimizable==0 ); - sqlite3_mutex_leave(db->mutex); - - return rc; -} - diff --git a/src/vdbeaux.c b/src/vdbeaux.c index d25b633dd..e524a53d7 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -53,13 +53,14 @@ Vdbe *sqlite3VdbeCreate(sqlite3 *db){ ** Remember the SQL string for a prepared statement. */ void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){ + assert( isPrepareV2==1 || isPrepareV2==0 ); if( p==0 ) return; #ifdef SQLITE_OMIT_TRACE if( !isPrepareV2 ) return; #endif assert( p->zSql==0 ); p->zSql = sqlite3DbStrNDup(p->db, z, n); - p->isPrepareV2 = isPrepareV2 ? 1 : 0; + p->isPrepareV2 = isPrepareV2; } /* @@ -3053,13 +3054,12 @@ sqlite3_value *sqlite3VdbeGetValue(Vdbe *v, int iVar, u8 aff){ ** to sqlite3_reoptimize() that re-preparing the statement may result ** in a better query plan. */ -void sqlite3VdbeSetVarmask(Vdbe *v, int iVar, int isExpire){ - u32 *mask = (isExpire ? &v->expmask : &v->optmask); +void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){ assert( iVar>0 ); if( iVar>32 ){ - *mask = 0xffffffff; + v->expmask = 0xffffffff; }else{ - *mask |= ((u32)1 << (iVar-1)); + v->expmask |= ((u32)1 << (iVar-1)); } } diff --git a/src/where.c b/src/where.c index 53ec26b84..f9cb07570 100644 --- a/src/where.c +++ b/src/where.c @@ -671,7 +671,7 @@ static int isLikeOrGlob( if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){ z = (char *)sqlite3_value_text(pVal); } - sqlite3VdbeSetVarmask(pParse->pVdbe, pRight->iColumn, 0); + sqlite3VdbeSetVarmask(pParse->pVdbe, pRight->iColumn); assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER ); }else if( op==TK_STRING ){ z = pRight->u.zToken; @@ -689,7 +689,7 @@ static int isLikeOrGlob( *ppPrefix = pPrefix; if( op==TK_VARIABLE ){ Vdbe *v = pParse->pVdbe; - sqlite3VdbeSetVarmask(v, pRight->iColumn, 1); + sqlite3VdbeSetVarmask(v, pRight->iColumn); if( *pisComplete && pRight->u.zToken[1] ){ /* If the rhs of the LIKE expression is a variable, and the current ** value of the variable means there is no need to invoke the LIKE @@ -2045,7 +2045,7 @@ static int valueFromExpr( || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE) ){ int iVar = pExpr->iColumn; - sqlite3VdbeSetVarmask(pParse->pVdbe, iVar, 0); + sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff); return SQLITE_OK; } |