1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Prevent the flattening optimization from transforming a to a query with an illegal ORDER BY clause. (CVS 5372)

FossilOrigin-Name: 6c2adade34fdbe344cf73f6bac951e0c37dd003b
This commit is contained in:
danielk1977
2008-07-08 17:43:56 +00:00
parent 1bc71590c4
commit 49fc1f60b0
5 changed files with 36 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Test\sanother\scorruption\scase\sin\sbtree.c.\sAnd\san\sIO\serror\srelated\sscenario.\s(CVS\s5371)
D 2008-07-08T17:13:59
C Prevent\sthe\sflattening\soptimization\sfrom\stransforming\sa\sto\sa\squery\swith\san\sillegal\sORDER\sBY\sclause.\s(CVS\s5372)
D 2008-07-08T17:43:57
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -140,7 +140,7 @@ F src/pragma.c 6fad83fbcc7ec6e76d91fe2805fe972ff3af6a0c
F src/prepare.c aba51dad52308e3d9d2074d8ff4e612e7f1cab51
F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e
F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
F src/select.c 3e44f3910660ab63c690d2a4eac5449ae48ce96b
F src/select.c 183a68a0af4ce20c8ebe684dd1581ce898c9f48f
F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0
F src/sqlite.h.in 22c32cedf7e435d5b3bb8564ce0a640c40dbbfb1
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
@ -341,7 +341,7 @@ F test/in2.test b1f447f4f0f67e9f83ff931e7e2e30873f9ea055
F test/in3.test dc62b080ed79898121c61c91118b4d1e111f1438
F test/incrblob.test 4455fffd08b2f9418a9257e18b135d72273eff3e
F test/incrblob2.test c82a780356bdf4d0c77f1adf0ea888248904fc07
F test/incrblob_err.test 96ae06bbb7d0cb2cad39744a32e57af5c07412e4
F test/incrblob_err.test 50eff975fd19ea7d0f376a4488a17315ec0703fd
F test/incrvacuum.test 1a2b0bddc76629afeb41e3d8ea3e4563982d16b9
F test/incrvacuum2.test 46ef65f377e3937cfd1ba66e818309dab46f590d
F test/incrvacuum_ioerr.test ebc94092ac1545d9ce518a673988aef88197ca4e
@ -451,7 +451,7 @@ F test/select7.test 7906735805cfbee4dddc0bed4c14e68d7f5f9c5f
F test/select8.test 391de11bdd52339c30580dabbbbe97e3e9a3c79d
F test/select9.test b4007b15396cb7ba2615cab31e1973b572e43210
F test/selectA.test e4501789a1d0fe9d00db15187623fb5b7031357b
F test/selectB.test 811a852ad6567f3d6f786619511f9c4b2ed1defd
F test/selectB.test 09ae87083e87e76924fa85206fc69f55f23a9aeb
F test/server1.test f5b790d4c0498179151ca8a7715a65a7802c859c
F test/shared.test f1066281aa19517ab8dbe76328afadff76516f67
F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4
@ -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 96df0a5fa4bb2b3dfedf034d81704e152cdc63a9
R bc52d4843754cbd36c0ef3202e607fb2
P d74fbb81ca3f973ac46534344e5076afc5dd5491
R e1ce45277dc48c16e1fe351ba15bc433
U danielk1977
Z 01c21e73d1086c9de6763f3a0f6454a5
Z 27ce1f86b9768bde4d591564b2a9be66

View File

@ -1 +1 @@
d74fbb81ca3f973ac46534344e5076afc5dd5491
6c2adade34fdbe344cf73f6bac951e0c37dd003b

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.447 2008/07/02 16:10:46 danielk1977 Exp $
** $Id: select.c,v 1.448 2008/07/08 17:43:57 danielk1977 Exp $
*/
#include "sqliteInt.h"
@ -3074,6 +3074,10 @@ static void substSelect(
** rules (11), (13) and (14), they may also contain ORDER BY,
** LIMIT and OFFSET clauses.
**
** (18) If the sub-query is a compound select, then all terms of the
** ORDER by clause of the parent must be simple references to
** columns of the sub-query.
**
** In this routine, the "p" parameter is a pointer to the outer query.
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates.
@ -3110,6 +3114,7 @@ static int flattenSubquery(
pSrc = p->pSrc;
assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
pSubitem = &pSrc->a[iFrom];
iParent = pSubitem->iCursor;
pSub = pSubitem->pSelect;
assert( pSub!=0 );
if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */
@ -3185,6 +3190,17 @@ static int flattenSubquery(
return 0;
}
}
/* Restriction 18. */
if( p->pOrderBy ){
int ii;
for(ii=0; ii<p->pOrderBy->nExpr; ii++){
Expr *pExpr = p->pOrderBy->a[ii].pExpr;
if( pExpr->op!=TK_COLUMN || pExpr->iTable!=iParent ){
return 0;
}
}
}
}
pParse->zAuthContext = pSubitem->zName;
@ -3228,7 +3244,6 @@ static int flattenSubquery(
** iFrom-th entry of the FROM clause in the outer query.
*/
pSub = pSub1 = pSubitem->pSelect;
iParent = pSubitem->iCursor;
for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
int nSubSrc = pSubSrc->nSrc;
int jointype = 0;

View File

@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: incrblob_err.test,v 1.11 2008/07/08 12:07:33 danielk1977 Exp $
# $Id: incrblob_err.test,v 1.12 2008/07/08 17:43:57 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@ -131,4 +131,6 @@ do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep {
close $::blob
}
db2 close
finish_test

View File

@ -10,7 +10,7 @@
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: selectB.test,v 1.5 2008/07/01 18:26:51 danielk1977 Exp $
# $Id: selectB.test,v 1.6 2008/07/08 17:43:57 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -357,6 +357,12 @@ for {set ii 3} {$ii <= 4} {incr ii} {
)
}
} {0 1}
do_test selectB-$ii.21 {
execsql {
SELECT * FROM (SELECT * FROM t1 UNION ALL SELECT * FROM t2) ORDER BY a+b
}
} {2 4 6 3 6 9 8 10 12 12 15 18 14 16 18 21 24 27}
}
finish_test