From: drh Date: Tue, 7 May 2013 19:44:38 +0000 (+0000) Subject: Inserting a few WhereLoop objects without leaking memory. Costs are X-Git-Tag: version-3.8.0~130^2~91 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f1645f084376428d018930ef72f1e304cfab29dc;p=thirdparty%2Fsqlite.git Inserting a few WhereLoop objects without leaking memory. Costs are not correct. Inequality and IN constraints are not implemented. FossilOrigin-Name: e8881a8b2f25f38bc8ff77619f96f38fe530d13b --- diff --git a/manifest b/manifest index a36fbf25aa..29d28aecb0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\swhere.c,\smake\sfindTerm()\sa\swrapper\saround\smethods\sto\sa\snew\sWhereScan\sobject\nwhich\sis\scapable\sof\sfinding\sall\ssuitable\smatching\sterms,\snot\sjust\sthe\sfirst.\nThis\scheck-in\sincludes\ssome\sprototype\sfunctions\sfor\sbuilding\sWhereLoop\sobjects. -D 2013-05-04T20:25:23.612 +C Inserting\sa\sfew\sWhereLoop\sobjects\swithout\sleaking\smemory.\s\sCosts\sare\nnot\scorrect.\s\sInequality\sand\sIN\sconstraints\sare\snot\simplemented. +D 2013-05-07T19:44:38.531 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -263,7 +263,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83 F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d F src/wal.h a4d3da523d55a226a0b28e9058ef88d0a8051887 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 173347e4598207467401e1952bdee983cf0bf087 +F src/where.c e987a4ff2818b812f902361c1131fef4a8f95a41 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1060,7 +1060,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P ccaf4c3f7e1ec45e058d594d9b5c26818a37722a -R d516c3475d503fb543da6770e30ae39a +P dd92b8fa929badaf2f79e8a00c83667a9d589096 +R 20c9cc42b7ec6059ab1cb985542962e1 U drh -Z 4a8c637fc587086861ee6817f8b965a6 +Z 6dee1758f1f268139b7d8139f9ade772 diff --git a/manifest.uuid b/manifest.uuid index 36eaec293a..62ed5b5e8a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dd92b8fa929badaf2f79e8a00c83667a9d589096 \ No newline at end of file +e8881a8b2f25f38bc8ff77619f96f38fe530d13b \ No newline at end of file diff --git a/src/where.c b/src/where.c index 14120339d2..4776a2b231 100644 --- a/src/where.c +++ b/src/where.c @@ -5163,6 +5163,7 @@ static void whereLoopAddBtreeIndex( WhereTerm *pTerm; /* A WhereTerm under consideration */ int eqTermMask; /* Valid equality operators */ WhereScan scan; /* Iterator for WHERE terms */ + WhereLoop savedLoop; db = pBuilder->db; pNew = pBuilder->pNew; @@ -5182,13 +5183,26 @@ static void whereLoopAddBtreeIndex( iCol = pProbe->aiColumn[pNew->nEq]; pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol, eqTermMask, iCol>=0 ? pProbe : 0); + savedLoop = *pNew; pNew->nEq++; + pNew->nTerm++; for(; pTerm!=0; pTerm = whereScanNext(&scan)){ pNew->aTerm[pNew->nEq-1] = pTerm; - + pNew->nOut = (double)(pProbe->aiRowEst[pNew->nEq] * nInMul); + pNew->rSetup = (double)0; + pNew->rRun = pNew->nOut; + pNew->prereq = savedLoop.prereq | pTerm->prereqRight; + if( pProbe->tnum<=0 ){ + pNew->wsFlags = savedLoop.wsFlags | WHERE_ROWID_EQ; + }else{ + pNew->wsFlags = savedLoop.wsFlags | WHERE_COLUMN_EQ; + } + whereLoopInsert(pBuilder->pWInfo, pNew); + if( pNew->nEqnColumn ){ + whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul); + } } - pNew->nEq--; - + *pNew = savedLoop; } } @@ -5202,7 +5216,6 @@ static void whereLoopAddBtree( Bitmask mExtra /* Extra prerequesites for using this table */ ){ Index *pProbe; /* An index we are evaluating */ - int eqTermMask; /* Current mask of valid equality operators */ Index sPk; /* A fake index object for the primary key */ tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */ int aiColumnPk = -1; /* The aColumn[] value for the sPk index */ @@ -5243,13 +5256,15 @@ static void whereLoopAddBtree( /* Loop over all indices */ for(; pProbe; pProbe=pProbe->pNext){ + WhereTerm **paTerm; pNew->prereq = mExtra; pNew->iTab = iTab; pNew->nEq = 0; pNew->nTerm = 0; - pNew->aTerm = sqlite3DbRealloc(db, pNew->aTerm, - (pProbe->nColumn+1)*sizeof(pNew->aTerm[0])); - if( pNew->aTerm==0 ) break; + paTerm = sqlite3DbRealloc(db, pNew->aTerm, + (pProbe->nColumn+1)*sizeof(pNew->aTerm[0])); + if( paTerm==0 ) break; + pNew->aTerm = paTerm; pNew->pIndex = pProbe; whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 1); @@ -5551,7 +5566,7 @@ WhereInfo *sqlite3WhereBegin( /* Construct the WhereLoop objects */ WHERETRACE(("*** Optimizer Start ***\n")); - /*whereLoopAddAll(&sWLB);*/ + whereLoopAddAll(&sWLB); /* Display all of the WhereLoop objects if wheretrace is enabled */ #if defined(SQLITE_DEBUG) \ @@ -5563,16 +5578,16 @@ WhereInfo *sqlite3WhereBegin( struct SrcList_item *pItem = pTabList->a + p->iTab; Table *pTab = pItem->pTab; sqlite3DebugPrintf("%02d.%0*llx", p->iTab, nb, p->prereq); - sqlite3DebugPrintf(" %s", + sqlite3DebugPrintf(" %5s", pItem->zAlias ? pItem->zAlias : pTab->zName); if( p->pIndex ){ - sqlite3DebugPrintf(" index %s nEq %d", p->pIndex->zName, p->nEq); + sqlite3DebugPrintf(".%-5s %2d", p->pIndex->zName, p->nEq); }else{ - sqlite3DebugPrintf("\n"); + sqlite3DebugPrintf("%9s",""); } - sqlite3DebugPrintf(" wsFlags %08x OB %d,%d nTerm %d\n", + sqlite3DebugPrintf(" fg %08x OB %d,%d N %2d", p->wsFlags, p->iOb, p->nOb, p->nTerm); - sqlite3DebugPrintf(" cost %.2e + %.2e nOut %.2e\n", + sqlite3DebugPrintf(" cost %.2g+%.2g,%.2g\n", p->prereq, p->rSetup, p->rRun, p->nOut); } }