]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Avoid change tests when analyzing single-column unique indexes after
authordrh <drh@noemail.net>
Thu, 24 Jul 2014 19:54:20 +0000 (19:54 +0000)
committerdrh <drh@noemail.net>
Thu, 24 Jul 2014 19:54:20 +0000 (19:54 +0000)
getting past the initial NULL entries.

FossilOrigin-Name: 4690e99c07024f40fafba1db8e4487b287b788a9

manifest
manifest.uuid
src/analyze.c

index c9cc80f3061cd5c7bc3bc19ccad038783b041d65..f33fbbea5191b8722abba1b0ddf6f0a36aec97cc 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Ugh.\s\sConsecutive\sUNIQUE\sindex\sentries\sare\sonly\sdistinct\sif\sthe\sindex\sis\non\sNOT\sNULL\scolumns.\s\sSo\sthe\sprevious\sversion\swas\snot\squite\sright.\s\sThis\ncheck-in\sfixes\sthe\sproblem.
-D 2014-07-23T19:37:21.314
+C Avoid\schange\stests\swhen\sanalyzing\ssingle-column\sunique\sindexes\safter\ngetting\spast\sthe\sinitial\sNULL\sentries.
+D 2014-07-24T19:54:20.150
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -161,7 +161,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
 F src/alter.c b00900877f766f116f9e16116f1ccacdc21d82f1
-F src/analyze.c 7f893416d1e4375e31e497107e92b28c2f8f82d1
+F src/analyze.c 45216a14e7e71084859d2899cd323b2f597f8527
 F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52
 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53
@@ -1183,7 +1183,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 3e1e79e1335f7ad33cd35f384f2a063c4aa2253b
-R 8df862d446d339da769e0f44096b055d
+P 30033f965030a015fad15e532bcaba1314c8cc0f
+R e98a107e1f5891c465c70c3fe5e38f27
 U drh
-Z cc08889d86841af01a0687614b9dbde8
+Z 7cfd64b5f36044a7bdee3831c72ee79f
index b9ae50e83b996cefe387e508f1dc6cadce159bec..bfe6770cbbf925bb9c8e26868dac102a0bd41014 100644 (file)
@@ -1 +1 @@
-30033f965030a015fad15e532bcaba1314c8cc0f
\ No newline at end of file
+4690e99c07024f40fafba1db8e4487b287b788a9
\ No newline at end of file
index e235389e2d726b1e2d00f67b24475cbce22d8c9a..9a64108384c2c7ce7a5f401a88191b83edc34af1 100644 (file)
@@ -1031,7 +1031,7 @@ static void analyzeOneTable(
       zIdxName = pIdx->zName;
       nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
     }
-    aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nColTest+1));
+    aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*nColTest);
     if( aGotoChng==0 ) continue;
 
     /* Populate the register containing the index name. */
@@ -1061,7 +1061,7 @@ static void analyzeOneTable(
     **   regPrev(1) = idx(1)
     **  ...
     **
-    **  chng_addr_N:
+    **  endDistinctTest:
     **   regRowid = idx(rowid)
     **   stat_push(P, regChng, regRowid)
     **   Next csr
@@ -1115,6 +1115,7 @@ static void analyzeOneTable(
     addrNextRow = sqlite3VdbeCurrentAddr(v);
 
     if( nColTest>0 ){
+      int endDistinctTest = sqlite3VdbeMakeLabel(v);
       /*
       **  next_row:
       **   regChng = 0
@@ -1123,10 +1124,17 @@ static void analyzeOneTable(
       **   if( idx(1) != regPrev(1) ) goto chng_addr_1
       **   ...
       **   regChng = N
-      **   goto chng_addr_N
+      **   goto endDistinctTest
       */
       sqlite3VdbeAddOp0(v, OP_Goto);
       addrNextRow = sqlite3VdbeCurrentAddr(v);
+      if( nColTest==1 && pIdx->nKeyCol==1 && pIdx->onError!=OE_None ){
+        /* For a single-column UNIQUE index, once we have found a non-NULL
+        ** row, we know that all the rest will be distinct, so skip 
+        ** subsequent distinctness tests. */
+        sqlite3VdbeAddOp2(v, OP_NotNull, regPrev, endDistinctTest);
+        VdbeCoverage(v);
+      }
       for(i=0; i<nColTest; i++){
         char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
         sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
@@ -1137,7 +1145,7 @@ static void analyzeOneTable(
         VdbeCoverage(v);
       }
       sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
-      aGotoChng[nColTest] = sqlite3VdbeAddOp0(v, OP_Goto);
+      sqlite3VdbeAddOp2(v, OP_Goto, 0, endDistinctTest);
   
   
       /*
@@ -1152,7 +1160,7 @@ static void analyzeOneTable(
         sqlite3VdbeJumpHere(v, aGotoChng[i]);
         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i);
       }
-      sqlite3VdbeJumpHere(v, aGotoChng[nColTest]);
+      sqlite3VdbeResolveLabel(v, endDistinctTest);
     }
   
     /*