Fix a problem with the sorting of literals in a compound query. Ticket #1501. (CVS 2770)

FossilOrigin-Name: b3882b434a1ef7d8d636c7c5917b9e8f0d2952fb
This commit is contained in:
drh 2005-11-16 13:47:50 +00:00
parent 7e56e71125
commit 4efc083f57
4 changed files with 44 additions and 12 deletions

View File

@ -1,5 +1,5 @@
C Do\snot\sallow\saggregate\sfunctions\sin\sa\sWHERE\sclause.\s\sTicket\s#1514.\s(CVS\s2769)
D 2005-11-16T12:53:15
C Fix\sa\sproblem\swith\sthe\ssorting\sof\sliterals\sin\sa\scompound\squery.\sTicket\s#1501.\s(CVS\s2770)
D 2005-11-16T13:47:51
F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -64,7 +64,7 @@ F src/pragma.c b40189967155a522433b8470f363192a927ba22c
F src/prepare.c fc098db25d2a121affb08686cf04833fd50452d4
F src/printf.c 3ea3a17d25d7ac498efc18007c70371a42c968f8
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
F src/select.c 095d5b7a9c1989f2855d496d49096559fa67710d
F src/select.c 4a9e5366f4a16bd2e6e93c05f585633887be6372
F src/shell.c 3596c1e559b82663057940d19ba533ad421c7dd3
F src/sqlite.h.in 8e648e1f386e4509f2f96c09ded7c07b0df0c9a2
F src/sqliteInt.h 4148c9778e350014c2e27b332d7a2ef7278fe62e
@ -226,6 +226,7 @@ F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
F test/tkt1444.test 5ef55d36dba1a39a96c728a519e66378a6f6816f
F test/tkt1449.test f8de8a84ec12ee805ed80055e1209560f8bee4d8
F test/tkt1473.test e4637c27d606fd002de78113a8e1a142e48ffb18
F test/tkt1501.test 0cf859299f0052ecfaf7db6f0984f122c7db5d15
F test/tkt1512.test 8efd8d07e27e99d7462f75b5711de65eb7708baf
F test/tkt1514.test baa587a69fa2e8d575ebdaf1460f711281dcba49
F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
@ -318,7 +319,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 2e195e96bcbad104da09ebe6cef617e0e9ef1884
R ffdeff6933e9c8149230cb664075bfe1
P bb866ed880c33ec9ce6ded8ebdbb459fedf9c257
R 7c9a33e45e816665be15765531c18711
U drh
Z b747cc0c814ab502d11e59e2f8d36ee2
Z aa3c54ef29f09c5fa4da147679eb55f1

View File

@ -1 +1 @@
bb866ed880c33ec9ce6ded8ebdbb459fedf9c257
b3882b434a1ef7d8d636c7c5917b9e8f0d2952fb

View File

@ -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.279 2005/11/14 22:29:05 drh Exp $
** $Id: select.c,v 1.280 2005/11/16 13:47:51 drh Exp $
*/
#include "sqliteInt.h"
@ -1814,15 +1814,15 @@ static int multiSelect(
if( pOrderBy ){
struct ExprList_item *pOTerm = pOrderBy->a;
int nExpr = pOrderBy->nExpr;
int nOrderByExpr = pOrderBy->nExpr;
int addr;
u8 *pSortOrder;
aCopy = (CollSeq**)&pKeyInfo[1];
pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nExpr];
pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nCol];
memcpy(aCopy, pKeyInfo->aColl, nCol*sizeof(CollSeq*));
apColl = pKeyInfo->aColl;
for(i=0; i<pOrderBy->nExpr; i++, pOTerm++, apColl++, pSortOrder++){
for(i=0; i<nOrderByExpr; i++, pOTerm++, apColl++, pSortOrder++){
Expr *pExpr = pOTerm->pExpr;
char *zName = pOTerm->zName;
assert( pExpr->op==TK_COLUMN && pExpr->iColumn<nCol );
@ -1837,7 +1837,7 @@ static int multiSelect(
assert( p->addrOpenVirt[2]>=0 );
addr = p->addrOpenVirt[2];
sqlite3VdbeChangeP2(v, addr, p->pEList->nExpr+2);
pKeyInfo->nField = pOrderBy->nExpr;
pKeyInfo->nField = nOrderByExpr;
sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
pKeyInfo = 0;
generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm);

31
test/tkt1501.test Normal file
View File

@ -0,0 +1,31 @@
# 2005 November 16
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that ticket #1501 is
# fixed.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test tkt1501-1.1 {
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,2);
SELECT a, b, 'abc' FROM t1
UNION
SELECT b, a, 'xyz' FROM t1
ORDER BY 2, 3;
}
} {2 1 xyz 1 2 abc}
finish_test