]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Suppress more instances of unnecessary OP_IsNull and OP_Affinity opcodes.
authordrh <drh@noemail.net>
Wed, 18 Nov 2009 01:25:26 +0000 (01:25 +0000)
committerdrh <drh@noemail.net>
Wed, 18 Nov 2009 01:25:26 +0000 (01:25 +0000)
FossilOrigin-Name: bf6c0bd1c5568c6292ea0a64c8a5071e1bd3079a

manifest
manifest.uuid
src/expr.c
src/sqliteInt.h
src/where.c

index a97ab5f5df3a0aa4cd63d0d724e9199946758f00..97790316a6742af5fb374358ea7c3d70c51875b8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Enhancements\sto\sthe\sVDBE\sopcode\sloop\sto\sreduce\sthe\snumber\sof\smachine-code\ninstructions\sevaluated\sby\sabout\s10%.
-D 2009-11-17T23:59:58
+C Suppress\smore\sinstances\sof\sunnecessary\sOP_IsNull\sand\sOP_Affinity\sopcodes.
+D 2009-11-18T01:25:27
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 53f3dfa49f28ab5b80cb083fb7c9051e596bcfa1
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -117,7 +117,7 @@ F src/callback.c 908f3e0172c3d4058f4ca0acd42c637c52e9669f
 F src/complete.c 417df1ef5ea798532bb6290b0cc4265fef82980a
 F src/date.c a79c0a8f219370b972e320741f995a3bef9df33f
 F src/delete.c ec04635d152debdab70d4b30c5516b59282075ea
-F src/expr.c cc086099c3afbc10bfdb506a0b5b298b0547c956
+F src/expr.c ba653dafb23a75a7dbfb2033daa9786faf1e09da
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
 F src/fkey.c e2116672a6bd610dc888e27df292ebc7999c9bb0
 F src/func.c bf54e1202cbfb28bf4b1fd9b58899009ae76716f
@@ -167,7 +167,7 @@ F src/select.c a727f61f3267bfa20ce1c3e85d38dc2132db1060
 F src/shell.c f4948cb6d30665d755a6b5e0ec313d1094aab828
 F src/sqlite.h.in 4464e9772122f0447305d425e04d122b6f1bffec
 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
-F src/sqliteInt.h 1d6795e4d56c55cff86d9b9968eab37c67307f95
+F src/sqliteInt.h e4d1e5233b2430b7e69ae551e16975304f5a60d6
 F src/sqliteLimit.h 3afab2291762b5d09ae20c18feb8e9fa935a60a6
 F src/status.c e651be6b30d397d86384c6867bc016e4913bcac7
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -219,7 +219,7 @@ F src/vdbeblob.c 84f924700a7a889152aeebef77ca5f4e3875ffb4
 F src/vdbemem.c 1e16e3a16e55f4c3452834f0e041726021aa66e0
 F src/vtab.c 456fc226614569f0e46f216e33265bea268bd917
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
-F src/where.c ef0dbd3963087e9caecf175e4669d2ef2a5735a1
+F src/where.c 6dedaffcf818448ed8de4f0992fad2e181852638
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
 F test/all.test 14165b3e32715b700b5f0cbf8f6e3833dda0be45
@@ -771,14 +771,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P ebb0c8a3e977dc741704e733b5a5d931d9b27028
-R dad6cdc4c4a1dec37df2a9a1ce7926da
+P 9744ffb3f5bc6d8fd59fbb6577a0d549411cd967
+R d36e087fc4b7b1ec197d8db8ebfd9826
 U drh
-Z 1249a61e88d85d90c0245acb22f5c40f
+Z a65e5359a57fd3c4929b703d7b9770c6
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFLAzkBoxKgR168RlERApdIAJ4+6zJDY9FY78sInSHpbNE0CiUriQCeMvQr
-4Rd5fpIsbKIZ9/+W9YH/eYE=
-=va/T
+iD8DBQFLA00KoxKgR168RlERAkR3AJ4jbQhFWv8ACVaJMpYhvyMoTvCbhgCeJfKR
+ynxCgW1AnojjISsq/wFjnvg=
+=DZuy
 -----END PGP SIGNATURE-----
