]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix an issue in ANALYZE when STAT3 is disabled but both sqlite_stat2 and
authordrh <drh@noemail.net>
Thu, 22 Sep 2011 18:46:34 +0000 (18:46 +0000)
committerdrh <drh@noemail.net>
Thu, 22 Sep 2011 18:46:34 +0000 (18:46 +0000)
sqlite_stat3 tables exist.  Also add testability tweaks to the STAT3 code.

FossilOrigin-Name: 3ca7e449e2e20d95e516cf7fe87bfa0b51c07086

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

index 0e783c5618287d28ecb4f2c9ff31bdc53901c646..d4e2d30b7bcc4871b8d4427211947f3f12c620bd 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\suninitialized\svariable\sand\sa\smisuse\sof\smemcpy().
-D 2011-09-22T00:28:55.958
+C Fix\san\sissue\sin\sANALYZE\swhen\sSTAT3\sis\sdisabled\sbut\sboth\ssqlite_stat2\sand\nsqlite_stat3\stables\sexist.\s\sAlso\sadd\stestability\stweaks\sto\sthe\sSTAT3\scode.
+D 2011-09-22T18:46:34.844
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in d314143fa6be24828021d3f583ad37d9afdce505
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -118,7 +118,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
 F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
 F src/alter.c ac80a0f31189f8b4a524ebf661e47e84536ee7f5
-F src/analyze.c 78a513d6229689c40252aa5d820565bcba90634c
+F src/analyze.c 12c096a7e2383559c451c7111938a2682661795a
 F src/attach.c 12c6957996908edc31c96d7c68d4942c2474405f
 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c 28a4fe55327ff708bfaf9d4326d02686f7a553c3
@@ -183,7 +183,7 @@ F src/select.c d9b7d20b0365f80761846f00ef3638d4b33eeaf2
 F src/shell.c 13fe2aeddc3cc90d6a273831d1f63736d1596f81
 F src/sqlite.h.in 3f531daa04457e83bc13765c98c06c7d71c27fa5
 F src/sqlite3ext.h 1a1a4f784aa9c3b00edd287940197de52487cd93
-F src/sqliteInt.h 6cb04e5216d68becf18fd4a4a6d47ec07f33219c
+F src/sqliteInt.h 40bc71ab0840027d0b4e452b09467dc7274828e2
 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 7ac64842c86cec2fc1a1d0e5c16d3beb8ad332bf
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -251,7 +251,7 @@ F src/vtab.c 901791a47318c0562cd0c676a2c6ff1bc530e582
 F src/wal.c 3154756177d6219e233d84291d5b05f4e06ff5e9
 F src/wal.h 66b40bd91bc29a5be1c88ddd1f5ade8f3f48728a
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
-F src/where.c bd9ca1bb5ab909b04bdba6da2fffdfe07207c655
+F src/where.c 432a42cf4392bafe80ff06affb62cc24c8eea3fb
 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
@@ -965,7 +965,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5
 F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
-P 63fc3e4bea6a7f5dc34b2af83f30458eb10b8fe0
-R 21208cbb3e90ead0385f6f34c9d78ada
+P ee110d5a4a6f29400bb632a9a18c7dcd04638657
+R ed357b44bde952eee8192d464b59f2eb
 U drh
