1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-08 03:22:21 +03:00

Do not optimize views with an ORDER BY clause if they are used in a UNION ALL

that also has an ORDER BY clause.  Ticket #1444. (CVS 2723)

FossilOrigin-Name: 6cc57fcf15cfa3ce73c78b1cac90f7806e5bae40
This commit is contained in:
drh
2005-09-19 17:35:53 +00:00
parent a7aa59e097
commit 4b14b4d720
5 changed files with 65 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
C Fix\suninitialized\svalue\son\sa\sUNION\sALL\sselect\swith\san\sORDER\sBY\sclause.\s(CVS\s2722)
D 2005-09-19T15:37:07
C Do\snot\soptimize\sviews\swith\san\sORDER\sBY\sclause\sif\sthey\sare\sused\sin\sa\sUNION\sALL\nthat\salso\shas\san\sORDER\sBY\sclause.\s\sTicket\s#1444.\s(CVS\s2723)
D 2005-09-19T17:35:53
F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -63,10 +63,10 @@ F src/pragma.c 6d773e25e8af13ef0820531ad2793417f8a8959d
F src/prepare.c fc098db25d2a121affb08686cf04833fd50452d4
F src/printf.c bd421c1ad5e01013c89af63c60eab02852ccd15e
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
F src/select.c 2d6a485a3fcb342e132ca1542556c1afaad56686
F src/select.c 459fb935f1b3f6f0011c548a7664b4d7d062a041
F src/shell.c 3596c1e559b82663057940d19ba533ad421c7dd3
F src/sqlite.h.in 461b2535550cf77aedfd44385da11ef7d63e57a2
F src/sqliteInt.h cc5874662b2b3236e2d70a23429561b9f469c423
F src/sqliteInt.h f59e1ceccfca73737016b8912ac5f23995dd40c6
F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
F src/tclsqlite.c ac94682f9e601dd373912c46414a5a842db2089a
F src/test1.c 0f1a66f65a54fba029f7e93b7500d49443dc959b
@@ -219,6 +219,7 @@ F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
F test/tkt1435.test f768e5415d102fa1d8de3f548469d8fd1b79abd8
F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
F test/tkt1444.test 0f0fc1f277691f904dea2abece6db919dcae2351
F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e
F test/trigger1.test 152aed5a1fa90709fe171f2ca501a6b7f7901479
@@ -309,7 +310,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 41e226d2ff5c0021fd07388da13f6d750fac508b
R 8bfb93d2bda540419ac9c07075b31e02
P 92126a216101d30e16390bf063d52d7182fbc763
R 72c2d98bc3d985fe2db9dcfe0f467d3c
U drh
Z fdd630cee04ef4f9384ba8eea195e4c7
Z 91dd1e861c7623fcdb1db511dd98ef1d

View File

@@ -1 +1 @@
92126a216101d30e16390bf063d52d7182fbc763
6cc57fcf15cfa3ce73c78b1cac90f7806e5bae40

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.270 2005/09/19 15:37:07 drh Exp $
** $Id: select.c,v 1.271 2005/09/19 17:35:53 drh Exp $
*/
#include "sqliteInt.h"
@@ -1571,6 +1571,7 @@ static int multiSelect(
}
p->pPrior = 0;
p->pOrderBy = 0;
p->disallowOrderBy = pOrderBy!=0;
pLimit = p->pLimit;
p->pLimit = 0;
pOffset = p->pOffset;
@@ -1971,7 +1972,7 @@ static int flattenSubquery(
return 0;
}
if( p->isDistinct && subqueryIsAgg ) return 0;
if( p->pOrderBy && pSub->pOrderBy ) return 0;
if( (p->disallowOrderBy || p->pOrderBy) && pSub->pOrderBy ) return 0;
/* Restriction 3: If the subquery is a join, make sure the subquery is
** not used as the right operand of an outer join. Examples of why this

View File

@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.419 2005/09/17 15:20:27 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.420 2005/09/19 17:35:53 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -1118,6 +1118,7 @@ struct Select {
u8 isResolved; /* True once sqlite3SelectResolve() has run. */
u8 isAgg; /* True if this is an aggregate query */
u8 usesVirt; /* True if uses an OpenVirtual opcode */
u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */
SrcList *pSrc; /* The FROM clause */
Expr *pWhere; /* The WHERE clause */
ExprList *pGroupBy; /* The GROUP BY clause */

51
test/tkt1444.test Normal file
View File

@@ -0,0 +1,51 @@
# 2005 September 19
#
# 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 #1444 has been
# fixed.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# The use of a VIEW that contained an ORDER BY clause within a UNION ALL
# was causing problems. See ticket #1444.
#
do_test tkt1444-1.1 {
execsql {
CREATE TABLE DemoTable (x INTEGER, TextKey TEXT, DKey Real);
CREATE INDEX DemoTableIdx ON DemoTable (TextKey);
INSERT INTO DemoTable VALUES(9,8,7);
INSERT INTO DemoTable VALUES(1,2,3);
CREATE VIEW DemoView AS SELECT * FROM DemoTable ORDER BY TextKey;
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView ORDER BY 1;
}
} {1 2 3 1 2 3 9 8 7 9 8 7}
do_test tkt1444-1.2 {
execsql {
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView;
}
} {9 8 7 1 2 3 1 2 3 9 8 7}
do_test tkt1444-1.3 {
execsql {
DROP VIEW DemoView;
CREATE VIEW DemoView AS SELECT * FROM DemoTable;
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView ORDER BY 1;
}
} {1 2 3 1 2 3 9 8 7 9 8 7}
do_test tkt1444-1.4 {
execsql {
SELECT * FROM DemoTable UNION ALL SELECT * FROM DemoView;
}
} {9 8 7 1 2 3 9 8 7 1 2 3}
finish_test