index ad5fddd94f3d175555fc9931741d97e56f7e9a09..4ac93b9fc0cf0cd08fe945ad70262a8ba048fceb 100644 (file)
@@ -1 +1 @@
-9744ffb3f5bc6d8fd59fbb6577a0d549411cd967
\ No newline at end of file
+bf6c0bd1c5568c6292ea0a64c8a5071e1bd3079a
\ No newline at end of file
index db74e87594d0c88a6579eec524becbf524aa2a30..99d88f94075aa151da18077e95e8986c459edd03 100644 (file)
@@ -1288,6 +1288,24 @@ int sqlite3ExprCanBeNull(const Expr *p){
   }
 }
 
+/*
+** Generate an OP_IsNull instruction that tests register iReg and jumps
+** to location iDest if the value in iReg is NULL.  The value in iReg 
+** was computed by pExpr.  If we can look at pExpr at compile-time and
+** determine that it can never generate a NULL, then the OP_IsNull operation
+** can be omitted.
+*/
+void sqlite3ExprCodeIsNullJump(
+  Vdbe *v,            /* The VDBE under construction */
+  const Expr *pExpr,  /* Only generate OP_IsNull if this expr can be NULL */
+  int iReg,           /* Test the value in this register for NULL */
+  int iDest           /* Jump here if the value is null */
+){
+  if( sqlite3ExprCanBeNull(pExpr) ){
+    sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest);
+  }
+}
+
 /*
 ** Return TRUE if the given expression is a constant which would be
 ** unchanged by OP_Affinity with the affinity given in the second
@@ -1317,6 +1335,10 @@ int sqlite3ExprNeedsNoAffinityChange(const Expr *p, char aff){
     case TK_BLOB: {
       return 1;
     }
+    case TK_COLUMN: {
+      return p->iTable>=0 && p->iColumn<0
+               && (aff==SQLITE_AFF_INTEGER || aff==SQLITE_AFF_NUMERIC);
+    }
     default: {
       return 0;
     }
index 64c7c356fa19c141633bd03bd47989690f7f8f35..293c2446b718f61631e16a58067f22845c4746f2 100644 (file)
@@ -2675,6 +2675,7 @@ int sqlite3ExprIsConstantNotJoin(Expr*);
 int sqlite3ExprIsConstantOrFunction(Expr*);
 int sqlite3ExprIsInteger(Expr*, int*);
 int sqlite3ExprCanBeNull(const Expr*);
+void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
 int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
 int sqlite3IsRowid(const char*);
 void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int);
index 7abf7d58242a23ff9017471998d009a7508579cd..c39504047f117293fb7e79f3b685f14802df9e42 100644 (file)
@@ -2789,9 +2789,7 @@ static int codeAllEqualityTerms(
     testcase( pTerm->eOperator & WO_IN );
     if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
       Expr *pRight = pTerm->pExpr->pRight;
-      if( sqlite3ExprCanBeNull(pRight) ){
-        sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
-      }
+      sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk);
       if( zAff ){
         if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
           zAff[j] = SQLITE_AFF_NONE;
@@ -3124,7 +3122,7 @@ static Bitmask codeOneLoopStart(
     if( pRangeStart ){
       Expr *pRight = pRangeStart->pExpr->pRight;
       sqlite3ExprCode(pParse, pRight, regBase+nEq);
-      sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
+      sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
       if( zAff ){
         if( sqlite3CompareAffinity(pRight, zAff[nConstraint])==SQLITE_AFF_NONE){
           /* Since the comparison is to be performed with no conversions
@@ -3162,7 +3160,7 @@ static Bitmask codeOneLoopStart(
       Expr *pRight = pRangeEnd->pExpr->pRight;
       sqlite3ExprCacheRemove(pParse, regBase+nEq);
       sqlite3ExprCode(pParse, pRight, regBase+nEq);
-      sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
+      sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
       if( zAff ){
         if( sqlite3CompareAffinity(pRight, zAff[nConstraint])==SQLITE_AFF_NONE){
           /* Since the comparison is to be performed with no conversions