From: drh Date: Thu, 22 Aug 2013 02:56:28 +0000 (+0000) Subject: Defer the creation of automatic indices until the index is actually used. X-Git-Tag: version-3.8.0~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc04afdad03905e34e32db7f47ceca9ff0f29d08;p=thirdparty%2Fsqlite.git Defer the creation of automatic indices until the index is actually used. FossilOrigin-Name: 0775501acf152dcbf4dd039f4511f3d8c4330d85 --- diff --git a/manifest b/manifest index 07c1642183..18542bbdc3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sthe\sbtreeGetPage()\sroutine\sso\sthat\sit\suses\sa\ssingle\sflag\sparameter\nin\splace\sof\stwo\sboolean\sparameters. -D 2013-08-21T23:42:32.077 +C Defer\sthe\screation\sof\sautomatic\sindices\suntil\sthe\sindex\sis\sactually\sused. +D 2013-08-22T02:56:28.029 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 0ced8882cadbf1817904331a5d942b30ebe0e789 +F src/where.c 8596edcfbffc6d26a9a4f8e4a41d09f058dd7037 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 9ae1f9ce7ea6beaeddc3711080b3796e05acc4f8 -R 14b54904acb5b4b4c7c51baf723290ac +P 617e23ec283d3147fc3fd29c474ccedf4915cdc7 +R c8cf06f49dffbef3bb0170f8252069c7 U drh -Z 0a305d97c258e659e4da204fe193224d +Z c5e5b20d4589a0c600c887ab3fa62d4e diff --git a/manifest.uuid b/manifest.uuid index f6dfd7fe75..296e198d71 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -617e23ec283d3147fc3fd29c474ccedf4915cdc7 \ No newline at end of file +0775501acf152dcbf4dd039f4511f3d8c4330d85 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 23a35fa790..1375c585e1 100644 --- a/src/where.c +++ b/src/where.c @@ -90,6 +90,7 @@ struct WhereLevel { int addrNxt; /* Jump here to start the next IN combination */ int addrCont; /* Jump here to continue with the next loop cycle */ int addrFirst; /* First instruction of interior of the loop */ + int addrBody; /* Beginning of the body of this loop */ u8 iFrom; /* Which entry in the FROM clause */ u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */ int p1, p2; /* Operands of the opcode used to ends the loop */ @@ -5984,11 +5985,6 @@ WhereInfo *sqlite3WhereBegin( }else{ sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); } -#ifndef SQLITE_OMIT_AUTOMATIC_INDEX - if( (pLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ - constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel); - }else -#endif if( pLoop->wsFlags & WHERE_INDEXED ){ Index *pIx = pLoop->u.btree.pIndex; KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx); @@ -6013,7 +6009,15 @@ WhereInfo *sqlite3WhereBegin( notReady = ~(Bitmask)0; for(ii=0; iia[ii]; +#ifndef SQLITE_OMIT_AUTOMATIC_INDEX + if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ + constructAutomaticIndex(pParse, &pWInfo->sWC, + &pTabList->a[pLevel->iFrom], notReady, pLevel); + if( db->mallocFailed ) goto whereBeginError; + } +#endif explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags); + pLevel->addrBody = sqlite3VdbeCurrentAddr(v); notReady = codeOneLoopStart(pWInfo, ii, notReady); pWInfo->iContinue = pLevel->addrCont; } @@ -6133,9 +6137,10 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ int k, j, last; VdbeOp *pOp; - pOp = sqlite3VdbeGetOp(v, pWInfo->iTop); last = sqlite3VdbeCurrentAddr(v); - for(k=pWInfo->iTop; kaddrBody; + pOp = sqlite3VdbeGetOp(v, k); + for(; kp1!=pLevel->iTabCur ) continue; if( pOp->opcode==OP_Column ){ for(j=0; jnColumn; j++){