From: drh Date: Fri, 26 Aug 2011 15:51:37 +0000 (+0000) Subject: Get stat3 working after import from trunk-based the stat3-enhancement branch. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=895eab4e137e6316e64d7d646de0c4f47ff964d6;p=thirdparty%2Fsqlite.git Get stat3 working after import from trunk-based the stat3-enhancement branch. There is still a problem in the wal2 test. FossilOrigin-Name: 01cc4ff6af56a3dd08013862027bf8b91314986d --- diff --git a/manifest b/manifest index 6e6c1ff9b0..3ed964fd89 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -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 @@ -107,7 +107,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b 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 @@ -234,7 +234,7 @@ F src/where.c 9323b7a65ec9e1f9211d0cd3d21a3b048b195a39 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 @@ -853,10 +853,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff 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 diff --git a/manifest.uuid b/manifest.uuid index 93a5030b20..7d13629435 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0df04f920b3e6cfe8db7687cc9c392f65c11d9ce \ No newline at end of file +01cc4ff6af56a3dd08013862027bf8b91314986d \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index bc964bb1f7..d645637f0b 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -124,7 +124,8 @@ static void openStatTable( 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; @@ -186,7 +187,7 @@ static void openStatTable( 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. */ @@ -280,7 +281,8 @@ static const FuncDef stat3InitFuncdef = { 0, /* xStep */ 0, /* xFinalize */ "stat3_init", /* zName */ - 0 /* pHash */ + 0, /* pHash */ + 0 /* pDestructor */ }; @@ -373,7 +375,8 @@ static const FuncDef stat3PushFuncdef = { 0, /* xStep */ 0, /* xFinalize */ "stat3_push", /* zName */ - 0 /* pHash */ + 0, /* pHash */ + 0 /* pDestructor */ }; /* @@ -413,8 +416,9 @@ static const FuncDef stat3GetFuncdef = { stat3Get, /* xFunc */ 0, /* xStep */ 0, /* xFinalize */ - "stat3_get", /* zName */ - 0 /* pHash */ + "stat3_get", /* zName */ + 0, /* pHash */ + 0 /* pDestructor */ }; #endif /* SQLITE_ENABLE_STAT3 */ @@ -428,6 +432,7 @@ static const FuncDef stat3GetFuncdef = { 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 */ ){ @@ -438,8 +443,7 @@ static void analyzeOneTable( 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 */ @@ -464,6 +468,7 @@ static void analyzeOneTable( int regTemp = iMem++; /* Temporary use register */ int regNewRowid = iMem++; /* Rowid for the inserted record */ + v = sqlite3GetVdbe(pParse); if( v==0 || NEVER(pTab==0) ){ return; @@ -492,11 +497,12 @@ static void analyzeOneTable( 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); @@ -655,7 +661,7 @@ static void analyzeOneTable( ** is never possible. */ sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regStat1); - if( jZeroRows==0 ){ + if( jZeroRows<0 ){ jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem); } for(i=0; i0 ); - 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); @@ -693,9 +698,7 @@ static void analyzeOneTable( sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid); sqlite3VdbeChangeP5(v, OPFLAG_APPEND); if( pParse->nMemnMem = regRec; - if( jZeroRows ){ - sqlite3VdbeJumpHere(v, addr); - } + sqlite3VdbeJumpHere(v, jZeroRows); } @@ -723,20 +726,21 @@ static void analyzeDatabase(Parse *pParse, int iDb){ 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; @@ -746,8 +750,12 @@ static void analyzeTable(Parse *pParse, Table *pTab){ 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); } @@ -769,6 +777,7 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ int i; char *z, *zDb; Table *pTab; + Index *pIdx; Token *pTableName; /* Read the database schema. If an error occurs, leave an error message @@ -793,11 +802,12 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ }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{ @@ -807,11 +817,12 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ 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); } } } @@ -1065,7 +1076,6 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ assert( iDb>=0 && iDbnDb ); 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)){ diff --git a/test/alter.test b/test/alter.test index fc23112888..bf7cf00624 100644 --- a/test/alter.test +++ b/test/alter.test @@ -840,24 +840,4 @@ do_test alter-14.2 { } {1 {Cannot add a PRIMARY KEY column}} -#------------------------------------------------------------------------- -# Test that it is not possible to use ALTER TABLE on any system table. -# -set system_table_list {1 sqlite_master} -catchsql ANALYZE -ifcapable analyze { lappend system_table_list 2 sqlite_stat1 } -ifcapable stat2 { lappend system_table_list 3 sqlite_stat2 } -ifcapable stat3 { lappend system_table_list 4 sqlite_stat3 } - -foreach {tn tbl} $system_table_list { - do_test alter-15.$tn.1 { - catchsql "ALTER TABLE $tbl RENAME TO xyz" - } [list 1 "table $tbl may not be altered"] - - do_test alter-15.$tn.2 { - catchsql "ALTER TABLE $tbl ADD COLUMN xyz" - } [list 1 "table $tbl may not be altered"] -} - - finish_test