From: drh Date: Tue, 25 Oct 2016 19:39:31 +0000 (+0000) Subject: Simplifications to faststat1.c. Fix a bug in sqlite3MovetoProportional() for X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57ad53ada4252f75dce063ff3e2fc5def5a8dbec;p=thirdparty%2Fsqlite.git Simplifications to faststat1.c. Fix a bug in sqlite3MovetoProportional() for very large b-trees. FossilOrigin-Name: f7f78147c5d51dfb4c46b2d9afad0648f57d54f3 --- diff --git a/manifest b/manifest index 20cf726cd7..cace430b2e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\srefinements\sto\sthe\sfaststat1.c\sutility. -D 2016-10-25T19:21:18.947 +C Simplifications\sto\sfaststat1.c.\s\sFix\sa\sbug\sin\ssqlite3MovetoProportional()\sfor\nvery\slarge\sb-trees. +D 2016-10-25T19:39:31.185 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f @@ -330,7 +330,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63 F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c c0921ff5144702aecc69207025c99d9182d8baf0 +F src/btree.c 4ea67e42541e8a876e469aad20d821746b9a65b3 F src/btree.h 012576c1d0000e96ccc785c6fe22b4be8211f0d9 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 F src/build.c e22e66fb34e1e50bb7869a510923bfe58db3071a @@ -1449,7 +1449,7 @@ F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 F tool/dbhash.c a06228aa21ebc4e6ea8daa486601d938499238a5 F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 -F tool/faststat1.c 61265716af50e067cd5a095f737ebde25b5179b4 +F tool/faststat1.c fd4f16c195e5a10a3181e9810776f9e03d651f28 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 F tool/fuzzershell.c f294ca67a10e87db76af130d75b2c94be36359c6 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 @@ -1528,7 +1528,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 65444f2e35cfd51ece1ba6e37b39d181da479137 -R dc5ab078ccee063ac5ecf0c1a702e09d +P b051fd19bc5b4e5805154b40beb703674f2a8ba8 +R c167cf5d4d4d8fcdea9a309e63a09e97 U drh -Z e3cb65b107952edc3d499ff83f7648af +Z 8ded4d30c76e5a6d10204f81bb1a0185 diff --git a/manifest.uuid b/manifest.uuid index d886a0bd72..793765f8c3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b051fd19bc5b4e5805154b40beb703674f2a8ba8 \ No newline at end of file +f7f78147c5d51dfb4c46b2d9afad0648f57d54f3 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index fe140e5387..e35f34eff1 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5080,6 +5080,7 @@ int sqlite3BtreeMovetoProportional( pPage = pCur->apPage[0]; while( !pPage->leaf ){ perChild = (mx+pPage->nCell)/(pPage->nCell+1); + if( perChild<1 ) perChild = 1; rx = x/perChild; x %= perChild; mx = perChild; @@ -5099,6 +5100,7 @@ int sqlite3BtreeMovetoProportional( rx = 0; }else{ perChild = mx/pPage->nCell; + if( perChild<1 ) perChild = 1; rx = x/perChild; if( rx>=pPage->nCell ) rx = pPage->nCell-1; } diff --git a/tool/faststat1.c b/tool/faststat1.c index 325afcf913..02d62ae1d8 100644 --- a/tool/faststat1.c +++ b/tool/faststat1.c @@ -236,12 +236,8 @@ static int analyzeIndex(const char *zTab, const char *zIdx){ sqlite3_snprintf(szRes-k, zRes+k, " %d", (nRow+aCnt[j]-1)/aCnt[j]); k += (int)strlen(zRes+k); } - pStmt = db_prepare( - "INSERT INTO temp.est_stat1(tbl,idx,stat)" - "VALUES(\"%w\",\"%w\",'%s')", zTab, zIdx, zRes - ); - sqlite3_step(pStmt); - sqlite3_finalize(pStmt); + printf("INSERT INTO sqlite_stat1 VALUES('%s','%s','%s');\n", + zTab, zIdx, zRes); return 1; } @@ -269,99 +265,10 @@ static void analyzeTable(const char *zTab){ } sqlite3_finalize(pStmt); if( nIndex==0 ){ - pStmt = db_prepare( - "INSERT INTO temp.est_stat1(tbl,idx,stat)" - "VALUES(\"%w\",NULL,'%lld')", zTab, n - ); - sqlite3_step(pStmt); - sqlite3_finalize(pStmt); - } -} - - -/* -** Print the sqlite3_value X as an SQL literal. -*/ -static void printQuoted(FILE *out, sqlite3_value *X){ - switch( sqlite3_value_type(X) ){ - case SQLITE_FLOAT: { - double r1; - char zBuf[50]; - r1 = sqlite3_value_double(X); - sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1); - fprintf(out, "%s", zBuf); - break; - } - case SQLITE_INTEGER: { - fprintf(out, "%lld", sqlite3_value_int64(X)); - break; - } - case SQLITE_BLOB: { - const unsigned char *zBlob = sqlite3_value_blob(X); - int nBlob = sqlite3_value_bytes(X); - if( zBlob ){ - int i; - fprintf(out, "x'"); - for(i=0; i0" " AND name NOT LIKE 'sqlite_%%'" @@ -431,7 +334,7 @@ int main(int argc, char **argv){ analyzeTable(zName); } sqlite3_finalize(pStmt); - dump_table("temp.est_stat1","sqlite_stat1"); + printf("ANALYZE sqlite_master;\n"); sqlite3_close(g.db); return 0; }