]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix for ticket #31: Do not attempt the flattening optimization if the
authordrh <drh@noemail.net>
Tue, 30 Apr 2002 19:20:28 +0000 (19:20 +0000)
committerdrh <drh@noemail.net>
Tue, 30 Apr 2002 19:20:28 +0000 (19:20 +0000)
subselect does not contain a FROM clause.  Handle the special case where
a WHERE clause is constant. (CVS 548)

FossilOrigin-Name: 24e4cf73d22bb41d26bf3c833f1854a9c90923e8

VERSION
manifest
manifest.uuid
src/select.c
src/where.c
test/select6.test
test/where.test

diff --git a/VERSION b/VERSION
index 3f5987a5cb27b922145df269b485aa7c008cea39..b0f6bf0cd29cd4a9781fb3f61498d79f6712c0f0 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.4.9
+2.4.10
index 6dfb0f9cb10c368325b97475412fc411d671b6e9..21f04488f781a5e5c3d4685f797631b7ca1558d5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,9 +1,9 @@
-C Fix\sfor\sticket\s#28:\sExport\sthe\s"sqlite_changes"\sfunction\sin\sWindows\sDLLs.\s(CVS\s547)
-D 2002-04-26T09:47:21
+C Fix\sfor\sticket\s#31:\sDo\snot\sattempt\sthe\sflattening\soptimization\sif\sthe\nsubselect\sdoes\snot\scontain\sa\sFROM\sclause.\s\sHandle\sthe\sspecial\scase\swhere\na\sWHERE\sclause\sis\sconstant.\s(CVS\s548)
+D 2002-04-30T19:20:28
 F Makefile.in 50f1b3351df109b5774771350d8c1b8d3640130d
 F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
-F VERSION 23cded544ac22813b39f410aac0a8735ae991d64
+F VERSION 6e80c9947485276e468a2630f3c89616498507bf
 F aclocal.m4 11faa843caa38fd451bc6aeb43e248d1723a269d
 F config.guess f38b1e93d1e0fa6f5a6913e9e7b12774b9232588
 F config.log 6a73d03433669b10a3f0c221198c3f26b9413914
@@ -39,7 +39,7 @@ F src/pager.h 6fddfddd3b73aa8abc081b973886320e3c614f0e
 F src/parse.y 0ce56f1c751657f01e18a4b4ac1aa4d29525ac20
 F src/printf.c 300a90554345751f26e1fc0c0333b90a66110a1d
 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
-F src/select.c 04860119440c22b7f473bec848127d73af46db39
+F src/select.c 5e9fe2cdbb398be036c43bfa71b0686fcbbe5f96
 F src/shell.c 5acbe59e137d60d8efd975c683dbea74ab626530
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in ffcacf73b5ed1a4939205d29a704a185758fa6a6
@@ -55,7 +55,7 @@ F src/update.c 7dd714a6a7fa47f849ebb36b6d915974d6c6accb
 F src/util.c b34cd91387bbfdc79319ea451a7d120cef478120
 F src/vdbe.c 0ed88fff32273c103a24396d491b71bc69b4b596
 F src/vdbe.h 67840a462e1daedb958cca0ccc97db140d3d9152
-F src/where.c 9d36f6c9fea4af71501770c13089f824cb9b033c
+F src/where.c 5e3e97adfa5800378f2ed45bb9312dd3a70e239c
 F test/all.test 6aa106eee4d7127afa5cee97c51a783a79694ead
 F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
 F test/btree.test bf326f546a666617367a7033fa2c07451bd4f8e1
@@ -90,7 +90,7 @@ F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4
 F test/select3.test 9469c332250a75a0ef1771fb5da62dc04ec77f18
 F test/select4.test a8f1d97fbd6049211ddd0ed50899e8afb1cb4508
 F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac
-F test/select6.test 5b9b52e84c1f44fd3a4eeb75e78deceb085b78b0
+F test/select6.test efb8d0c07a440441db87db2c4ade6904e1407e85
 F test/sort.test 3b996ce7ca385f9cd559944ac0f4027a23aa546b
 F test/subselect.test 335d3dad8d585726c447dfee8d9c4f7383c76b78
 F test/table.test 17b0b6eafa3faaee5545b7a94e6c1ff73f0880f3
@@ -103,7 +103,7 @@ F test/unique.test 07776624b82221a80c8b4138ce0dd8b0853bb3ea
 F test/update.test 3cf1ca0565f678063c2dfa9a7948d2d66ae1a778
 F test/vacuum.test 059871b312eb910bbe49dafde1d01490cc2c6bbe
 F test/view.test 4a8a9cf59b54409228c7b9b918ed8bf9bade1220
-F test/where.test 032d581c3de4893eba33b569e581c46b941bb02a
+F test/where.test 1d85a7eba93e7acc0a971c6d9daead0e49cb023a
 F tool/lemon.c 77d026f58d7715543786d457cf9432f9103e3f62
 F tool/lempar.c ee508b94607f74d591d60eda5c8014db4e144de5
 F tool/memleak.awk 296dfbce7a9ca499b95ce04e30334e64a50052e0
@@ -132,7 +132,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 18c28519d973944756694b2c213bfef3153f4b1b
-R 2d6fab377f325966b8f3f4627b42b359
+P f7cea4634dd53204b4aa8a3630b9c55c40fdc4b3
+R 9d7c12ded1d4fd021880c7039e5ea94d
 U drh
