]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Factor some work out of the index loop of the bestBtreeIndex() routine for
authordrh <drh@noemail.net>
Sat, 8 Dec 2012 22:14:29 +0000 (22:14 +0000)
committerdrh <drh@noemail.net>
Sat, 8 Dec 2012 22:14:29 +0000 (22:14 +0000)
a small performance increase.

FossilOrigin-Name: 92c9ab56b1c67b9468bec57ab1d2c483a69a2810

manifest
manifest.uuid
src/where.c

index 49f4593615d59c49ec94d004614c73db8577599a..9c89093a192661229fdead7563bbd84ac6912680 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Refactor\scollating-sequence\shandling\sas\sa\sfix\sfor\sticket\s[71e333e7d2e642].\nThe\sExpr.pColl\sfield\sis\sremoved\sfrom\sthe\sExpr\sobject.\s\sThe\sCOLLATE\soperator\nnow\sbecomes\sa\sseparate\sinstance\sof\sExpr\sin\sthe\sexpression\stree.\s\sThe\scode\ngenerator\slooks\sup\sthe\scorrect\scollating\sfunction\sas\sneeded,\srather\sthan\nreferring\sto\sExpr.pColl.
-D 2012-12-08T21:51:24.433
+C Factor\ssome\swork\sout\sof\sthe\sindex\sloop\sof\sthe\sbestBtreeIndex()\sroutine\sfor\na\ssmall\sperformance\sincrease.
+D 2012-12-08T22:14:29.324
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 690d441a758cbffd13e814dc2724a721a6ebd400
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -250,7 +250,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
 F src/wal.c f5c7b5027d0ed0e9bc9afeb4a3a8dfea762ec7d2
 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b
-F src/where.c b613cf5be71a34c85e3a85782d9ea44bba8ea373
+F src/where.c 53b991af50dab230b319b098bcb90fc7cd82da47
 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -1025,7 +1025,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 2d5f37c99a9e5377409697f5392a1ca55970964e cdbfa664839a409589ec7cebfc9111235d2f3b38
-R fd5c21e14054b78f0a72082ceca653a9
+P 8542e6180d4321d45b34f33e481658908ce1430d
+R 307714a402bf6d86beef10997fbac787
 U drh
-Z 9b6ace21d2c8985753646add41f3f044
+Z c87a5a2068dc4b6318f0ce8f3372ea0a
index 46d93323f854aaaab0667eb61c95a55a79343077..5047e5ef8116bec5ff80bb52ec489fb943376516 100644 (file)
@@ -1 +1 @@
-8542e6180d4321d45b34f33e481658908ce1430d
\ No newline at end of file
+92c9ab56b1c67b9468bec57ab1d2c483a69a2810
\ No newline at end of file
index e5e497ad01937f3d464f02d046542edcc4d5e80f..98369db6d285f2533cfa8ac0d893d4ff764cfc58 100644 (file)
@@ -3032,6 +3032,11 @@ static void bestBtreeIndex(WhereBestIdx *p){
   tRowcnt aiRowEstPk[2];      /* The aiRowEst[] value for the sPk index */
   int aiColumnPk = -1;        /* The aColumn[] value for the sPk index */
   int wsFlagMask;             /* Allowed flags in p->cost.plan.wsFlag */
+  int nPriorSat;              /* ORDER BY terms satisfied by outer loops */
+  int nOrderBy;               /* Number of ORDER BY terms */
+  char bSortInit;             /* Initializer for bSort in inner loop */
+  char bDistInit;             /* Initializer for bDist in inner loop */
+
 
   /* Initialize the cost to a worst-case value */
   memset(&p->cost, 0, sizeof(p->cost));
@@ -3081,6 +3086,17 @@ static void bestBtreeIndex(WhereBestIdx *p){
     pIdx = 0;
   }
 
+  nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0;
+  if( p->i ){
+    nPriorSat = p->aLevel[p->i-1].plan.nOBSat;
+    bSortInit = nPriorSat<nOrderBy;
+    bDistInit = 0;
+  }else{
+    nPriorSat = 0;
+    bSortInit = nOrderBy>0;
+    bDistInit = p->pDistinct!=0;
+  }
+
   /* Loop over all indices looking for the best one to use
   */
   for(; pProbe; pIdx=pProbe=pProbe->pNext){
@@ -3158,11 +3174,9 @@ static void bestBtreeIndex(WhereBestIdx *p){
     int nInMul = 1;               /* Number of distinct equalities to lookup */
     double rangeDiv = (double)1;  /* Estimated reduction in search space */
     int nBound = 0;               /* Number of range constraints seen */
-    int bSort;                    /* True if external sort required */
-    int bDist;                    /* True if index cannot help with DISTINCT */
-    int bLookup = 0;              /* True if not a covering index */
-    int nPriorSat;                /* ORDER BY terms satisfied by outer loops */
-    int nOrderBy;                 /* Number of ORDER BY terms */
+    char bSort = bSortInit;       /* True if external sort required */
+    char bDist = bDistInit;       /* True if index cannot help with DISTINCT */
+    char bLookup = 0;             /* True if not a covering index */
     WhereTerm *pTerm;             /* A single term of the WHERE clause */
 #ifdef SQLITE_ENABLE_STAT3
     WhereTerm *pFirstTerm = 0;    /* First term matching the index */
@@ -3173,16 +3187,7 @@ static void bestBtreeIndex(WhereBestIdx *p){
       pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk")
     ));
     memset(&pc, 0, sizeof(pc));
-    nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0;
-    if( p->i ){
-      nPriorSat = pc.plan.nOBSat = p->aLevel[p->i-1].plan.nOBSat;
-      bSort = nPriorSat<nOrderBy;
-      bDist = 0;
-    }else{
-      nPriorSat = pc.plan.nOBSat = 0;
-      bSort = nOrderBy>0;
-      bDist = p->pDistinct!=0;
-    }
+    pc.plan.nOBSat = nPriorSat;
 
     /* Determine the values of pc.plan.nEq and nInMul */
     for(pc.plan.nEq=0; pc.plan.nEq<pProbe->nColumn; pc.plan.nEq++){