From bab39e1358f62bb566726a8e9beff9ff47caedd4 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Jul 2004 23:38:11 +0000 Subject: [PATCH] Refinements to the LIMIT patch (1823) for ticket #749. (CVS 1825) FossilOrigin-Name: 9d4f43f030438b3e7358032de2e04132b80e04a8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 11 +++++------ test/limit.test | 15 ++++++++++----- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 7d01ae3a80..d3e9ca57f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C LIMIT\soccurs\safter\sDISTINCT.\s\sTicket\s#749.\s(CVS\s1823) -D 2004-07-19T23:16:39 +C Refinements\sto\sthe\sLIMIT\spatch\s(1823)\sfor\sticket\s#749.\s(CVS\s1825) +D 2004-07-19T23:38:11 F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -57,7 +57,7 @@ F src/parse.y 51c8e696276c409618e66a4ccf316fcff245506e F src/pragma.c 8326df8c400f573eb43004dfb8e53e5102acb3e4 F src/printf.c 36090f6d7b4946539de97c1850675ce55ef66c16 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 -F src/select.c d4585c55c460dad2019964e5d0ae18f9b91cd142 +F src/select.c b8d0a8325552e46bf295ccfdad54668404fad88b F src/shell.c ebec5da57ea401f4886eefc790917b939d94d595 F src/sqlite.h.in aaf46c8d458efd8aca694ec4f18c6ecf616ee55e F src/sqliteInt.h aeae6793d1db335ec1179ad9f26b0affc0ec658a @@ -129,7 +129,7 @@ F test/join3.test 8d989e52413199065bd630b3d0a6b2329d173099 F test/join4.test 8dec387d06b3a4685e1104048065cf5236b99b93 F test/lastinsert.test 31382f88b9b0270333ac9e4a17f2c2f4732da718 F test/laststmtchanges.test 417aa27eb2b5cdfafb46e390e2c9ddd0a20eba43 -F test/limit.test 404a540e3fede22cab5667e12d7e3788617b07dc +F test/limit.test e4ee72ab4869992950f8cfce256e04a0a2a98b23 F test/lock.test 1dbf1d06b0a7eb36237b4f107cfb3da9726b449e F test/lock2.test 4108cabaa108a142e5eed83de3b13b6e579c12cf F test/main.test e8c4d9ca6d1e5f5e55e6550d31aec488883b2ed9 @@ -237,7 +237,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P a0f107ca66f825cc1fd10b15157b22fd9cc0f95c -R 2a77d36b9d379fa39cee995a7b6ac780 +P e6bc8aa80824a9156e78fc99b5ac7045b97d29c3 +R a1595d94360f07506cd424fa5219917d U drh -Z ebf8b5ec73a9dc2627883459f07e7b7c +Z 4dcf250616b0eecc7cd0cb15ba666c1d diff --git a/manifest.uuid b/manifest.uuid index 40ae21b745..c3ec5091ce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e6bc8aa80824a9156e78fc99b5ac7045b97d29c3 \ No newline at end of file +9d4f43f030438b3e7358032de2e04132b80e04a8 \ No newline at end of file diff --git a/src/select.c b/src/select.c index c362c02dd8..7fae4be4b7 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.198 2004/07/19 23:16:39 drh Exp $ +** $Id: select.c,v 1.199 2004/07/19 23:38:11 drh Exp $ */ #include "sqliteInt.h" @@ -324,13 +324,12 @@ static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){ ** Add code to implement the OFFSET and LIMIT */ static void codeLimiter( - Parse *pParse, /* Parsing context */ + Vdbe *v, /* Generate code into this VM */ Select *p, /* The SELECT statement being coded */ int iContinue, /* Jump here to skip the current record */ int iBreak, /* Jump here to end the loop */ int nPop /* Number of times to pop stack when jumping */ ){ - Vdbe *v = pParse->pVdbe; if( p->iOffset>=0 ){ int addr = sqlite3VdbeCurrentAddr(v) + 2; if( nPop>0 ) addr++; @@ -380,7 +379,7 @@ static int selectInnerLoop( */ hasDistinct = distinct>=0 && pEList && pEList->nExpr>0; if( pOrderBy==0 && !hasDistinct ){ - codeLimiter(pParse, p, iContinue, iBreak, 0); + codeLimiter(v, p, iContinue, iBreak, 0); } /* Pull the requested columns. @@ -413,7 +412,7 @@ static int selectInnerLoop( sqlite3VdbeAddOp(v, OP_String8, 0, 0); sqlite3VdbeAddOp(v, OP_PutStrKey, distinct, 0); if( pOrderBy==0 ){ - codeLimiter(pParse, p, iContinue, iBreak, nColumn); + codeLimiter(v, p, iContinue, iBreak, nColumn); } } @@ -582,7 +581,7 @@ static void generateSortTail( } sqlite3VdbeOp3(v, OP_Sort, 0, 0, (char*)pInfo, P3_KEYINFO_HANDOFF); addr = sqlite3VdbeAddOp(v, OP_SortNext, 0, end1); - codeLimiter(pParse, p, addr, end2, 1); + codeLimiter(v, p, addr, end2, 1); switch( eDest ){ case SRT_Table: case SRT_TempTable: { diff --git a/test/limit.test b/test/limit.test index 9282f0e3a2..8ac822fd63 100644 --- a/test/limit.test +++ b/test/limit.test @@ -12,7 +12,7 @@ # focus of this file is testing the LIMIT ... OFFSET ... clause # of SELECT statements. # -# $Id: limit.test,v 1.14 2004/07/19 23:16:39 drh Exp $ +# $Id: limit.test,v 1.15 2004/07/19 23:38:11 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -90,7 +90,6 @@ do_test limit-3.1 { } } {50 51 52 53 54} -btree_breakpoint do_test limit-4.1 { execsql { BEGIN; @@ -295,17 +294,23 @@ do_test limit-7.12 { } } {30} -# Tests for limit in conjunction with distinct +# Tests for limit in conjunction with distinct. The distinct should +# occur before both the limit and the offset. Ticket #749. # do_test limit-8.1 { execsql { - SELECT DISTINCT x/100 FROM t3 LIMIT 5; + SELECT DISTINCT round(x/100) FROM t3 LIMIT 5; } } {0 1 2 3 4} do_test limit-8.2 { execsql { - SELECT DISTINCT x/100 FROM t3 LIMIT 5 OFFSET 5; + SELECT DISTINCT round(x/100) FROM t3 LIMIT 5 OFFSET 5; } } {5 6 7 8 9} +do_test limit-8.3 { + execsql { + SELECT DISTINCT round(x/100) FROM t3 LIMIT 5 OFFSET 25; + } +} {25 26 27 28 29} finish_test