mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-22 20:22:44 +03:00
Factor out common operations into whereLoopAddAll(). Add stubs for
missing features. FossilOrigin-Name: 0278e420614e02fb2d8474ed99b0904275882dfe
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Merge\sin\sthe\slatest\strunk\schanges.
|
C Factor\sout\scommon\soperations\sinto\swhereLoopAddAll().\s\sAdd\sstubs\sfor\nmissing\sfeatures.
|
||||||
D 2013-05-10T02:11:40.008
|
D 2013-05-10T03:30:49.076
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111
|
F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -264,7 +264,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
|
|||||||
F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d
|
F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d
|
||||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||||
F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
|
F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
|
||||||
F src/where.c 4816e3ec624c96b5169f0cc83dbb5cf459ce3fd1
|
F src/where.c 31160bacc36e1fa5818caf091d5559d55eae7a5d
|
||||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||||
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
|
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
|
||||||
@@ -1062,7 +1062,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||||
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||||
P 82d50e198025a2fdb8ee733edb8419d388ee5362 cf5c3642247fdd34d87f0368594cd7b8f081636a
|
P 5ed31c8279a4f465b982df5dc20cefc286928b93
|
||||||
R bed3d93321566d3c8fda15cb3370678a
|
R 6a6b39040b040f90ce4281cc062a3caa
|
||||||
U drh
|
U drh
|
||||||
Z 9d7433ee1472cd0008b2ab99b16fa998
|
Z ca90367b6425b581381608ce8a76b4fa
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
5ed31c8279a4f465b982df5dc20cefc286928b93
|
0278e420614e02fb2d8474ed99b0904275882dfe
|
||||||
65
src/where.c
65
src/where.c
@@ -5309,7 +5309,6 @@ static int whereLoopAddBtreeIndex(
|
|||||||
*/
|
*/
|
||||||
static int whereLoopAddBtree(
|
static int whereLoopAddBtree(
|
||||||
WhereLoopBuilder *pBuilder, /* WHERE clause information */
|
WhereLoopBuilder *pBuilder, /* WHERE clause information */
|
||||||
int iTab, /* The table to process */
|
|
||||||
Bitmask mExtra /* Extra prerequesites for using this table */
|
Bitmask mExtra /* Extra prerequesites for using this table */
|
||||||
){
|
){
|
||||||
Index *pProbe; /* An index we are evaluating */
|
Index *pProbe; /* An index we are evaluating */
|
||||||
@@ -5317,14 +5316,11 @@ static int whereLoopAddBtree(
|
|||||||
tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
|
tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
|
||||||
int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
|
int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
|
||||||
struct SrcList_item *pSrc; /* The FROM clause btree term to add */
|
struct SrcList_item *pSrc; /* The FROM clause btree term to add */
|
||||||
sqlite3 *db; /* The database connection */
|
|
||||||
WhereLoop *pNew; /* Template WhereLoop object */
|
WhereLoop *pNew; /* Template WhereLoop object */
|
||||||
int rc = SQLITE_OK; /* Return code */
|
int rc = SQLITE_OK; /* Return code */
|
||||||
|
|
||||||
pNew = pBuilder->pNew;
|
pNew = pBuilder->pNew;
|
||||||
db = pBuilder->db;
|
pSrc = pBuilder->pTabList->a + pNew->iTab;
|
||||||
pSrc = pBuilder->pTabList->a + iTab;
|
|
||||||
pNew->maskSelf = getMask(pBuilder->pWC->pMaskSet, pSrc->iCursor);
|
|
||||||
|
|
||||||
if( pSrc->pIndex ){
|
if( pSrc->pIndex ){
|
||||||
/* An INDEXED BY clause specifies a particular index to use */
|
/* An INDEXED BY clause specifies a particular index to use */
|
||||||
@@ -5353,23 +5349,21 @@ static int whereLoopAddBtree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Insert a full table scan */
|
/* Insert a full table scan */
|
||||||
pNew->iTab = iTab;
|
|
||||||
pNew->u.btree.nEq = 0;
|
pNew->u.btree.nEq = 0;
|
||||||
pNew->nTerm = 0;
|
pNew->nTerm = 0;
|
||||||
pNew->rSetup = (double)0;
|
pNew->rSetup = (double)0;
|
||||||
pNew->prereq = 0;
|
pNew->prereq = mExtra;
|
||||||
pNew->u.btree.pIndex = 0;
|
pNew->u.btree.pIndex = 0;
|
||||||
pNew->wsFlags = 0;
|
pNew->wsFlags = 0;
|
||||||
pNew->rRun = (double)pSrc->pTab->nRowEst;
|
pNew->rRun = (double)pSrc->pTab->nRowEst;
|
||||||
pNew->nOut = (double)pSrc->pTab->nRowEst;
|
pNew->nOut = (double)pSrc->pTab->nRowEst;
|
||||||
rc = whereLoopInsert(pBuilder->pWInfo, pNew);
|
rc = whereLoopInsert(pBuilder->pWInfo, pNew);
|
||||||
|
|
||||||
|
/* TBD: Insert automatic index opportunities */
|
||||||
|
|
||||||
/* Loop over all indices
|
/* Loop over all indices
|
||||||
*/
|
*/
|
||||||
for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext){
|
for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext){
|
||||||
WhereTerm **paTerm;
|
|
||||||
pNew->prereq = mExtra;
|
|
||||||
pNew->iTab = iTab;
|
|
||||||
pNew->u.btree.nEq = 0;
|
pNew->u.btree.nEq = 0;
|
||||||
pNew->nTerm = 0;
|
pNew->nTerm = 0;
|
||||||
if( pProbe->tnum<=0 ){
|
if( pProbe->tnum<=0 ){
|
||||||
@@ -5386,10 +5380,6 @@ static int whereLoopAddBtree(
|
|||||||
}
|
}
|
||||||
pNew->wsFlags = m==0 ? WHERE_IDX_ONLY : 0;
|
pNew->wsFlags = m==0 ? WHERE_IDX_ONLY : 0;
|
||||||
}
|
}
|
||||||
paTerm = sqlite3DbRealloc(db, pNew->aTerm,
|
|
||||||
(pProbe->nColumn+2)*sizeof(pNew->aTerm[0]));
|
|
||||||
if( paTerm==0 ){ rc = SQLITE_NOMEM; break; }
|
|
||||||
pNew->aTerm = paTerm;
|
|
||||||
pNew->u.btree.pIndex = pProbe;
|
pNew->u.btree.pIndex = pProbe;
|
||||||
|
|
||||||
rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 1);
|
rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 1);
|
||||||
@@ -5407,7 +5397,6 @@ static int whereLoopAddBtree(
|
|||||||
*/
|
*/
|
||||||
static int whereLoopAddVirtual(
|
static int whereLoopAddVirtual(
|
||||||
WhereLoopBuilder *pBuilder, /* WHERE clause information */
|
WhereLoopBuilder *pBuilder, /* WHERE clause information */
|
||||||
int iTab, /* The table to process */
|
|
||||||
Bitmask mExtra /* Extra prerequesites for using this table */
|
Bitmask mExtra /* Extra prerequesites for using this table */
|
||||||
){
|
){
|
||||||
Parse *pParse; /* The parsing context */
|
Parse *pParse; /* The parsing context */
|
||||||
@@ -5425,27 +5414,17 @@ static int whereLoopAddVirtual(
|
|||||||
int seenVar = 0; /* True if a non-constant constraint is seen */
|
int seenVar = 0; /* True if a non-constant constraint is seen */
|
||||||
int iPhase; /* 0: const w/o IN, 1: const, 2: no IN, 2: IN */
|
int iPhase; /* 0: const w/o IN, 1: const, 2: no IN, 2: IN */
|
||||||
WhereLoop *pNew;
|
WhereLoop *pNew;
|
||||||
WhereTerm **paTerm;
|
|
||||||
int rc = SQLITE_OK;
|
int rc = SQLITE_OK;
|
||||||
|
|
||||||
pParse = pBuilder->pParse;
|
pParse = pBuilder->pParse;
|
||||||
db = pParse->db;
|
db = pParse->db;
|
||||||
pWC = pBuilder->pWC;
|
pWC = pBuilder->pWC;
|
||||||
pSrc = &pBuilder->pTabList->a[iTab];
|
|
||||||
pTab = pSrc->pTab;
|
|
||||||
pNew = pBuilder->pNew;
|
pNew = pBuilder->pNew;
|
||||||
pIdxInfo = allocateIndexInfo(pParse,pWC,pSrc,pBuilder->pOrderBy);
|
pSrc = &pBuilder->pTabList->a[pNew->iTab];
|
||||||
|
pTab = pSrc->pTab;
|
||||||
|
pIdxInfo = allocateIndexInfo(pParse, pWC, pSrc, pBuilder->pOrderBy);
|
||||||
if( pIdxInfo==0 ) return SQLITE_NOMEM;
|
if( pIdxInfo==0 ) return SQLITE_NOMEM;
|
||||||
paTerm = sqlite3DbRealloc(db, pNew->aTerm,
|
|
||||||
(pIdxInfo->nConstraint+1)*sizeof(pNew->aTerm[0]));
|
|
||||||
if( paTerm==0 ){
|
|
||||||
sqlite3DbFree(db, pIdxInfo);
|
|
||||||
return SQLITE_NOMEM;
|
|
||||||
}
|
|
||||||
pNew->aTerm = paTerm;
|
|
||||||
pNew->prereq = 0;
|
pNew->prereq = 0;
|
||||||
pNew->iTab = iTab;
|
|
||||||
pNew->maskSelf = getMask(pBuilder->pWC->pMaskSet, pSrc->iCursor);
|
|
||||||
pNew->rSetup = 0;
|
pNew->rSetup = 0;
|
||||||
pNew->wsFlags = WHERE_VIRTUALTABLE;
|
pNew->wsFlags = WHERE_VIRTUALTABLE;
|
||||||
pNew->nTerm = 0;
|
pNew->nTerm = 0;
|
||||||
@@ -5571,22 +5550,36 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
|
|||||||
sqlite3 *db = pBuilder->db;
|
sqlite3 *db = pBuilder->db;
|
||||||
int nTabList = pBuilder->pWInfo->nLevel;
|
int nTabList = pBuilder->pWInfo->nLevel;
|
||||||
int rc = SQLITE_OK;
|
int rc = SQLITE_OK;
|
||||||
|
WhereLoop *pNew;
|
||||||
|
|
||||||
/* Loop over the tables in the join, from left to right */
|
/* Loop over the tables in the join, from left to right */
|
||||||
pBuilder->pNew = sqlite3DbMallocZero(db, sizeof(WhereLoop));
|
pBuilder->pNew = pNew = sqlite3DbMallocZero(db, sizeof(WhereLoop));
|
||||||
if( pBuilder->pNew==0 ) return SQLITE_NOMEM;
|
if( pNew==0 ) return SQLITE_NOMEM;
|
||||||
|
pNew->aTerm = sqlite3DbMallocZero(db, (pWC->nTerm+1)*sizeof(pNew->aTerm[0]));
|
||||||
|
if( pNew->aTerm==0 ){
|
||||||
|
rc = SQLITE_NOMEM;
|
||||||
|
goto whereLoopAddAll_end;
|
||||||
|
}
|
||||||
for(iTab=0, pItem=pTabList->a; iTab<nTabList; iTab++, pItem++){
|
for(iTab=0, pItem=pTabList->a; iTab<nTabList; iTab++, pItem++){
|
||||||
if( IsVirtual(pItem->pTab) ){
|
pNew->iTab = iTab;
|
||||||
rc = whereLoopAddVirtual(pBuilder, iTab, mExtra);
|
pNew->maskSelf = getMask(pWC->pMaskSet, pItem->iCursor);
|
||||||
}else{
|
|
||||||
rc = whereLoopAddBtree(pBuilder, iTab, mExtra);
|
|
||||||
}
|
|
||||||
mPrior |= getMask(pWC->pMaskSet, pItem->iCursor);
|
|
||||||
if( (pItem->jointype & (JT_LEFT|JT_CROSS))!=0 ){
|
if( (pItem->jointype & (JT_LEFT|JT_CROSS))!=0 ){
|
||||||
mExtra = mPrior;
|
mExtra = mPrior;
|
||||||
}
|
}
|
||||||
|
if( IsVirtual(pItem->pTab) ){
|
||||||
|
rc = whereLoopAddVirtual(pBuilder, mExtra);
|
||||||
|
}else{
|
||||||
|
rc = whereLoopAddBtree(pBuilder, mExtra);
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
if( rc==SQLITE_OK ){
|
||||||
|
rc = whereLoopAddOr(pBuilder, mExtra);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
mPrior |= pNew->maskSelf;
|
||||||
if( rc || db->mallocFailed ) break;
|
if( rc || db->mallocFailed ) break;
|
||||||
}
|
}
|
||||||
|
whereLoopAddAll_end:
|
||||||
whereLoopDelete(db, pBuilder->pNew);
|
whereLoopDelete(db, pBuilder->pNew);
|
||||||
pBuilder->pNew = 0;
|
pBuilder->pNew = 0;
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
Reference in New Issue
Block a user