Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -5253,12 +5253,12 @@ */ #ifdef SQLITE_DEBUG int sqlite3NoTempsInRange(Parse *pParse, int iFirst, int iLast){ int i; if( pParse->nRangeReg>0 - && pParse->iRangeReg+pParse->nRangeRegiRangeReg>=iFirst + && pParse->iRangeReg+pParse->nRangeReg > iFirst + && pParse->iRangeReg <= iLast ){ return 0; } for(i=0; inTempReg; i++){ if( pParse->aTempReg[i]>=iFirst && pParse->aTempReg[i]<=iLast ){ Index: src/pragma.c ================================================================== --- src/pragma.c +++ src/pragma.c @@ -1526,10 +1526,11 @@ } aRoot[cnt] = 0; /* Make sure sufficient number of registers have been allocated */ pParse->nMem = MAX( pParse->nMem, 8+mxIdx ); + sqlite3ClearTempRegCache(pParse); /* Do the b-tree integrity checks */ sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY); sqlite3VdbeChangeP5(v, (u8)i); addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); @@ -1940,11 +1941,12 @@ ** pragmas run by future database connections. ** ** 0x0008 (Not yet implemented) Create indexes that might have ** been helpful to recent queries ** - ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all ** of the optimizations listed above except Debug Mode, including new + ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all + ** of the optimizations listed above except Debug Mode, including new ** optimizations that have not yet been invented. If new optimizations are ** ever added that should be off by default, those off-by-default ** optimizations will have bitmasks of 0x10000 or larger. ** ** DETERMINATION OF WHEN TO RUN ANALYZE Index: test/attach.test ================================================================== --- test/attach.test +++ test/attach.test @@ -868,7 +868,23 @@ CREATE TABLE aux1.t1(x,y); INSERT INTO aux1.t1(x,y) VALUES(1,2),(3,4); SELECT * FROM aux1.t1; } {1 2 3 4} +# Ticket https://sqlite.org/src/tktview/a4e06e75a9ab61a1 2017-07-15 +# False positive when running integrity_check on a connection with +# attached databases. +# +db close +sqlite3 db :memory: +do_execsql_test attach-12.1 { + CREATE TABLE Table1 (col TEXT NOT NULL PRIMARY KEY); + ATTACH ':memory:' AS db2; + CREATE TABLE db2.Table2(col1 INTEGER, col2 INTEGER, col3 INTEGER, col4); + CREATE UNIQUE INDEX db2.idx_col1_unique ON Table2 (col1); + CREATE UNIQUE INDEX db2.idx_col23_unique ON Table2 (col2, col3); + CREATE INDEX db2.idx_col2 ON Table2 (col2); + INSERT INTO Table2 VALUES(1,2,3,4); + PRAGMA integrity_check; +} {ok} finish_test Index: tool/showstat4.c ================================================================== --- tool/showstat4.c +++ tool/showstat4.c @@ -116,12 +116,15 @@ for(j=1; j