1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

Cleanup and refactor parts of the optimizer. (CVS 3301)

FossilOrigin-Name: 6609c25fbfa5ad7f55c356936abb1721686c47ca
This commit is contained in:
drh
2006-06-27 02:33:40 +00:00
parent 6d209d8b0d
commit 9861a9f065
3 changed files with 22 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
C Cache\sand\sreuse\svirtual\stable\sindex\sinformation\sin\sthe\soptimizer.\nImproved\sdiagnostics\sfor\svirtual\stable\sindex\sselection.\s(CVS\s3300) C Cleanup\sand\srefactor\sparts\sof\sthe\soptimizer.\s(CVS\s3301)
D 2006-06-27T01:54:26 D 2006-06-27T02:33:40
F Makefile.in f839b470345d3cb4b0644068474623fe2464b5d3 F Makefile.in f839b470345d3cb4b0644068474623fe2464b5d3
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -105,7 +105,7 @@ F src/vdbeaux.c bb0a7b800a7167f2e49702a2bfc971919c0b99d1
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3 F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3
F src/vtab.c 4751954e26e9caa6ce3ea5ad9468bd34f07d1de7 F src/vtab.c 4751954e26e9caa6ce3ea5ad9468bd34f07d1de7
F src/where.c 676105f882af3e58fd4cf75fb51746f8e9f70bdc F src/where.c f794d15f5f0503b7b5cdb3fa49fd1f76c015e80d
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/all.test 5df90d015ca63fcef2a4b62c24f7316b66c4bfd4 F test/all.test 5df90d015ca63fcef2a4b62c24f7316b66c4bfd4
@@ -374,7 +374,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 1ca385bb39514cb73f506bfbbe38aabb6b70816c P 28413cf2b3f0e6f294e1f3c59fcce135b65c294f
R 68db026572948c11690ddd8e3fadf452 R 241cba895df62f4aae2eec3dd91bf438
U drh U drh
Z b6129eea235de4e5615a497f90bd0807 Z e0a333826629d40e18f9e44a948284ff

View File

@@ -1 +1 @@
28413cf2b3f0e6f294e1f3c59fcce135b65c294f 6609c25fbfa5ad7f55c356936abb1721686c47ca

View File

@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting ** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer". ** indices, you might also think of this module as the "query optimizer".
** **
** $Id: where.c,v 1.224 2006/06/27 01:54:26 drh Exp $ ** $Id: where.c,v 1.225 2006/06/27 02:33:40 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -1856,7 +1856,6 @@ WhereInfo *sqlite3WhereBegin(
} }
assert( pTabItem->pTab ); assert( pTabItem->pTab );
#ifndef SQLITE_OMIT_VIRTUALTABLE #ifndef SQLITE_OMIT_VIRTUALTABLE
pIndex = 0;
if( IsVirtual(pTabItem->pTab) ){ if( IsVirtual(pTabItem->pTab) ){
sqlite3_index_info **ppIdxInfo = &pWInfo->a[j].pIdxInfo; sqlite3_index_info **ppIdxInfo = &pWInfo->a[j].pIdxInfo;
cost = bestVirtualIndex(pParse, &wc, pTabItem, notReady, cost = bestVirtualIndex(pParse, &wc, pTabItem, notReady,
@@ -1875,6 +1874,7 @@ WhereInfo *sqlite3WhereBegin(
cost = bestIndex(pParse, &wc, pTabItem, notReady, cost = bestIndex(pParse, &wc, pTabItem, notReady,
(i==0 && ppOrderBy) ? *ppOrderBy : 0, (i==0 && ppOrderBy) ? *ppOrderBy : 0,
&pIdx, &flags, &nEq); &pIdx, &flags, &nEq);
pIndex = 0;
} }
if( cost<lowestCost ){ if( cost<lowestCost ){
once = 1; once = 1;
@@ -1883,9 +1883,7 @@ WhereInfo *sqlite3WhereBegin(
bestFlags = flags; bestFlags = flags;
bestNEq = nEq; bestNEq = nEq;
bestJ = j; bestJ = j;
#ifndef SQLITE_OMIT_VIRTUALTABLE
pLevel->pBestIdx = pIndex; pLevel->pBestIdx = pIndex;
#endif
} }
if( doNotReorder ) break; if( doNotReorder ) break;
} }
@@ -1921,7 +1919,6 @@ WhereInfo *sqlite3WhereBegin(
** searching those tables. ** searching those tables.
*/ */
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
pLevel = pWInfo->a;
for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
Table *pTab; /* Table to open */ Table *pTab; /* Table to open */
Index *pIx; /* Index used to access pTab (if any) */ Index *pIx; /* Index used to access pTab (if any) */
@@ -2036,7 +2033,7 @@ WhereInfo *sqlite3WhereBegin(
/* Case 0: The table is a virtual-table. Use the VFilter and VNext /* Case 0: The table is a virtual-table. Use the VFilter and VNext
** to access the data. ** to access the data.
*/ */
int ii; int j;
sqlite3_index_info *pBestIdx = pLevel->pBestIdx; sqlite3_index_info *pBestIdx = pLevel->pBestIdx;
int nConstraint = pBestIdx->nConstraint; int nConstraint = pBestIdx->nConstraint;
struct sqlite3_index_constraint_usage *aUsage = struct sqlite3_index_constraint_usage *aUsage =
@@ -2044,25 +2041,26 @@ WhereInfo *sqlite3WhereBegin(
const struct sqlite3_index_constraint *aConstraint = const struct sqlite3_index_constraint *aConstraint =
pBestIdx->aConstraint; pBestIdx->aConstraint;
for(ii=1; ii<=nConstraint; ii++){ for(j=1; j<=nConstraint; j++){
int j; int k;
for(j=0; j<nConstraint; j++){ for(k=0; k<nConstraint; k++){
if( aUsage[j].argvIndex==ii ){ if( aUsage[k].argvIndex==j ){
int k = aConstraint[j].iTermOffset; int iTerm = aConstraint[j-1].iTermOffset;
sqlite3ExprCode(pParse, wc.a[k].pExpr->pRight); sqlite3ExprCode(pParse, wc.a[iTerm].pExpr->pRight);
break; break;
} }
} }
if( j==nConstraint ) break; if( k==nConstraint ) break;
} }
sqlite3VdbeAddOp(v, OP_Integer, ii-1, 0); sqlite3VdbeAddOp(v, OP_Integer, j-1, 0);
sqlite3VdbeAddOp(v, OP_Integer, pBestIdx->idxNum, 0); sqlite3VdbeAddOp(v, OP_Integer, pBestIdx->idxNum, 0);
sqlite3VdbeOp3(v, OP_VFilter, iCur, brk, pBestIdx->idxStr, sqlite3VdbeOp3(v, OP_VFilter, iCur, brk, pBestIdx->idxStr,
pBestIdx->needToFreeIdxStr ? P3_MPRINTF : P3_STATIC); pBestIdx->needToFreeIdxStr ? P3_MPRINTF : P3_STATIC);
pBestIdx->needToFreeIdxStr = 0; pBestIdx->needToFreeIdxStr = 0;
for(ii=0; ii<pBestIdx->nConstraint; ii++){ for(j=0; j<pBestIdx->nConstraint; j++){
if( pBestIdx->aConstraintUsage[ii].omit ){ if( aUsage[j].omit ){
disableTerm(pLevel, &wc.a[ii]); int iTerm = aConstraint[j].iTermOffset;
disableTerm(pLevel, &wc.a[iTerm]);
} }
} }
pLevel->op = OP_VNext; pLevel->op = OP_VNext;