-Z 173e771ada64f444efa1679d0416f2ab
+Z b3542caa8ec714ec974a1ed2d471f84c
index bcbf1257fb4c632ccf199e091fd19b9ab6b39e94..353f35070c96e0c6616cda53a55a053646cb7981 100644 (file)
@@ -1 +1 @@
-ee110d5a4a6f29400bb632a9a18c7dcd04638657
\ No newline at end of file
+3ca7e449e2e20d95e516cf7fe87bfa0b51c07086
\ No newline at end of file
index 251560f14ed3d50c34dba67673bbb21aa61fa553..b1af3bf70ad156f23da0eeebe1a2e4db1250177a 100644 (file)
@@ -172,7 +172,10 @@ static void openStatTable(
   */
   for(i=0; i<ArraySize(azToDrop); i++){
     Table *pTab = sqlite3FindTable(db, azToDrop[i], pDb->zName);
-    if( pTab ) sqlite3CodeDropTable(pParse, pTab, iDb, 0);
+    if( pTab ){
+      sqlite3CodeDropTable(pParse, pTab, iDb, 0);
+      break;
+    }
   }
 
   /* Create new statistic tables if they do not exist, or clear them
@@ -338,9 +341,8 @@ static void stat3Push(
   }
   if( !doInsert ) return;
   if( p->nSample==p->mxSample ){
-    if( iMin<p->nSample ){
-      memmove(&p->a[iMin], &p->a[iMin+1], sizeof(p->a[0])*(p->nSample-iMin-1));
-    }
+    assert( p->nSample - iMin - 1 >= 0 );
+    memmove(&p->a[iMin], &p->a[iMin+1], sizeof(p->a[0])*(p->nSample-iMin-1));
     pSample = &p->a[p->nSample-1];
   }else{
     pSample = &p->a[p->nSample++];
@@ -413,10 +415,10 @@ static void stat3Get(
   assert( p!=0 );
   if( p->nSample<=n ) return;
   switch( argc ){
-    case 2: sqlite3_result_int64(context, p->a[n].iRowid); break;
-    case 3: sqlite3_result_int64(context, p->a[n].nEq);    break;
-    case 4: sqlite3_result_int64(context, p->a[n].nLt);    break;
-    case 5: sqlite3_result_int64(context, p->a[n].nDLt);   break;
+    case 2:  sqlite3_result_int64(context, p->a[n].iRowid); break;
+    case 3:  sqlite3_result_int64(context, p->a[n].nEq);    break;
+    case 4:  sqlite3_result_int64(context, p->a[n].nLt);    break;
+    default: sqlite3_result_int64(context, p->a[n].nDLt);   break;
   }
 }
 static const FuncDef stat3GetFuncdef = {
@@ -972,6 +974,7 @@ static int loadStat3(sqlite3 *db, const char *zDb){
     pIdx = sqlite3FindIndex(db, zIndex, zDb);
     if( pIdx==0 ) continue;
     assert( pIdx->nSample==0 );
+    testcase( nSample==255 );
     pIdx->nSample = (u8)nSample;
     pIdx->aSample = sqlite3MallocZero( nSample*sizeof(IndexSample) );
     pIdx->avgEq = pIdx->aiRowEst[1];
@@ -1042,8 +1045,7 @@ static int loadStat3(sqlite3 *db, const char *zDb){
               sqlite3_column_text(pStmt, 4)
            );
         int n = z ? sqlite3_column_bytes(pStmt, 4) : 0;
-        if( n>0xffff ) n = 0xffff;
-        pSample->nByte = (u16)n;
+        pSample->nByte = n;
         if( n < 1){
           pSample->u.z = 0;
         }else{
index 75bafe81a61ebc484dee49c6fd9daa2372b623ed..6f92a1a41e1980cea8c41ed64f288e92c87e1e74 100644 (file)
@@ -1524,7 +1524,7 @@ struct IndexSample {
     i64 i;          /* Value if eType is SQLITE_INTEGER */
   } u;
   u8 eType;         /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
-  u16 nByte;        /* Size in byte of text or blob. */
+  int nByte;        /* Size in byte of text or blob. */
   tRowcnt nEq;      /* Est. number of rows where the key equals this sample */
   tRowcnt nLt;      /* Est. number of rows where key is less than this sample */
   tRowcnt nDLt;     /* Est. number of distinct keys less than this sample */
index db076ebaf00011e66245fa9f2a1c999ff4a4beb3..bf6b52752fff1af099a025dc4cc5c71963b24a09 100644 (file)
@@ -2452,6 +2452,7 @@ static int whereKeyStats(
   double r, rS;
 
   assert( roundUp==0 || roundUp==1 );
+  assert( pIdx->nSample>0 );
   if( pVal==0 ) return SQLITE_ERROR;
   n = pIdx->aiRowEst[0];
   aSample = pIdx->aSample;
@@ -2494,7 +2495,7 @@ static int whereKeyStats(
     }
   }else if( eType==SQLITE_NULL ){
     i = 0;
-    if( pIdx->nSample>=1 && aSample[0].eType==SQLITE_NULL ) isEq = 1;
+    if( aSample[0].eType==SQLITE_NULL ) isEq = 1;
   }else{
     assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
     for(i=0; i<pIdx->nSample; i++){
@@ -2760,6 +2761,7 @@ static int whereEqualScanEst(
   tRowcnt a[2];             /* Statistics */
 
   assert( p->aSample!=0 );
+  assert( p->nSample>0 );
   aff = p->pTable->aCol[p->aiColumn[0]].affinity;
   if( pExpr ){
     rc = valueFromExpr(pParse, pExpr, aff, &pRhs);