From a9671a22b370710dfc89c0220cf02a1967ac869f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 8 Jul 2008 23:40:20 +0000 Subject: [PATCH] Remove obsolete code from select.c, including the "affinity" parameter to the sqlite3Select() module. (CVS 5380) FossilOrigin-Name: cbd3c1585b7a8f8042aa1448fe1be87de056c41a --- manifest | 34 ++++---- manifest.uuid | 2 +- src/build.c | 4 +- src/delete.c | 4 +- src/expr.c | 6 +- src/insert.c | 4 +- src/parse.y | 4 +- src/select.c | 210 ++++++++++++++-------------------------------- src/sqliteInt.h | 4 +- src/test_config.c | 4 +- src/trigger.c | 4 +- src/update.c | 4 +- test/join.test | 31 ++++++- 13 files changed, 128 insertions(+), 187 deletions(-) diff --git a/manifest b/manifest index 6e93a2f535..0233e3cd00 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Handle\ssqlite3_temp_directory\son\sOS/2.\s(CVS\s5379) -D 2008-07-08T22:34:07 +C Remove\sobsolete\scode\sfrom\sselect.c,\sincluding\sthe\s"affinity"\sparameter\nto\sthe\ssqlite3Select()\smodule.\s(CVS\s5380) +D 2008-07-08T23:40:20 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -98,19 +98,19 @@ F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2 F src/btree.c a52b0a1d0459e3a028a90df84a84ec1c58148574 F src/btree.h b1bd7e0b8c2e33658aaf447cb0d1d94f74664b6b F src/btreeInt.h 8f6e0817365ac822da0afffedc664ba03047718b -F src/build.c c5985afa7f2519ffd2b93d575caa6d75d610156b +F src/build.c bac7233d984be3805aaa41cf500f7ee12dc97249 F src/callback.c aa492a0ad8c2d454edff9fb8a57fae13743cf71d F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c F src/date.c e841168e5520bbbb2a1cbcdce7531d8b23017b4d -F src/delete.c d3fc5987f2eb88f7b9549d58a5dfea079a83fe8b -F src/expr.c 8f2caa888af148ebf9cdb2cf7ffaae2a09767c48 +F src/delete.c 4a1f98fb2ffead69c8c685dcac33253ac6f9d56d +F src/expr.c 6343c50c2bc39ac4f653b1eebd1339e25378b0e7 F src/fault.c 3638519d1e0b82bccfafcb9f5ff491918b28f8e1 F src/func.c 08422a7bd06c25c5e6823d525f7c63563e3fcf61 F src/global.c f12dc84d23f52d2ed42d1bdb5460fa3caf63e890 F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 F src/hwtime.h 745961687a65ef8918cd551c02e5ccb4b8e772de -F src/insert.c d20fb21ef632ec4b5ba196edbdd7a1cb15b1f1e7 +F src/insert.c e8efc17d037346e4a4a6949e72aab850befe3d5d F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df F src/loadext.c ae0eed9fa96d74172d2a90ee63b5bc36d284295c @@ -135,16 +135,16 @@ F src/os_unix.c 3d19f0491e0b32e5b757c7e6f310f2f6d3aea3f4 F src/os_win.c 2bf2f8cd700299564cc236262c2668e1e02c626a F src/pager.c 2cd554d474cfa0228ece30645fe7bb7d1f6824c7 F src/pager.h 6aa3050a3c684475a5a9dbad5ff1cebad612acba -F src/parse.y 8c2c3145eebe1964eb279cb3c4e502eae28bb0fa +F src/parse.y 097bff733e89fbf554a07d9327046718ce364011 F src/pragma.c 6fad83fbcc7ec6e76d91fe2805fe972ff3af6a0c F src/prepare.c c9bb0aacb7a571d049805699ed18f2bb136ea091 F src/printf.c 0e4bd1413226e8aaeadec251ffcee93448400417 F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a -F src/select.c 5ff8bc0ec204d02fb9d61ce59d5efc80680b8897 +F src/select.c 02b7877754dd8391e48c3ba94b2b3bc8c3a74f20 F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0 F src/sqlite.h.in 22c32cedf7e435d5b3bb8564ce0a640c40dbbfb1 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e -F src/sqliteInt.h 97c17728266bef590721276ef19c68c2fe577c4e +F src/sqliteInt.h 5f820a35b12bedad6f20395f4947b97f645ed243 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 F src/status.c 6cb10377992505bd69f1ca1d75c1240a65f25a58 F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8 @@ -161,7 +161,7 @@ F src/test9.c 4615ef08750245a2d96aaa7cbe2fb4aff2b57acc F src/test_async.c da9f58f49faccd3a26ba89f58de125862351b6e2 F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c -F src/test_config.c e893a7195e975f133c4481d679089531c2970c73 +F src/test_config.c 7d3c3bb37e12d8ed22c5e0900e1361178b0580a3 F src/test_devsym.c 6012cb8e3acf812513511025a4fa5d626e0ba19b F src/test_func.c ade4f0117cc96c5a05682e1ef38b84320a866ad9 F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f @@ -176,8 +176,8 @@ F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b F src/test_tclvar.c 73530070df8378571c8ce6bbbbb993236ae3ad0b F src/test_thread.c e297dd41db0b249646e69f97d36ec13e56e8b730 F src/tokenize.c b5fdc79fb7e00077b9c02af7a0da3b89c9f3398e -F src/trigger.c 1e751f8d5ceeb328d26bf1ccfb2de50653670d49 -F src/update.c 2d7143b9014e955509cc4f323f9a9584fb898f34 +F src/trigger.c bdb56bb9db1a7b18f8505484051221ab5123f21d +F src/update.c 945242ccc4fa09799333632baf6b47c657f43cbc F src/utf.c 8d52f620a7153d90b058502124fe51d821fcdf57 F src/util.c e202291456d34f8e2cf1c0a6f7e2538a77587445 F src/vacuum.c ef342828002debc97514617af3424aea8ef8522c @@ -361,7 +361,7 @@ F test/ioerr2.test 5598405c48842c6c0187daad9eb49eff2c54f80d F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd F test/ioerr4.test fc6eddfec2efc2f1ed217b9eae4c1c1d3516ce86 F test/ioerr5.test f44e30b4780b879bcceb2601aabae40d8a0a0b56 -F test/join.test af0443185378b64878750aa1cf4b83c216f246b4 +F test/join.test f6aab432bd42c0a2617ff1563557d5e45336f391 F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 @@ -600,7 +600,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 6cdb6841ff4683e424ef394733da9c24f5602570 -R 25d8e118bf8ba394bf175259827dc7d9 -U pweilbacher -Z 037a3fab80bbb871bde5db3b3d98709e +P 9da0b32c8c55b41cbcb4eb635c51348072101ea9 +R ddba1a74c7f8c0729773c7fe021be047 +U drh +Z 19507801db0a91231559be894402bb80 diff --git a/manifest.uuid b/manifest.uuid index 22b1952aa6..ff5dc166a6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9da0b32c8c55b41cbcb4eb635c51348072101ea9 \ No newline at end of file +cbd3c1585b7a8f8042aa1448fe1be87de056c41a \ No newline at end of file diff --git a/src/build.c b/src/build.c index 926015fe9b..8a1d4bb755 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.489 2008/07/08 22:28:49 shane Exp $ +** $Id: build.c,v 1.490 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteInt.h" #include @@ -1526,7 +1526,7 @@ void sqlite3EndTable( sqlite3VdbeChangeP5(v, 1); pParse->nTab = 2; sqlite3SelectDestInit(&dest, SRT_Table, 1); - sqlite3Select(pParse, pSelect, &dest, 0, 0, 0, 0); + sqlite3Select(pParse, pSelect, &dest, 0, 0, 0); sqlite3VdbeAddOp1(v, OP_Close, 1); if( pParse->nErr==0 ){ pSelTab = sqlite3ResultSetOfSelect(pParse, 0, pSelect); diff --git a/src/delete.c b/src/delete.c index 61b3f8b455..654570bc53 100644 --- a/src/delete.c +++ b/src/delete.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** in order to generate code for DELETE FROM statements. ** -** $Id: delete.c,v 1.169 2008/04/28 18:46:43 drh Exp $ +** $Id: delete.c,v 1.170 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteInt.h" @@ -106,7 +106,7 @@ void sqlite3MaterializeView( pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); } sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); - sqlite3Select(pParse, pDup, &dest, 0, 0, 0, 0); + sqlite3Select(pParse, pDup, &dest, 0, 0, 0); sqlite3SelectDelete(pDup); } #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ diff --git a/src/expr.c b/src/expr.c index b2aca6bf9f..1929eb7d23 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.383 2008/07/04 09:41:39 danielk1977 Exp $ +** $Id: expr.c,v 1.384 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteInt.h" #include @@ -1888,7 +1888,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){ sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable); dest.affinity = (int)affinity; assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable ); - if( sqlite3Select(pParse, pExpr->pSelect, &dest, 0, 0, 0, 0) ){ + if( sqlite3Select(pParse, pExpr->pSelect, &dest, 0, 0, 0) ){ return; } pEList = pExpr->pSelect->pEList; @@ -1969,7 +1969,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr, int rMayHaveNull){ } sqlite3ExprDelete(pSel->pLimit); pSel->pLimit = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &one); - if( sqlite3Select(pParse, pSel, &dest, 0, 0, 0, 0) ){ + if( sqlite3Select(pParse, pSel, &dest, 0, 0, 0) ){ return; } pExpr->iColumn = dest.iParm; diff --git a/src/insert.c b/src/insert.c index 586775e5c6..9dda3954f1 100644 --- a/src/insert.c +++ b/src/insert.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.246 2008/07/08 22:28:49 shane Exp $ +** $Id: insert.c,v 1.247 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteInt.h" @@ -530,7 +530,7 @@ void sqlite3Insert( VdbeComment((v, "Jump over SELECT coroutine")); /* Resolve the expressions in the SELECT statement and execute it. */ - rc = sqlite3Select(pParse, pSelect, &dest, 0, 0, 0, 0); + rc = sqlite3Select(pParse, pSelect, &dest, 0, 0, 0); if( rc || pParse->nErr || db->mallocFailed ){ goto insert_cleanup; } diff --git a/src/parse.y b/src/parse.y index 914cad15dc..65c1747195 100644 --- a/src/parse.y +++ b/src/parse.y @@ -14,7 +14,7 @@ ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.244 2008/06/05 16:47:39 danielk1977 Exp $ +** @(#) $Id: parse.y,v 1.245 2008/07/08 23:40:20 drh Exp $ */ // All token codes are small integers with #defines that begin with "TK_" @@ -361,7 +361,7 @@ cmd ::= DROP VIEW ifexists(E) fullname(X). { // cmd ::= select(X). { SelectDest dest = {SRT_Callback, 0, 0, 0, 0}; - sqlite3Select(pParse, X, &dest, 0, 0, 0, 0); + sqlite3Select(pParse, X, &dest, 0, 0, 0); sqlite3SelectDelete(X); } diff --git a/src/select.c b/src/select.c index f7c5780adb..7bd7c59e92 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.450 2008/07/08 19:34:07 drh Exp $ +** $Id: select.c,v 1.451 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteInt.h" @@ -160,12 +160,11 @@ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){ (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) || (jointype & JT_ERROR)!=0 ){ - const char *zSp1 = " "; - const char *zSp2 = " "; - if( pB==0 ){ zSp1++; } - if( pC==0 ){ zSp2++; } + const char *zSp = " "; + assert( pB!=0 ); + if( pC==0 ){ zSp++; } sqlite3ErrorMsg(pParse, "unknown or unsupported join type: " - "%T%s%T%s%T", pA, zSp1, pB, zSp2, pC); + "%T %T%s%T", pA, pB, zSp, pC); jointype = JT_INNER; }else if( jointype & JT_RIGHT ){ sqlite3ErrorMsg(pParse, @@ -531,8 +530,7 @@ static void selectInnerLoop( int distinct, /* If >=0, make sure results are distinct */ SelectDest *pDest, /* How to dispose of the results */ int iContinue, /* Jump here to continue with next row */ - int iBreak, /* Jump here to break out of the inner loop */ - char *aff /* affinity string if eDest is SRT_Union */ + int iBreak /* Jump here to break out of the inner loop */ ){ Vdbe *v = pParse->pVdbe; int i; @@ -609,9 +607,6 @@ static void selectInnerLoop( int r1; r1 = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1); - if( aff ){ - sqlite3VdbeChangeP4(v, -1, aff, P4_STATIC); - } sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1); sqlite3ReleaseTempReg(pParse, r1); break; @@ -849,7 +844,7 @@ static void generateSortTail( if( eDest==SRT_Callback ){ sqlite3VdbeAddOp2(v, OP_ResultRow, pDest->iMem, nColumn); sqlite3ExprCacheAffinityChange(pParse, pDest->iMem, nColumn); - }else if( eDest==SRT_Coroutine ){ + }else{ sqlite3VdbeAddOp1(v, OP_Yield, pDest->iParm); } break; @@ -862,12 +857,9 @@ static void generateSortTail( sqlite3ReleaseTempReg(pParse, regRow); sqlite3ReleaseTempReg(pParse, regRowid); - /* Jump to the end of the loop when the LIMIT is reached + /* LIMIT has been implemented by the pushOntoSorter() routine. */ - if( p->iLimit ){ - sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1); - sqlite3VdbeAddOp2(v, OP_IfZero, p->iLimit, brk); - } + assert( p->iLimit==0 ); /* The bottom of the loop */ @@ -1825,21 +1817,6 @@ static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){ } } -/* -** Allocate a virtual index to use for sorting. -*/ -static void createSortingIndex(Parse *pParse, Select *p, ExprList *pOrderBy){ - if( pOrderBy ){ - int addr; - assert( pOrderBy->iECursor==0 ); - pOrderBy->iECursor = pParse->nTab++; - addr = sqlite3VdbeAddOp2(pParse->pVdbe, OP_OpenEphemeral, - pOrderBy->iECursor, pOrderBy->nExpr+1); - assert( p->addrOpenEphm[2] == -1 ); - p->addrOpenEphm[2] = addr; - } -} - #ifndef SQLITE_OMIT_COMPOUND_SELECT /* ** Return the appropriate collating sequence for the iCol-th column of @@ -1867,8 +1844,7 @@ static CollSeq *multiSelectCollSeq(Parse *pParse, Select *p, int iCol){ static int multiSelectOrderBy( Parse *pParse, /* Parsing context */ Select *p, /* The right-most of SELECTs to be coded */ - SelectDest *pDest, /* What to do with query results */ - char *aff /* If eDest is SRT_Union, the affinity string */ + SelectDest *pDest /* What to do with query results */ ); @@ -1907,14 +1883,12 @@ static int multiSelectOrderBy( static int multiSelect( Parse *pParse, /* Parsing context */ Select *p, /* The right-most of SELECTs to be coded */ - SelectDest *pDest, /* What to do with query results */ - char *aff /* If eDest is SRT_Union, the affinity string */ + SelectDest *pDest /* What to do with query results */ ){ int rc = SQLITE_OK; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ int nCol; /* Number of columns in the result set */ - ExprList *pOrderBy; /* The ORDER BY clause on p */ int aSetP2[2]; /* Set P2 value of these op to number of columns */ int nSetP2 = 0; /* Number of slots in aSetP2[] used */ SelectDest dest; /* Alternative data destination */ @@ -1971,47 +1945,43 @@ static int multiSelect( goto multi_select_end; } -#if 1 + /* Compound SELECTs that have an ORDER BY clause are handled separately. + */ if( p->pOrderBy ){ - return multiSelectOrderBy(pParse, p, pDest, aff); + return multiSelectOrderBy(pParse, p, pDest); } -#endif /* Generate code for the left and right SELECT statements. */ - pOrderBy = p->pOrderBy; switch( p->op ){ case TK_ALL: { - if( pOrderBy==0 ){ - int addr = 0; - assert( !pPrior->pLimit ); - pPrior->pLimit = p->pLimit; - pPrior->pOffset = p->pOffset; - rc = sqlite3Select(pParse, pPrior, &dest, 0, 0, 0, aff); - p->pLimit = 0; - p->pOffset = 0; - if( rc ){ - goto multi_select_end; - } - p->pPrior = 0; - p->iLimit = pPrior->iLimit; - p->iOffset = pPrior->iOffset; - if( p->iLimit ){ - addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); - VdbeComment((v, "Jump ahead if LIMIT reached")); - } - rc = sqlite3Select(pParse, p, &dest, 0, 0, 0, aff); - pDelete = p->pPrior; - p->pPrior = pPrior; - if( rc ){ - goto multi_select_end; - } - if( addr ){ - sqlite3VdbeJumpHere(v, addr); - } - break; + int addr = 0; + assert( !pPrior->pLimit ); + pPrior->pLimit = p->pLimit; + pPrior->pOffset = p->pOffset; + rc = sqlite3Select(pParse, pPrior, &dest, 0, 0, 0); + p->pLimit = 0; + p->pOffset = 0; + if( rc ){ + goto multi_select_end; } - /* For UNION ALL ... ORDER BY fall through to the next case */ + p->pPrior = 0; + p->iLimit = pPrior->iLimit; + p->iOffset = pPrior->iOffset; + if( p->iLimit ){ + addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); + VdbeComment((v, "Jump ahead if LIMIT reached")); + } + rc = sqlite3Select(pParse, p, &dest, 0, 0, 0); + pDelete = p->pPrior; + p->pPrior = pPrior; + if( rc ){ + goto multi_select_end; + } + if( addr ){ + sqlite3VdbeJumpHere(v, addr); + } + break; } case TK_EXCEPT: case TK_UNION: { @@ -2023,7 +1993,7 @@ static int multiSelect( SelectDest uniondest; priorOp = p->op==TK_ALL ? SRT_Table : SRT_Union; - if( dest.eDest==priorOp && pOrderBy==0 && !p->pLimit && !p->pOffset ){ + if( dest.eDest==priorOp && !p->pLimit && !p->pOffset ){ /* We can reuse a temporary table generated by a SELECT to our ** right. */ @@ -2046,7 +2016,6 @@ static int multiSelect( p->addrOpenEphm[0] = addr; p->pRightmost->usesEphm = 1; } - createSortingIndex(pParse, p, pOrderBy); assert( p->pEList ); } @@ -2054,7 +2023,7 @@ static int multiSelect( */ assert( !pPrior->pOrderBy ); sqlite3SelectDestInit(&uniondest, priorOp, unionTab); - rc = sqlite3Select(pParse, pPrior, &uniondest, 0, 0, 0, aff); + rc = sqlite3Select(pParse, pPrior, &uniondest, 0, 0, 0); if( rc ){ goto multi_select_end; } @@ -2067,20 +2036,19 @@ static int multiSelect( case TK_ALL: op = SRT_Table; break; } p->pPrior = 0; - p->pOrderBy = 0; - p->disallowOrderBy = pOrderBy!=0; + p->disallowOrderBy = 0; pLimit = p->pLimit; p->pLimit = 0; pOffset = p->pOffset; p->pOffset = 0; uniondest.eDest = op; - rc = sqlite3Select(pParse, p, &uniondest, 0, 0, 0, aff); + rc = sqlite3Select(pParse, p, &uniondest, 0, 0, 0); /* Query flattening in sqlite3Select() might refill p->pOrderBy. ** Be sure to delete p->pOrderBy, therefore, to avoid a memory leak. */ sqlite3ExprListDelete(p->pOrderBy); pDelete = p->pPrior; p->pPrior = pPrior; - p->pOrderBy = pOrderBy; + p->pOrderBy = 0; sqlite3ExprDelete(p->pLimit); p->pLimit = pLimit; p->pOffset = pOffset; @@ -2108,7 +2076,7 @@ static int multiSelect( sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); iStart = sqlite3VdbeCurrentAddr(v); selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr, - pOrderBy, -1, &dest, iCont, iBreak, 0); + 0, -1, &dest, iCont, iBreak); sqlite3VdbeResolveLabel(v, iCont); sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); sqlite3VdbeResolveLabel(v, iBreak); @@ -2134,7 +2102,6 @@ static int multiSelect( rc = 1; goto multi_select_end; } - createSortingIndex(pParse, p, pOrderBy); addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0); assert( p->addrOpenEphm[0] == -1 ); @@ -2145,7 +2112,7 @@ static int multiSelect( /* Code the SELECTs to our left into temporary table "tab1". */ sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1); - rc = sqlite3Select(pParse, pPrior, &intersectdest, 0, 0, 0, aff); + rc = sqlite3Select(pParse, pPrior, &intersectdest, 0, 0, 0); if( rc ){ goto multi_select_end; } @@ -2161,7 +2128,7 @@ static int multiSelect( pOffset = p->pOffset; p->pOffset = 0; intersectdest.iParm = tab2; - rc = sqlite3Select(pParse, p, &intersectdest, 0, 0, 0, aff); + rc = sqlite3Select(pParse, p, &intersectdest, 0, 0, 0); pDelete = p->pPrior; p->pPrior = pPrior; sqlite3ExprDelete(p->pLimit); @@ -2189,7 +2156,7 @@ static int multiSelect( sqlite3VdbeAddOp3(v, OP_NotFound, tab2, iCont, r1); sqlite3ReleaseTempReg(pParse, r1); selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr, - pOrderBy, -1, &dest, iCont, iBreak, 0); + 0, -1, &dest, iCont, iBreak); sqlite3VdbeResolveLabel(v, iCont); sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); sqlite3VdbeResolveLabel(v, iBreak); @@ -2206,28 +2173,24 @@ static int multiSelect( sqlite3VdbeChangeP2(v, aSetP2[--nSetP2], nCol); } - /* Compute collating sequences used by either the ORDER BY clause or - ** by any temporary tables needed to implement the compound select. - ** Attach the KeyInfo structure to all temporary tables. Invoke the - ** ORDER BY processing if there is an ORDER BY clause. + /* Compute collating sequences used by + ** temporary tables needed to implement the compound select. + ** Attach the KeyInfo structure to all temporary tables. ** ** This section is run by the right-most SELECT statement only. ** SELECT statements to the left always skip this part. The right-most ** SELECT might also skip this part if it has no ORDER BY clause and ** no temp tables are required. */ - if( pOrderBy || p->usesEphm ){ + if( p->usesEphm ){ int i; /* Loop counter */ KeyInfo *pKeyInfo; /* Collating sequence for the result set */ Select *pLoop; /* For looping through SELECT statements */ - int nKeyCol; /* Number of entries in pKeyInfo->aCol[] */ CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */ - CollSeq **aCopy; /* A copy of pKeyInfo->aColl[] */ assert( p->pRightmost==p ); - nKeyCol = nCol + (pOrderBy ? pOrderBy->nExpr : 0); pKeyInfo = sqlite3DbMallocZero(pParse->db, - sizeof(*pKeyInfo)+nKeyCol*(sizeof(CollSeq*) + 1)); + sizeof(*pKeyInfo)+nCol*(sizeof(CollSeq*) + 1)); if( !pKeyInfo ){ rc = SQLITE_NOMEM; goto multi_select_end; @@ -2257,51 +2220,6 @@ static int multiSelect( pLoop->addrOpenEphm[i] = -1; } } - - if( pOrderBy ){ - struct ExprList_item *pOTerm = pOrderBy->a; - int nOrderByExpr = pOrderBy->nExpr; - int addr; - u8 *pSortOrder; - - /* Reuse the same pKeyInfo for the ORDER BY as was used above for - ** the compound select statements. Except we have to change out the - ** pKeyInfo->aColl[] values. Some of the aColl[] values will be - ** reused when constructing the pKeyInfo for the ORDER BY, so make - ** a copy. Sufficient space to hold both the nCol entries for - ** the compound select and the nOrderbyExpr entries for the ORDER BY - ** was allocated above. But we need to move the compound select - ** entries out of the way before constructing the ORDER BY entries. - ** Move the compound select entries into aCopy[] where they can be - ** accessed and reused when constructing the ORDER BY entries. - ** Because nCol might be greater than or less than nOrderByExpr - ** we have to use memmove() when doing the copy. - */ - aCopy = &pKeyInfo->aColl[nOrderByExpr]; - pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nCol]; - memmove(aCopy, pKeyInfo->aColl, nCol*sizeof(CollSeq*)); - - apColl = pKeyInfo->aColl; - for(i=0; ipExpr; - if( (pExpr->flags & EP_ExpCollate) ){ - assert( pExpr->pColl!=0 ); - *apColl = pExpr->pColl; - }else{ - *apColl = aCopy[pExpr->iColumn]; - } - *pSortOrder = pOTerm->sortOrder; - } - assert( p->pRightmost==p ); - assert( p->addrOpenEphm[2]>=0 ); - addr = p->addrOpenEphm[2]; - sqlite3VdbeChangeP2(v, addr, p->pOrderBy->nExpr+2); - pKeyInfo->nField = nOrderByExpr; - sqlite3VdbeChangeP4(v, addr, (char*)pKeyInfo, P4_KEYINFO_HANDOFF); - pKeyInfo = 0; - generateSortTail(pParse, p, v, p->pEList->nExpr, &dest); - } - sqlite3_free(pKeyInfo); } @@ -2558,8 +2476,7 @@ static int generateOutputSubroutine( static int multiSelectOrderBy( Parse *pParse, /* Parsing context */ Select *p, /* The right-most of SELECTs to be coded */ - SelectDest *pDest, /* What to do with query results */ - char *aff /* If eDest is SRT_Union, the affinity string */ + SelectDest *pDest /* What to do with query results */ ){ int i, j; /* Loop counters */ Select *pPrior; /* Another SELECT immediately to our left */ @@ -2758,7 +2675,7 @@ static int multiSelectOrderBy( */ VdbeNoopComment((v, "Begin coroutine for left SELECT")); pPrior->iLimit = regLimitA; - sqlite3Select(pParse, pPrior, &destA, 0, 0, 0, 0); + sqlite3Select(pParse, pPrior, &destA, 0, 0, 0); sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofA); sqlite3VdbeAddOp1(v, OP_Yield, regAddrA); VdbeNoopComment((v, "End coroutine for left SELECT")); @@ -2772,7 +2689,7 @@ static int multiSelectOrderBy( savedOffset = p->iOffset; p->iLimit = regLimitB; p->iOffset = 0; - sqlite3Select(pParse, p, &destB, 0, 0, 0, 0); + sqlite3Select(pParse, p, &destB, 0, 0, 0); p->iLimit = savedLimit; p->iOffset = savedOffset; sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofB); @@ -3731,8 +3648,7 @@ int sqlite3Select( SelectDest *pDest, /* What to do with the query results */ Select *pParent, /* Another SELECT for which this is a sub-query */ int parentTab, /* Index in pParent->pSrc of this query */ - int *pParentAgg, /* True if pParent uses aggregate functions */ - char *aff /* If eDest is SRT_Union, the affinity string */ + int *pParentAgg /* True if pParent uses aggregate functions */ ){ int i, j; /* Loop counters */ WhereInfo *pWInfo; /* Return from sqlite3WhereBegin() */ @@ -3839,7 +3755,7 @@ int sqlite3Select( i = -1; }else{ sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); - sqlite3Select(pParse, pSub, &dest, p, i, &isAgg, 0); + sqlite3Select(pParse, pSub, &dest, p, i, &isAgg); } if( pParse->nErr || db->mallocFailed ){ goto select_end; @@ -3876,7 +3792,7 @@ int sqlite3Select( return 1; } } - return multiSelect(pParse, p, pDest, aff); + return multiSelect(pParse, p, pDest); } #endif @@ -3963,7 +3879,7 @@ int sqlite3Select( */ assert(!isDistinct); selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, -1, pDest, - pWInfo->iContinue, pWInfo->iBreak, aff); + pWInfo->iContinue, pWInfo->iBreak); /* End the database scan loop. */ @@ -4073,7 +3989,7 @@ int sqlite3Select( } selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy, distinct, pDest, - addrOutputRow+1, addrSetAbort, aff); + addrOutputRow+1, addrSetAbort); sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); VdbeComment((v, "end groupby result generator")); @@ -4268,7 +4184,7 @@ int sqlite3Select( sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL); } selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, -1, - pDest, addrEnd, addrEnd, aff); + pDest, addrEnd, addrEnd); sqlite3ExprListDelete(pDel); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 103fd04fe6..3b22e94ca9 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.737 2008/07/08 22:28:49 shane Exp $ +** @(#) $Id: sqliteInt.h,v 1.738 2008/07/08 23:40:20 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -1922,7 +1922,7 @@ void sqlite3SrcListDelete(SrcList*); void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, Token*, int, int); void sqlite3DropIndex(Parse*, SrcList*, int); -int sqlite3Select(Parse*, Select*, SelectDest*, Select*, int, int*, char *aff); +int sqlite3Select(Parse*, Select*, SelectDest*, Select*, int, int*); Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, Expr*,ExprList*,int,Expr*,Expr*); void sqlite3SelectDelete(Select*); diff --git a/src/test_config.c b/src/test_config.c index 35ca0c188c..b62f8c01b0 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -16,7 +16,7 @@ ** The focus of this file is providing the TCL testing layer ** access to compile-time constants. ** -** $Id: test_config.c,v 1.30 2008/06/26 10:54:12 danielk1977 Exp $ +** $Id: test_config.c,v 1.31 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteLimit.h" @@ -64,7 +64,7 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY); #endif -#ifdef SQLITE_MEMDEBUG +#if 1 /* def SQLITE_MEMDEBUG */ Tcl_SetVar2(interp, "sqlite_options", "memdebug", "1", TCL_GLOBAL_ONLY); #else Tcl_SetVar2(interp, "sqlite_options", "memdebug", "0", TCL_GLOBAL_ONLY); diff --git a/src/trigger.c b/src/trigger.c index 36e82aeb38..ccee82917b 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -10,7 +10,7 @@ ************************************************************************* ** ** -** $Id: trigger.c,v 1.126 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: trigger.c,v 1.127 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteInt.h" @@ -680,7 +680,7 @@ static int codeTriggerProgram( sqlite3SelectDestInit(&dest, SRT_Discard, 0); sqlite3SelectResolve(pParse, ss, 0); - sqlite3Select(pParse, ss, &dest, 0, 0, 0, 0); + sqlite3Select(pParse, ss, &dest, 0, 0, 0); sqlite3SelectDelete(ss); } break; diff --git a/src/update.c b/src/update.c index 5ce03bf408..22d3012407 100644 --- a/src/update.c +++ b/src/update.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.178 2008/04/28 18:46:43 drh Exp $ +** $Id: update.c,v 1.179 2008/07/08 23:40:20 drh Exp $ */ #include "sqliteInt.h" @@ -649,7 +649,7 @@ static void updateVirtualTable( /* fill the ephemeral table */ sqlite3SelectDestInit(&dest, SRT_Table, ephemTab); - sqlite3Select(pParse, pSelect, &dest, 0, 0, 0, 0); + sqlite3Select(pParse, pSelect, &dest, 0, 0, 0); /* Generate code to scan the ephemeral table and call VUpdate. */ iReg = ++pParse->nMem; diff --git a/test/join.test b/test/join.test index 2a13128199..476145165a 100644 --- a/test/join.test +++ b/test/join.test @@ -12,7 +12,7 @@ # # This file implements tests for joins, including outer joins. # -# $Id: join.test,v 1.22 2006/06/20 11:01:09 danielk1977 Exp $ +# $Id: join.test,v 1.23 2008/07/08 23:40:20 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -233,11 +233,16 @@ do_test join-3.3 { SELECT * FROM t1 JOIN t2 ON t1.a=t2.b USING(b); } } {1 {cannot have both ON and USING clauses in the same join}} -do_test join-3.4 { +do_test join-3.4.1 { catchsql { SELECT * FROM t1 JOIN t2 USING(a); } } {1 {cannot join using column a - column not present in both tables}} +do_test join-3.4.2 { + catchsql { + SELECT * FROM t1 JOIN t2 USING(d); + } +} {1 {cannot join using column d - column not present in both tables}} do_test join-3.5 { catchsql { SELECT * FROM t1 USING(a); @@ -253,11 +258,31 @@ do_test join-3.7 { SELECT * FROM t1 INNER OUTER JOIN t2; } } {1 {unknown or unsupported join type: INNER OUTER}} -do_test join-3.7 { +do_test join-3.8 { + catchsql { + SELECT * FROM t1 INNER OUTER CROSS JOIN t2; + } +} {1 {unknown or unsupported join type: INNER OUTER CROSS}} +do_test join-3.9 { + catchsql { + SELECT * FROM t1 OUTER NATURAL INNER JOIN t2; + } +} {1 {unknown or unsupported join type: OUTER NATURAL INNER}} +do_test join-3.10 { catchsql { SELECT * FROM t1 LEFT BOGUS JOIN t2; } } {1 {unknown or unsupported join type: LEFT BOGUS}} +do_test join-3.11 { + catchsql { + SELECT * FROM t1 INNER BOGUS CROSS JOIN t2; + } +} {1 {unknown or unsupported join type: INNER BOGUS CROSS}} +do_test join-3.12 { + catchsql { + SELECT * FROM t1 NATURAL AWK SED JOIN t2; + } +} {1 {unknown or unsupported join type: NATURAL AWK SED}} do_test join-4.1 { execsql {