-C Merge\sbranches\sbranch-3.7.2\sand\sstat3-enhancement\sinto\sa\snew\sbranch\sfor\ntesting\spurposes.
-D 2011-08-26T13:52:23.174
+C Get\sstat3\sworking\safter\simport\sfrom\strunk-based\sthe\sstat3-enhancement\sbranch.\nThere\sis\sstill\sa\sproblem\sin\sthe\swal2\stest.
+D 2011-08-26T15:51:37.923
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 543f91f24cd7fee774ecc0a61c19704c0c3e78fd
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
F src/alter.c 8dc27638e7e2553e80b2b621f232be5eb1e85ef3
-F src/analyze.c 107333cc6c89fe7887609979ac024f2226bb43b4
+F src/analyze.c 4653643860c91fb7c507ad7130e0d680223041be
F src/attach.c c689d516ee8cc52bf11bef2067d76eb8b716228a
F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
F src/backup.c 8ff0b7018df253c7f30d3f9702b0b16f19209d5c
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
F test/all.test 6745008c144bd2956d58864d21f7b304689c1cce
-F test/alter.test 328d2daaeb8aa6801b47bd5e80bddf5c5d3623a9
+F test/alter.test 15f9224868b290d6bf7a63f31437f31aee070636
F test/alter2.test 52096b711afe5f219e575c6db7a70f7a35df4f63
F test/alter3.test 25b95a136708f22b87184fa6a4309eea03d65153
F test/alter4.test 9386ffd1e9c7245f43eca412b2058d747509cc1f
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P d55b64ef7e04e10a31360dea55751a33a0d591a4 eaf447ea87b0ff29ae06283204f522fcd005b284
-R 58ef93486807718798db02129bd46bb2
-T *branch * stat3-3.7.2
-T *sym-stat3-3.7.2 *
-T -sym-branch-3.7.2 *
+P 0df04f920b3e6cfe8db7687cc9c392f65c11d9ce
+R c6188bdc4814ef578da2c9218e5e3bbd
U drh
-Z 412311c28c86c46b8114a70551171453
+Z 0fcbce733956a38903ab15fa2b257361
Parse *pParse, /* Parsing context */
int iDb, /* The database we are looking in */
int iStatCur, /* Open the sqlite_stat1 table on this cursor */
- const char *zWhere /* Delete entries associated with this table */
+ const char *zWhere, /* Delete entries for this table or index */
+ const char *zWhereType /* Either "tbl" or "idx" */
){
static const struct {
const char *zName;
sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
if( zWhere ){
sqlite3NestedParse(pParse,
- "DELETE FROM %Q.%s WHERE tbl=%Q", pDb->zName, zTab, zWhere
+ "DELETE FROM %Q.%s WHERE %s=%Q", pDb->zName, zTab, zWhereType, zWhere
);
}else{
/* The sqlite_stat[12] table already exists. Delete all rows. */
0, /* xStep */
0, /* xFinalize */
"stat3_init", /* zName */
- 0 /* pHash */
+ 0, /* pHash */
+ 0 /* pDestructor */
};
0, /* xStep */
0, /* xFinalize */
"stat3_push", /* zName */
- 0 /* pHash */
+ 0, /* pHash */
+ 0 /* pDestructor */
};
/*
stat3Get, /* xFunc */
0, /* xStep */
0, /* xFinalize */
- "stat3_get", /* zName */
- 0 /* pHash */
+ "stat3_get", /* zName */
+ 0, /* pHash */
+ 0 /* pDestructor */
};
#endif /* SQLITE_ENABLE_STAT3 */
static void analyzeOneTable(
Parse *pParse, /* Parser context */
Table *pTab, /* Table whose indices are to be analyzed */
+ Index *pOnlyIdx, /* If not NULL, only analyze this one index */
int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
int iMem /* Available memory locations begin here */
){
int i; /* Loop counter */
int topOfLoop; /* The top of the loop */
int endOfLoop; /* The end of the loop */
- int addr = 0; /* The address of an instruction */
- int jZeroRows = 0; /* Jump from here if number of rows is zero */
+ int jZeroRows = -1; /* Jump from here if number of rows is zero */
int iDb; /* Index of database containing pTab */
int regTabname = iMem++; /* Register containing table name */
int regIdxname = iMem++; /* Register containing index name */
int regTemp = iMem++; /* Temporary use register */
int regNewRowid = iMem++; /* Rowid for the inserted record */
+
v = sqlite3GetVdbe(pParse);
if( v==0 || NEVER(pTab==0) ){
return;
iIdxCur = pParse->nTab++;
sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
- int nCol = pIdx->nColumn;
- KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
+ int nCol;
+ KeyInfo *pKey;
int addrIfNot = 0; /* address of OP_IfNot */
int *aChngAddr; /* Array of jump instruction addresses */
+ if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
VdbeNoopComment((v, "Begin analysis of %s", pIdx->zName));
nCol = pIdx->nColumn;
aChngAddr = sqlite3DbMallocRaw(db, sizeof(int)*nCol);
** is never possible.
*/
sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regStat1);
- if( jZeroRows==0 ){
+ if( jZeroRows<0 ){
jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem);
}
for(i=0; i<nCol; i++){
sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
}else{
- assert( jZeroRows>0 );
- addr = sqlite3VdbeAddOp0(v, OP_Goto);
sqlite3VdbeJumpHere(v, jZeroRows);
+ jZeroRows = sqlite3VdbeAddOp0(v, OP_Goto);
}
sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid);
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
if( pParse->nMem<regRec ) pParse->nMem = regRec;
- if( jZeroRows ){
- sqlite3VdbeJumpHere(v, addr);
- }
+ sqlite3VdbeJumpHere(v, jZeroRows);
}
sqlite3BeginWriteOperation(pParse, 0, iDb);
iStatCur = pParse->nTab;
pParse->nTab += 3;
- openStatTable(pParse, iDb, iStatCur, 0);
+ openStatTable(pParse, iDb, iStatCur, 0, 0);
iMem = pParse->nMem+1;
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
Table *pTab = (Table*)sqliteHashData(k);
- analyzeOneTable(pParse, pTab, iStatCur, iMem);
+ analyzeOneTable(pParse, pTab, 0, iStatCur, iMem);
}
loadAnalysis(pParse, iDb);
}
/*
** Generate code that will do an analysis of a single table in
-** a database.
+** a database. If pOnlyIdx is not NULL then it is a single index
+** in pTab that should be analyzed.
*/
-static void analyzeTable(Parse *pParse, Table *pTab){
+static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){
int iDb;
int iStatCur;
sqlite3BeginWriteOperation(pParse, 0, iDb);
iStatCur = pParse->nTab;
pParse->nTab += 3;
- openStatTable(pParse, iDb, iStatCur, pTab->zName);
- analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem+1);
+ if( pOnlyIdx ){
+ openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");
+ }else{
+ openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");
+ }
+ analyzeOneTable(pParse, pTab, pOnlyIdx, iStatCur, pParse->nMem+1);
loadAnalysis(pParse, iDb);
}
int i;
char *z, *zDb;
Table *pTab;
+ Index *pIdx;
Token *pTableName;
/* Read the database schema. If an error occurs, leave an error message
}else{
z = sqlite3NameFromToken(db, pName1);
if( z ){
- pTab = sqlite3LocateTable(pParse, 0, z, 0);
- sqlite3DbFree(db, z);
- if( pTab ){
- analyzeTable(pParse, pTab);
+ if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
+ analyzeTable(pParse, pIdx->pTable, pIdx);
+ }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){
+ analyzeTable(pParse, pTab, 0);
}
+ sqlite3DbFree(db, z);
}
}
}else{
zDb = db->aDb[iDb].zName;
z = sqlite3NameFromToken(db, pTableName);
if( z ){
- pTab = sqlite3LocateTable(pParse, 0, z, zDb);
- sqlite3DbFree(db, z);
- if( pTab ){
- analyzeTable(pParse, pTab);
+ if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
+ analyzeTable(pParse, pIdx->pTable, pIdx);
+ }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
+ analyzeTable(pParse, pTab, 0);
}
+ sqlite3DbFree(db, z);
}
}
}
assert( iDb>=0 && iDb<db->nDb );
assert( db->aDb[iDb].pBt!=0 );
- assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
/* Clear any prior statistics */
for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){