diff options
author | drh <> | 2022-08-04 17:15:00 +0000 |
---|---|---|
committer | drh <> | 2022-08-04 17:15:00 +0000 |
commit | bffd5c1ece80bcf04512b2965d06bc89aaab7ba8 (patch) | |
tree | 8e2dca4ab22a63358d11da85a74b7fad732c0aad /src | |
parent | e24a6f58ae24670446f386578e63962633e8d4a6 (diff) | |
download | sqlite-bffd5c1ece80bcf04512b2965d06bc89aaab7ba8.tar.gz sqlite-bffd5c1ece80bcf04512b2965d06bc89aaab7ba8.zip |
Fix a problem with the query optimizer for LIMIT/OFFSET queries when
underlying query is a UNION ALL and both arms of the UNION ALL are
subqueries with an ORDER BY clause. This bug was reported at
[forum:/forumpost/6b5e9188f0657616|forum post 6b5e9188f0657616]. The
problem was introduced in 2015 (SQLite version 3.9.0) by check-in
[4b631364354068af]. See also ticket [b65cb2c8d91f6685].
FossilOrigin-Name: 6c806f64bbc9e98891bad0868575ee2ec5d0951ceb0c71d3ed417b45d5f27561
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/select.c b/src/select.c index d5c65bfb2..3f80e44ce 100644 --- a/src/select.c +++ b/src/select.c @@ -1688,7 +1688,7 @@ static void generateSortTail( if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce); addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak); VdbeCoverage(v); - codeOffset(v, p->iOffset, addrContinue); + assert( p->iLimit==0 && p->iOffset==0 ); sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab); bSeq = 0; }else{ @@ -1696,6 +1696,9 @@ static void generateSortTail( codeOffset(v, p->iOffset, addrContinue); iSortTab = iTab; bSeq = 1; + if( p->iOffset>0 ){ + sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1); + } } for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){ #ifdef SQLITE_ENABLE_SORTER_REFERENCES |