Simplifications to faststat1.c. Fix a bug in sqlite3MovetoProportional() for
very large b-trees. FossilOrigin-Name: f7f78147c5d51dfb4c46b2d9afad0648f57d54f3
This commit is contained in:
@@ -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
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
b051fd19bc5b4e5805154b40beb703674f2a8ba8
|
||||
f7f78147c5d51dfb4c46b2d9afad0648f57d54f3
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+5
-102
@@ -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);
|
||||
printf("INSERT INTO sqlite_stat1 VALUES('%s',NULL,'%lld');\n", zTab, n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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; i<nBlob; i++){
|
||||
fprintf(out, "%02x", zBlob[i]);
|
||||
}
|
||||
fprintf(out, "'");
|
||||
}else{
|
||||
/* Could be an OOM, could be a zero-byte blob */
|
||||
fprintf(out, "X''");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
const unsigned char *zArg = sqlite3_value_text(X);
|
||||
int i, j;
|
||||
|
||||
if( zArg==0 ){
|
||||
fprintf(out, "NULL");
|
||||
}else{
|
||||
fprintf(out, "'");
|
||||
for(i=j=0; zArg[i]; i++){
|
||||
if( zArg[i]=='\'' ){
|
||||
fprintf(out, "%.*s'", i-j+1, &zArg[j]);
|
||||
j = i+1;
|
||||
}
|
||||
}
|
||||
fprintf(out, "%s'", &zArg[j]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SQLITE_NULL: {
|
||||
fprintf(out, "NULL");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Output SQL that will recreate the aux.zTab table.
|
||||
*/
|
||||
static void dump_table(const char *zTab, const char *zAlias){
|
||||
int i; /* Loop counter */
|
||||
int nCol; /* Number of result columns */
|
||||
sqlite3_stmt *pStmt; /* SQL statement */
|
||||
const char *zSep; /* Separator string */
|
||||
|
||||
pStmt = db_prepare("SELECT * FROM %s", zTab);
|
||||
nCol = sqlite3_column_count(pStmt);
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
printf("INSERT INTO %s VALUES", zAlias);
|
||||
zSep = "(";
|
||||
for(i=0; i<nCol; i++){
|
||||
fprintf(stdout, "%s",zSep);
|
||||
printQuoted(stdout, sqlite3_column_value(pStmt,i));
|
||||
zSep = ",";
|
||||
}
|
||||
fprintf(stdout, ");\n");
|
||||
}
|
||||
sqlite3_finalize(pStmt);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Print sketchy documentation for this utility program
|
||||
*/
|
||||
@@ -417,11 +324,7 @@ int main(int argc, char **argv){
|
||||
if( rc || zErrMsg ){
|
||||
cmdlineError("\"%s\" does not appear to be a valid SQLite database", zDb);
|
||||
}
|
||||
rc = sqlite3_exec(g.db, "CREATE TEMP TABLE est_stat1(tbl,idx,stat);",
|
||||
0, 0, &zErrMsg);
|
||||
if( rc || zErrMsg ){
|
||||
cmdlineError("Cannot CREATE TEMP TABLE");
|
||||
}
|
||||
printf("ANALYZE sqlite_master;\nDELETE FROM sqlite_stat1;\n");
|
||||
pStmt = db_prepare("SELECT name FROM sqlite_master"
|
||||
" WHERE type='table' AND rootpage>0"
|
||||
" 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user