From 15d7982ad8192d6b66ed89f9c53d5605f7a7ddc8 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Tue, 15 May 2007 07:00:34 +0000 Subject: [PATCH] A fix for queries that used correlated, compound sub-queries in the HAVING clause. Also update fuzz.test some more. (CVS 4001) FossilOrigin-Name: da0c1ab4deedd2b952a43b3af6962a9403f8c9ee --- manifest | 16 +++++------ manifest.uuid | 2 +- src/expr.c | 5 +++- test/fuzz.test | 74 ++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 76 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index 2311f0bbfd..b87d2441fc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sproblems\sin\sALTER\sTABLE\sthat\soccur\swhen\scolumn\sor\stable\snames\sare\ninvalid\sUTF\sencodings.\s(CVS\s4000) -D 2007-05-15T03:56:49 +C A\sfix\sfor\squeries\sthat\sused\scorrelated,\scompound\ssub-queries\sin\sthe\sHAVING\sclause.\sAlso\supdate\sfuzz.test\ssome\smore.\s(CVS\s4001) +D 2007-05-15T07:00:34 F Makefile.in 87b200ad9970907f76df734d29dff3d294c10935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -70,7 +70,7 @@ F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 F src/date.c 6049db7d5a8fdf2c677ff7d58fa31d4f6593c988 F src/delete.c 5c0d89b3ef7d48fe1f5124bfe8341f982747fe29 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b -F src/expr.c bad06f783d2daf1884a922859c8e7427323e7dc3 +F src/expr.c 436f1d3e5addf95c195016b518cd2f44a6f5f081 F src/func.c cdbe36f2a71b7e6835189414c2fb626a339e300f F src/hash.c 67b23e14f0257b69a3e8aa663e4eeadc1a2b6fd5 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 @@ -248,7 +248,7 @@ F test/fts2l.test 4c53c89ce3919003765ff4fd8d98ecf724d97dd3 F test/fts2m.test 4b30142ead6f3ed076e880a2a464064c5ad58c51 F test/fts2n.test a70357e72742681eaebfdbe9007b87ff3b771638 F test/func.test bf30bac1c5ce10448ab739994268cf18f8b3fa30 -F test/fuzz.test f5c67c3bbf2031d6d1c08a546569831d53dc6452 +F test/fuzz.test 7a4c70e50c846e49611516869376d652463823a8 F test/fuzz2.test f1866329c9d0869297fb47fd1b4f597d5b66ac97 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a F test/icu.test e6bfae7f625c88fd14df6f540fe835bdfc1e4329 @@ -491,7 +491,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 1fbbc108a9e7ad1dc22c08ee990e2b6b949784eb -R b8fe54c7bac8048083b2ee052aff15ca -U drh -Z e8c0d1effc885ae48b4a6dcdd97879b1 +P 9ff382f4584ff685a78b39f24424319709efb382 +R 781ca6d5fc4b7ffe2d6fe8b39dfcde15 +U danielk1977 +Z dd0e0b0007aae2c4aac7b25601ed472b diff --git a/manifest.uuid b/manifest.uuid index 73ec0e36b2..dccf952b60 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9ff382f4584ff685a78b39f24424319709efb382 \ No newline at end of file +da0c1ab4deedd2b952a43b3af6962a9403f8c9ee \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index cfc534660e..921cca3435 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.293 2007/05/14 11:34:47 drh Exp $ +** $Id: expr.c,v 1.294 2007/05/15 07:00:34 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -804,6 +804,9 @@ static int walkSelectExpr(Select *p, int (*xFunc)(void *, Expr*), void *pArg){ walkExprList(p->pGroupBy, xFunc, pArg); walkExprTree(p->pHaving, xFunc, pArg); walkExprList(p->pOrderBy, xFunc, pArg); + if( p->pPrior ){ + walkSelectExpr(p->pPrior, xFunc, pArg); + } return 0; } diff --git a/test/fuzz.test b/test/fuzz.test index cb2af0dd57..19e9c1cb38 100644 --- a/test/fuzz.test +++ b/test/fuzz.test @@ -19,13 +19,15 @@ # # The most complicated trees are for SELECT statements. # -# $Id: fuzz.test,v 1.10 2007/05/14 16:50:49 danielk1977 Exp $ +# $Id: fuzz.test,v 1.11 2007/05/15 07:00:34 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl -# set ::REPEATS 20 set ::REPEATS 5000 +if {[info exists $::ISQUICK]} { + if {$::ISQUICK} { set ::REPEATS 20 } +} proc fuzz {TemplateList} { set n [llength $TemplateList] @@ -179,8 +181,8 @@ proc SimpleSelect {{nRes 0}} { if {$::SelectDepth < 4} { lappend TemplateList \ {[SelectKw] [ResultSet $nRes $::ColumnList] FROM ([Select])} \ - {[SelectKw] [ResultSet $nRes] FROM ([Select])} \ - {[SelectKw] [ResultSet $nRes $::ColumnList] FROM [Table]} \ + {[SelectKw] [ResultSet $nRes] FROM ([Select])} \ + {[SelectKw] [ResultSet $nRes $::ColumnList] FROM [Table]} \ { [SelectKw] [ResultSet $nRes $::ColumnList] FROM ([Select]) @@ -189,10 +191,10 @@ proc SimpleSelect {{nRes 0}} { } \ if {0 == $nRes} { - lappend TemplateList \ - {[SelectKw] * FROM ([Select])} \ - {[SelectKw] * FROM [Table]} \ - {[SelectKw] * FROM [Table] WHERE [Expr $::ColumnList]} \ + lappend TemplateList \ + {[SelectKw] * FROM ([Select])} \ + {[SelectKw] * FROM [Table]} \ + {[SelectKw] * FROM [Table] WHERE [Expr $::ColumnList]} \ { [SelectKw] * FROM [Table],[Table] AS t2 @@ -321,6 +323,26 @@ proc Coltype {} { fuzz $TemplateList } +proc DropTable {} { + set TemplateList { + {DROP TABLE IF EXISTS [Identifier]} + } + fuzz $TemplateList +} + +proc CreateView {} { + set TemplateList { + {CREATE VIEW [Identifier] AS [Select]} + } + fuzz $TemplateList +} +proc DropView {} { + set TemplateList { + {DROP VIEW IF EXISTS [Identifier]} + } + fuzz $TemplateList +} + proc CreateTable {} { set TemplateList { {CREATE TABLE [Identifier]([Identifier] [Coltype], [Identifier] [Coltype])} @@ -329,6 +351,16 @@ proc CreateTable {} { fuzz $TemplateList } +proc CreateOrDropTableOrView {} { + set TemplateList { + {[CreateTable]} + {[DropTable]} + {[CreateView]} + {[DropView]} + } + fuzz $TemplateList +} + ######################################################################## set ::log [open fuzzy.log w] @@ -496,6 +528,26 @@ do_test fuzz-1.13 { } } {abcd efgh} +do_test fuzz-1.14.1 { + execsql { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(123, 456, 789); + } + + # The [a] reference in the sub-select was causing a problem. Because + # the internal walkSelectExpr() function was not considering compound + # SELECT operators. + execsql { + SELECT 1 FROM abc + GROUP BY c HAVING EXISTS (SELECT a UNION SELECT 123); + } +} {1} +do_test fuzz-1.14.2 { + execsql { + DROP TABLE abc; + } +} {} + #---------------------------------------------------------------- # Test some fuzzily generated expressions. # @@ -565,10 +617,10 @@ do_test fuzz-7.4 {execsql COMMIT} {} integrity_check fuzz-7.5.integrity #---------------------------------------------------------------- -# Many CREATE TABLE statements: +# Many CREATE and DROP TABLE statements: # -do_fuzzy_test fuzz-8.1 -template {[CreateTable]} \ - -errorlist {table duplicate} -repeats 1000 +set E [list table duplicate {no such col} {ambiguous column name}] +do_fuzzy_test fuzz-8.1 -template {[CreateOrDropTableOrView]} -errorlist $E close $::log finish_test