-Z 3841c5ff7d19de6d1820c7833baa6b1c
+Z 70d8eddc023a9dcb2b671be415f0e5d2
index fdda7434bb03ebacbe1bf76d28e9063b747784b3..0563e9a8ec8bcc79ac8f3ac547257005ca75e5f5 100644 (file)
@@ -1 +1 @@
-f7cea4634dd53204b4aa8a3630b9c55c40fdc4b3
\ No newline at end of file
+24e4cf73d22bb41d26bf3c833f1854a9c90923e8
\ No newline at end of file
index 0f2fc609ad5f47b9459704db0c503189a7c71b97..530a7a3dda997f5e1559369f3ad2a1ff18839d04 100644 (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.79 2002/04/23 17:10:18 drh Exp $
+** $Id: select.c,v 1.80 2002/04/30 19:20:29 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -918,6 +918,8 @@ substExprList(ExprList *pList, int iTable, ExprList *pEList, int iSub){
 **   (6)  The subquery does not use aggregates or the outer query is not
 **        DISTINCT.
 **
+**   (7)  The subquery has a FROM clause.
+**
 ** 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.
@@ -947,7 +949,7 @@ int flattenSubquery(Select *p, int iFrom, int isAgg, int subqueryIsAgg){
   if( subqueryIsAgg && pSrc->nId>1 ) return 0;
   pSubSrc = pSub->pSrc;
   assert( pSubSrc );
-  if( pSubSrc->nId>1 ) return 0;
+  if( pSubSrc->nId!=1 ) return 0;
   if( pSub->isDistinct && pSrc->nId>1 ) return 0;
   if( pSub->isDistinct && isAgg ) return 0;
   if( p->isDistinct && subqueryIsAgg ) return 0;
index 0d685137a6d1a71671b3632d0fff238bf21af1d2..42b6bac4d03b7a237bcc43a9fc09358e7cb6ea3d 100644 (file)
@@ -13,7 +13,7 @@
 ** the WHERE clause of SQL statements.  Also found here are subroutines
 ** to generate VDBE code to evaluate expressions.
 **
-** $Id: where.c,v 1.40 2002/04/02 13:26:11 drh Exp $
+** $Id: where.c,v 1.41 2002/04/30 19:20:29 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -193,6 +193,14 @@ WhereInfo *sqliteWhereBegin(
   pWInfo->pTabList = pTabList;
   pWInfo->base = base;
   pWInfo->peakNTab = pWInfo->savedNTab = pParse->nTab;
+  pWInfo->iBreak = sqliteVdbeMakeLabel(v);
+
+  /* Special case: a WHERE clause that is constant.  Evaluate the
+  ** expression and either jump over all of the code or fall thru.
+  */
+  if( pWhere && sqliteExprIsConstant(pWhere) ){
+    sqliteExprIfFalse(pParse, pWhere, pWInfo->iBreak);
+  }
 
   /* Split the WHERE clause into as many as 32 separate subexpressions
   ** where each subexpression is separated by an AND operator.  Any additional
@@ -422,7 +430,6 @@ WhereInfo *sqliteWhereBegin(
   /* Generate the code to do the search
   */
   loopMask = 0;
-  pWInfo->iBreak = sqliteVdbeMakeLabel(v);
   for(i=0; i<pTabList->nId; i++){
     int j, k;
     int idx = aOrder[i];
index 9091677454ce568094d83ef95caeadab6f6fcf17..8fe71e1961bb37cb140e9c9a3baa473297aeaa48 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing SELECT statements that contain
 # subqueries in their FROM clause.
 #
-# $Id: select6.test,v 1.8 2002/03/23 00:31:29 drh Exp $
+# $Id: select6.test,v 1.9 2002/04/30 19:20:29 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -336,4 +336,27 @@ do_test select6-6.6 {
   }
 } {1 3}
 
+# Subselects with no FROM clause
+#
+do_test select6-7.1 {
+  execsql {
+    SELECT * FROM (SELECT 1)
+  }
+} {1}
+do_test select6-7.2 {
+  execsql {
+    SELECT c,b,a,* FROM (SELECT 1 AS 'a', 2 AS 'b', 'abc' AS 'c')
+  }
+} {abc 2 1 1 2 abc}
+do_test select6-7.3 {
+  execsql {
+    SELECT c,b,a,* FROM (SELECT 1 AS 'a', 2 AS 'b', 'abc' AS 'c' WHERE 0)
+  }
+} {}
+do_test select6-7.4 {
+  execsql2 {
+    SELECT c,b,a,* FROM (SELECT 1 AS 'a', 2 AS 'b', 'abc' AS 'c' WHERE 1)
+  }
+} {c abc b 2 a 1 a 1 b 2 c abc}
+
 finish_test
index 4ab658b14476afc44ad4ada7baab6d93239c2bc9..fc6d8bd7b224a6bafefaf4459fd996c2c0c9dc03 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the use of indices in WHERE clases.
 #
-# $Id: where.test,v 1.5 2001/12/22 14:49:26 drh Exp $
+# $Id: where.test,v 1.6 2002/04/30 19:20:29 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -237,4 +237,29 @@ do_test where-3.3 {
   }
 } {15 86 86 9}
 
+# Test to see that the special case of a constant WHERE clause is
+# handled.
+#
+do_test where-4.1 {
+  count {
+    SELECT * FROM t1 WHERE 0
+  }
+} {0}
+do_test where-4.2 {
+  count {
+    SELECT * FROM t1 WHERE 1 LIMIT 1
+  }
+} {1 0 4 0}
+do_test where-4.3 {
+  execsql {
+    SELECT 99 WHERE 0
+  }
+} {}
+do_test where-4.4 {
+  execsql {
+    SELECT 99 WHERE 1
+  }
+} {99}
+
+
 finish_test