From: danielk1977 Date: Tue, 1 Jul 2008 14:39:35 +0000 (+0000) Subject: Fix a problem with LIMIT and OFFSET clauses on the parent query when optimizing a... X-Git-Tag: version-3.6.10~845 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b86ef1d8767b82cea42ead0616e46a0a9c794e4;p=thirdparty%2Fsqlite.git Fix a problem with LIMIT and OFFSET clauses on the parent query when optimizing a UNION ALL sub-select. (CVS 5332) FossilOrigin-Name: a79786a961dba8f4ffaddbe55e6467c14b12f7d6 --- diff --git a/manifest b/manifest index 7477e81d1b..135265649d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\ssub-selects\sand\sviews\sthat\suse\sUNION\sALL.\sThis\soptimization\sisn't\svery\swell\stested\syet.\s(CVS\s5331) -D 2008-07-01T14:09:14 +C Fix\sa\sproblem\swith\sLIMIT\sand\sOFFSET\sclauses\son\sthe\sparent\squery\swhen\soptimizing\sa\sUNION\sALL\ssub-select.\s(CVS\s5332) +D 2008-07-01T14:39:35 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 727e546cd941a336d11a0e21da653ea53da53467 +F src/select.c d1b633882c90a8c8f9e8346d20b3f038dfee48bd F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0 F src/sqlite.h.in 76c144d23f8824e8811e837e9396b9f1361f5902 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e @@ -447,9 +447,9 @@ F test/select5.test 5ad14ea338aada2e6394ba98fa9aa40e3e50aec0 F test/select6.test 399f14b9ba37b768afe5d2cd8c12e4f340a69db8 F test/select7.test 7906735805cfbee4dddc0bed4c14e68d7f5f9c5f F test/select8.test 391de11bdd52339c30580dabbbbe97e3e9a3c79d -F test/select9.test 2f52de9bcca6002ff9ad57b045a023e2dff6438d +F test/select9.test b4007b15396cb7ba2615cab31e1973b572e43210 F test/selectA.test e4501789a1d0fe9d00db15187623fb5b7031357b -F test/selectB.test ade563cde5bc0f384d8b5de99e9aa036cd1a5e7f +F test/selectB.test 37d21b6f1896b2cadac36faf9c0255f07467f669 F test/server1.test f5b790d4c0498179151ca8a7715a65a7802c859c F test/shared.test c6769531e0cb751d46a9838c0532d3786606c0f6 F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4 @@ -596,7 +596,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 6fcb3bffe26ae1c21c72ce9019f1db1c118094a4 -R a2583ef5b7a521dcade25acc745843b4 +P 3ef468e7046b2091b5b6880fe19261ef1ee2887b +R 57b50557616e52f60ca94711b38caba6 U danielk1977 -Z ee7031ff29f21965f0690349b2076acb +Z 5823aa889da28368a392c306fc60b4e7 diff --git a/manifest.uuid b/manifest.uuid index e9c74619cb..0b9e63c5fe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3ef468e7046b2091b5b6880fe19261ef1ee2887b \ No newline at end of file +a79786a961dba8f4ffaddbe55e6467c14b12f7d6 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 7956dccf47..7eaa919974 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.441 2008/07/01 14:09:14 danielk1977 Exp $ +** $Id: select.c,v 1.442 2008/07/01 14:39:35 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -3191,16 +3191,21 @@ static int flattenSubquery( for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){ Select *pNew; ExprList *pOrderBy = p->pOrderBy; + Expr *pLimit = p->pLimit; + Expr *pOffset = p->pOffset; Select *pPrior = p->pPrior; p->pOrderBy = 0; p->pSrc = 0; p->pPrior = 0; + p->pLimit = 0; pNew = sqlite3SelectDup(db, p); pNew->pPrior = pPrior; p->pPrior = pNew; p->pOrderBy = pOrderBy; p->op = TK_ALL; p->pSrc = pSrc; + p->pLimit = pLimit; + p->pOffset = pOffset; p->pRightmost = 0; pNew->pRightmost = 0; } diff --git a/test/select9.test b/test/select9.test index db40c592a5..eeadf13d6e 100644 --- a/test/select9.test +++ b/test/select9.test @@ -10,7 +10,7 @@ #*********************************************************************** # This file implements regression tests for SQLite library. # -# $Id: select9.test,v 1.3 2008/06/30 07:53:10 danielk1977 Exp $ +# $Id: select9.test,v 1.4 2008/07/01 14:39:35 danielk1977 Exp $ # The tests in this file are focused on test compound SELECT statements # that have any or all of an ORDER BY, LIMIT or OFFSET clauses. As of @@ -360,7 +360,7 @@ proc cksort {sql} { # CREATE VIEW v1 AS SELECT a FROM t1 UNION ALL SELECT d FROM t2 # SELECT a FROM v1 ORDER BY 1 # -# Currently it is not. +# It turns out that it is. # do_test select9-3.1 { cksort { SELECT a FROM t1 ORDER BY 1 } @@ -379,7 +379,7 @@ do_test select9-3.4 { do_test select9-3.5 { execsql { CREATE VIEW v1 AS SELECT a FROM t1 UNION ALL SELECT d FROM t2 } cksort { SELECT a FROM v1 ORDER BY 1 LIMIT 5 } -} {1 1 2 2 3 sort} +} {1 1 2 2 3 nosort} do_test select9-3.X { execsql { DROP INDEX i1; diff --git a/test/selectB.test b/test/selectB.test index 4df6434f19..de3fb0374f 100644 --- a/test/selectB.test +++ b/test/selectB.test @@ -10,7 +10,7 @@ #*********************************************************************** # This file implements regression tests for SQLite library. # -# $Id: selectB.test,v 1.1 2008/07/01 14:09:14 danielk1977 Exp $ +# $Id: selectB.test,v 1.2 2008/07/01 14:39:35 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -93,6 +93,19 @@ test_transform selectB-1.6 { ORDER BY a } {14 21} +test_transform selectB-1.7 { + SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT d FROM t2) ORDER BY 1 LIMIT 2 +} { + SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 LIMIT 2 +} {2 3} + +test_transform selectB-1.8 { + SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT d FROM t2) ORDER BY 1 + LIMIT 2 OFFSET 3 +} { + SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 LIMIT 2 OFFSET 3 +} {12 14} + finish_test