From: dan Date: Mon, 1 May 2017 14:09:32 +0000 (+0000) Subject: Add extra tests for the optimization on this branch. X-Git-Tag: version-3.19.0~28^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=181a1167dc24f86e106e62a3d9874099fe2cdebd;p=thirdparty%2Fsqlite.git Add extra tests for the optimization on this branch. FossilOrigin-Name: 4921cd9520080f9baff70e548f64a56e2204b398b8397a2d318a98c32ec4b00c --- diff --git a/manifest b/manifest index a30d603c08..d89bebfd83 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Automatically\stransfer\sterms\sfrom\sthe\sHAVING\sclause\sto\sthe\sWHERE\sclause\sof\san\naggregate\squery\sin\scases\swhere\sthe\sresult\sof\sevaluating\sthe\sterm\sdepends\sonly\none\sone\sor\smore\sof\sthe\sGROUP\sBY\sexpressions\s(and\son\sno\sother\sinputs). -D 2017-04-29T20:53:09.360 +C Add\sextra\stests\sfor\sthe\soptimization\son\sthis\sbranch. +D 2017-05-01T14:09:32.423 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6a8c838220f7c00820e1fc0ac1bccaaa8e5676067e1dbfa1bafa7a4ffecf8ae6 @@ -850,7 +850,7 @@ F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/gcfault.test dd28c228a38976d6336a3fc42d7e5f1ad060cb8c F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/having.test a03676a754815628a08d3b96d506dd9eda8ffbdd356cd8ea9c2e5368286fbe6a +F test/having.test 30a02b8a9a47cba7bdb5281999c5cbff407c2ac296511ee64dd0b418fe38eb0f F test/hexlit.test 4a6a5f46e3c65c4bf1fa06f5dd5a9507a5627751 F test/hidden.test 23c1393a79e846d68fd902d72c85d5e5dcf98711 F test/hook.test dbc0b87756e1e20e7497b56889c9e9cd2f8cc2b5 @@ -1578,10 +1578,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d7bb79ed3a40419d143fbe35c310e51fe7b384a22f082a61ad788671d2d33ee0 -R bd50b7d1e9edcc2d5d20fca02c02c5c7 -T *branch * having-where-optimization -T *sym-having-where-optimization * -T -sym-trunk * +P 5375a3ce56f1d993b13b469fe33ec7679948f53940f62a15ddbaeb8aaa26a22c +R 123e296789286f2ee6ee6640a2471eff U dan -Z 94cbfc69ef14a78710cd01b746487e79 +Z 8431f2088d761010cb187c22f8f8d978 diff --git a/manifest.uuid b/manifest.uuid index 57fc2eb5ff..2428b6a0d4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5375a3ce56f1d993b13b469fe33ec7679948f53940f62a15ddbaeb8aaa26a22c \ No newline at end of file +4921cd9520080f9baff70e548f64a56e2204b398b8397a2d318a98c32ec4b00c \ No newline at end of file diff --git a/test/having.test b/test/having.test index 7763b06850..6d2f9fdcc5 100644 --- a/test/having.test +++ b/test/having.test @@ -17,6 +17,8 @@ source $testdir/tester.tcl set testprefix having do_execsql_test 1.0 { + CREATE TABLE t2(c, d); + CREATE TABLE t1(a, b); INSERT INTO t1 VALUES(1, 1); INSERT INTO t1 VALUES(2, 2); @@ -34,11 +36,14 @@ foreach {tn sql res} { do_execsql_test 1.$tn $sql $res } +# Run an EXPLAIN command for both SQL statements. Return true if +# the outputs are identical, or false otherwise. +# proc compare_vdbe {sql1 sql2} { set r1 [list] set r2 [list] - db eval "explain $sql1" { lappend r1 $opcode $p1 $p2 $p3} - db eval "explain $sql2" { lappend r2 $opcode $p1 $p2 $p3} + db eval "explain $sql1" { lappend r1 $opcode $p1 $p2 $p3 $p4 $p5} + db eval "explain $sql2" { lappend r2 $opcode $p1 $p2 $p3 $p4 $p5} return [expr {$r1==$r2}] } @@ -46,17 +51,10 @@ proc do_compare_vdbe_test {tn sql1 sql2 res} { uplevel [list do_test $tn [list compare_vdbe $sql1 $sql2] $res] } -do_compare_vdbe_test 2.1 { - SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2 -} { - SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a -} 1 -do_compare_vdbe_test 2.2 { - SELECT a, sum(b) FROM t1 GROUP BY a+1 HAVING a=2 -} { - SELECT a, sum(b) FROM t1 GROUP BY a+1 HAVING a=2 -} 1 - +#------------------------------------------------------------------------- +# Test that various statements that are eligible for the optimization +# produce the same VDBE code as optimizing by hand does. +# foreach {tn sql1 sql2} { 1 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2" "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a" @@ -79,16 +77,78 @@ foreach {tn sql1 sql2} { GROUP BY a ) } + + 5 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE binary HAVING 0" + "SELECT a, sum(b) FROM t1 WHERE 0 GROUP BY a COLLATE binary" + + 6 "SELECT count(*) FROM t1,t2 WHERE a=c GROUP BY b, d HAVING b=d" + "SELECT count(*) FROM t1,t2 WHERE a=c AND b=d GROUP BY b, d" + + 7 { + SELECT count(*) FROM t1,t2 WHERE a=c GROUP BY b, d + HAVING b=d COLLATE nocase + } { + SELECT count(*) FROM t1,t2 WHERE a=c AND b=d COLLATE nocase + GROUP BY b, d + } + + 8 "SELECT a, sum(b) FROM t1 GROUP BY a||b HAVING substr(a||b, 1, 1)='a'" + "SELECT a, sum(b) FROM t1 WHERE substr(a||b, 1, 1)='a' GROUP BY a||b" } { - do_compare_vdbe_test 3.$tn $sql1 $sql2 1 + do_compare_vdbe_test 2.$tn $sql1 $sql2 1 } +#------------------------------------------------------------------------- +# 1: Test that the optimization is only applied if the GROUP BY term +# uses BINARY collation. +# +# 2: Not applied if there is a non-deterministic function in the HAVING +# term. +# foreach {tn sql1 sql2} { 1 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE nocase HAVING a=2" "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a COLLATE nocase" + + 2 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING randomblob(a)