From: drh Date: Mon, 18 May 2009 15:46:07 +0000 (+0000) Subject: Changes to select.c in support of full coverage testing. (CVS 6647) X-Git-Tag: version-3.6.15~103 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccfcbcea60c08ce806f64eb48e938738b29911fd;p=thirdparty%2Fsqlite.git Changes to select.c in support of full coverage testing. (CVS 6647) FossilOrigin-Name: e225f365bd9353f753161887e05fe1eccaf9be1d --- diff --git a/manifest b/manifest index 950fe3a5a5..eaefff2dac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\son\sa\scomment\sassociated\swith\scheck-in\s(6641)\sand\sticket\s#3860.\s(CVS\s6646) -D 2009-05-18T13:34:38 +C Changes\sto\sselect.c\sin\ssupport\sof\sfull\scoverage\stesting.\s(CVS\s6647) +D 2009-05-18T15:46:08 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -158,7 +158,7 @@ F src/printf.c 3f4dca207a88258d37af5a7a03e800a825fe6456 F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628 F src/resolve.c 2ce8f8bc8a0c913cbaec3fb3da2be113ea1fa5af F src/rowset.c 14d12b5e81b5907b87d511f6f4219805f96a4b55 -F src/select.c b51d7f64f345f90f10a1ee8df489c3eda29fa3ee +F src/select.c e5813bd0a75f8d303a56667fa669c8cb9d47c375 F src/shell.c 0a11f831603f17fea20ca97133c0f64e716af4a7 F src/sqlite.h.in 0c459a45c1047be24c6a58646e8be4d001a3a28a F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 @@ -729,7 +729,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 0d974613473b9d2af71638248a57036f903ef387 -R 09df808b47e81fe931aacca7591d8277 +P 43051e0315246d734a81ccef2cf1a0cc159f239b +R 38f7f1975b86b5c904b4bdaa151080a5 U drh -Z eb3deca17c5edd805ee4a913a717f2fa +Z fa4ce17ae5118cad70d4b23a7eeee79b diff --git a/manifest.uuid b/manifest.uuid index 7488595520..26abbf3c6f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -43051e0315246d734a81ccef2cf1a0cc159f239b \ No newline at end of file +e225f365bd9353f753161887e05fe1eccaf9be1d \ No newline at end of file diff --git a/src/select.c b/src/select.c index 7e82e3cfd0..7604396b6b 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.516 2009/05/17 15:29:31 drh Exp $ +** $Id: select.c,v 1.517 2009/05/18 15:46:08 drh Exp $ */ #include "sqliteInt.h" @@ -1868,26 +1868,20 @@ static int generateOutputSubroutine( break; } - /* Results are stored in a sequence of registers. Then the - ** OP_ResultRow opcode is used to cause sqlite3_step() to return - ** the next row of result. + /* If none of the above, then the result destination must be + ** SRT_Output. This routine is never called with any other + ** destination other than the ones handled above or SRT_Output. + ** + ** For SRT_Output, results are stored in a sequence of registers. + ** Then the OP_ResultRow opcode is used to cause sqlite3_step() to + ** return the next row of result. */ - case SRT_Output: { + default: { + assert( pDest->eDest==SRT_Output ); sqlite3VdbeAddOp2(v, OP_ResultRow, pIn->iMem, pIn->nMem); sqlite3ExprCacheAffinityChange(pParse, pIn->iMem, pIn->nMem); break; } - -#if !defined(SQLITE_OMIT_TRIGGER) - /* Discard the results. This is used for SELECT statements inside - ** the body of a TRIGGER. The purpose of such selects is to call - ** user-defined functions that have side effects. We do not care - ** about the actual results of the select. - */ - default: { - break; - } -#endif } /* Jump to the end of the loop if the LIMIT is reached. @@ -2036,7 +2030,7 @@ static int multiSelectOrderBy( assert( pKeyDup==0 ); /* "Managed" code needs this. Ticket #3382. */ db = pParse->db; v = pParse->pVdbe; - if( v==0 ) return SQLITE_NOMEM; + assert( v!=0 ); /* Already thrown the error if VDBE alloc failed */ labelEnd = sqlite3VdbeMakeLabel(v); labelCmpr = sqlite3VdbeMakeLabel(v); @@ -2650,9 +2644,11 @@ static int flattenSubquery( return 0; } for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){ + testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ); + testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Aggregate ); if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 || (pSub1->pPrior && pSub1->op!=TK_ALL) - || !pSub1->pSrc || pSub1->pSrc->nSrc!=1 + || NEVER(pSub1->pSrc==0) || pSub1->pSrc->nSrc!=1 ){ return 0; } @@ -2752,8 +2748,10 @@ static int flattenSubquery( ** subquery until code generation is ** complete, since there may still exist Expr.pTab entries that ** refer to the subquery even after flattening. Ticket #3346. + ** + ** pSubitem->pTab is always non-NULL by test restrictions and tests above. */ - if( pSubitem->pTab!=0 ){ + if( ALWAYS(pSubitem->pTab!=0) ){ Table *pTabToDel = pSubitem->pTab; if( pTabToDel->nRef==1 ){ pTabToDel->pNextZombie = pParse->pZombieTab; @@ -2841,10 +2839,12 @@ static int flattenSubquery( */ pList = pParent->pEList; for(i=0; inExpr; i++){ - Expr *pExpr; - if( pList->a[i].zName==0 && (pExpr = pList->a[i].pExpr)->span.z!=0 ){ - pList->a[i].zName = + if( pList->a[i].zName==0 ){ + Expr *pExpr = pList->a[i].pExpr; + if( ALWAYS(pExpr->span.z!=0) ){ + pList->a[i].zName = sqlite3DbStrNDup(db, (char*)pExpr->span.z, pExpr->span.n); + } } } substExprList(db, pParent->pEList, iParent, pSub->pEList); @@ -3561,19 +3561,17 @@ int sqlite3Select( if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; memset(&sAggInfo, 0, sizeof(sAggInfo)); - pOrderBy = p->pOrderBy; if( IgnorableOrderby(pDest) ){ - p->pOrderBy = 0; - - /* In these cases the DISTINCT operator makes no difference to the - ** results, so remove it if it were specified. - */ assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union || pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard); + /* If ORDER BY makes no difference in the output then neither does + ** DISTINCT so it can be removed too. */ + sqlite3ExprListDelete(db, p->pOrderBy); + p->pOrderBy = 0; p->selFlags &= ~SF_Distinct; } sqlite3SelectPrep(pParse, p, 0); - p->pOrderBy = pOrderBy; + pOrderBy = p->pOrderBy; pTabList = p->pSrc; pEList = p->pEList; if( pParse->nErr || db->mallocFailed ){ @@ -3588,12 +3586,6 @@ int sqlite3Select( */ if( pParse->nErr>0 ) goto select_end; - /* ORDER BY is ignored for some destinations. - */ - if( IgnorableOrderby(pDest) ){ - pOrderBy = 0; - } - /* Begin generating code. */ v = sqlite3GetVdbe(pParse);