diff --git a/manifest b/manifest index b4bdc68a0a..643ffdacdf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Changes\sto\sloadext.test\sso\sthat\sit\sworks\son\sosx\sas\swell\sas\slinux.\s(CVS\s5329) -D 2008-06-30T15:09:29 +C Call\sthe\squery\sflattener\swhile\sprocessing\sthe\sparent\squery.\sPreviously,\sit\swas\scalled\swhile\sprocessing\sthe\ssub-queries.\s(CVS\s5330) +D 2008-06-30T18:12:28 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -140,7 +140,7 @@ F src/pragma.c 9a95f5b3708f6d3ddd987eab5f369a19ffcb6795 F src/prepare.c aba51dad52308e3d9d2074d8ff4e612e7f1cab51 F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a -F src/select.c 5b213de002382aeaac5c9c2d3be7c98900bc3056 +F src/select.c afaac3f04b922edb8af07f05763b63c00ddc4a5a F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0 F src/sqlite.h.in 76c144d23f8824e8811e837e9396b9f1361f5902 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e @@ -548,7 +548,7 @@ F test/vacuum2.test d3b9691541fe6ed5c711f547a1c7d70e9760ac6f F test/vacuum3.test 6149b24613f487915ca9cedfbb9147d5759714ec F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test fdd8108de66eec378291d9a0e46e30d129eef1ca -F test/view.test 4864e3841ab3213a95297718b94d5d6a8d3bc78b +F test/view.test 041ccaf4c96f6c90d564c9ea37d1c1fa21fdb470 F test/vtab1.test 47092e3ac59141f08e09a6c0cc0df8997242bc79 F test/vtab2.test 1da49b015582965a8fc386aa23d051a5a622b08e F test/vtab3.test f38d6d7d19f08bffdadce4d5b8cba078f8118587 @@ -595,7 +595,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P ba8819a6f3dbc45d88346789de42971aacc0d246 -R d9ae76ff4c185320bbb89c9f9139919a +P 189cd85413a2e00696752bb82e7a442e86e621ac +R d620881f6cbbbbefdfa4e9725f1fbb87 U danielk1977 -Z 00e6f564f2a763edcec24b97ea9019b8 +Z 6869d5a04e97a4a4d7edf1da8de9ca2a diff --git a/manifest.uuid b/manifest.uuid index 1902737b61..a4cb46a6c7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -189cd85413a2e00696752bb82e7a442e86e621ac \ No newline at end of file +6fcb3bffe26ae1c21c72ce9019f1db1c118094a4 \ No newline at end of file diff --git a/src/select.c b/src/select.c index ddd03726c5..55cf08e966 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.439 2008/06/27 00:52:45 drh Exp $ +** $Id: select.c,v 1.440 2008/06/30 18:12:28 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -3670,6 +3670,7 @@ int sqlite3Select( } p->pOrderBy = pOrderBy; + #ifndef SQLITE_OMIT_COMPOUND_SELECT /* If there is are a sequence of queries, do the earlier ones first. */ @@ -3696,11 +3697,7 @@ int sqlite3Select( /* Make local copies of the parameters for this query. */ pTabList = p->pSrc; - pWhere = p->pWhere; - pGroupBy = p->pGroupBy; - pHaving = p->pHaving; isAgg = p->isAgg; - isDistinct = p->isDistinct; pEList = p->pEList; if( pEList==0 ) goto select_end; @@ -3734,19 +3731,21 @@ int sqlite3Select( */ #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) for(i=0; inSrc; i++){ - const char *zSavedAuthContext = 0; - int needRestoreContext; struct SrcList_item *pItem = &pTabList->a[i]; SelectDest dest; + Select *pSub = pItem->pSelect; - if( pItem->pSelect==0 || pItem->isPopulated ) continue; - if( pItem->zName!=0 ){ - zSavedAuthContext = pParse->zAuthContext; + if( pSub==0 || pItem->isPopulated ) continue; + if( pItem->zName!=0 ){ /* An sql view */ + const char *zSavedAuthContext = pParse->zAuthContext; pParse->zAuthContext = pItem->zName; - needRestoreContext = 1; - }else{ - needRestoreContext = 0; + rc = sqlite3SelectResolve(pParse, pSub, 0); + pParse->zAuthContext = zSavedAuthContext; + if( rc ){ + goto select_end; + } } + /* Increment Parse.nHeight by the height of the largest expression ** tree refered to by this, the parent select. The child select ** may contain expression trees of at most @@ -3755,36 +3754,32 @@ int sqlite3Select( ** an exact limit. */ pParse->nHeight += sqlite3SelectExprHeight(p); - sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); - sqlite3Select(pParse, pItem->pSelect, &dest, p, i, &isAgg, 0); + + /* Check to see if the subquery can be absorbed into the parent. */ + if( !pSub->pPrior && flattenSubquery(db, p, i, isAgg, pSub->isAgg) ){ + if( pSub->isAgg ){ + p->isAgg = isAgg = 1; + } + i = -1; + }else{ + sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); + sqlite3Select(pParse, pSub, &dest, p, i, &isAgg, 0); + } if( db->mallocFailed ){ goto select_end; } pParse->nHeight -= sqlite3SelectExprHeight(p); - if( needRestoreContext ){ - pParse->zAuthContext = zSavedAuthContext; - } pTabList = p->pSrc; - pWhere = p->pWhere; if( !IgnorableOrderby(pDest) ){ pOrderBy = p->pOrderBy; } - pGroupBy = p->pGroupBy; - pHaving = p->pHaving; - isDistinct = p->isDistinct; - } -#endif - - /* Check to see if this is a subquery that can be "flattened" into its parent. - ** If flattening is a possiblity, do so and return immediately. - */ -#ifndef SQLITE_OMIT_VIEW - if( pParent && pParentAgg && - flattenSubquery(db, pParent, parentTab, *pParentAgg, isAgg) ){ - if( isAgg ) *pParentAgg = 1; - goto select_end; } + pEList = p->pEList; #endif + pWhere = p->pWhere; + pGroupBy = p->pGroupBy; + pHaving = p->pHaving; + isDistinct = p->isDistinct; /* If possible, rewrite the query to use GROUP BY instead of DISTINCT. ** GROUP BY may use an index, DISTINCT never does. diff --git a/test/view.test b/test/view.test index edc37c3927..f2f2ab68f8 100644 --- a/test/view.test +++ b/test/view.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing VIEW statements. # -# $Id: view.test,v 1.35 2008/01/25 15:04:50 drh Exp $ +# $Id: view.test,v 1.36 2008/06/30 18:12:28 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -514,5 +514,23 @@ do_test view-17.2 { } } {1 {no such view: main.nosuchview}} +do_test view-18.1 { + execsql { + DROP VIEW t1; + DROP TABLE t1; + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + + CREATE VIEW vv1 AS SELECT * FROM t1; + CREATE VIEW vv2 AS SELECT * FROM vv1; + CREATE VIEW vv3 AS SELECT * FROM vv2; + CREATE VIEW vv4 AS SELECT * FROM vv3; + CREATE VIEW vv5 AS SELECT * FROM vv4; + + SELECT * FROM vv5; + } +} {1 2 3 4 5 6} + finish_test