Add tests to ensure that the window functions implementation is not generating code for unnecessary sorts.

FossilOrigin-Name: e195948a6876efe01b5cf2ed67bc9015a781fda39dca668099cb7edc1d331818
This commit is contained in:
dan 2019-03-19 17:45:31 +00:00
parent 1d4b25fa50
commit 8eff0cc326
5 changed files with 71 additions and 9 deletions

View File

@ -1,5 +1,5 @@
C Add\smissing\sVdbeCoverage()\smacros\sto\snew\scode\sin\swindow.c.
D 2019-03-19T16:49:15.124
C Add\stests\sto\sensure\sthat\sthe\swindow\sfunctions\simplementation\sis\snot\sgenerating\scode\sfor\sunnecessary\ssorts.
D 2019-03-19T17:45:31.515
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -1677,7 +1677,7 @@ F test/win32heap.test 10fd891266bd00af68671e702317726375e5407561d859be1aa04696f2
F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972
F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d
F test/win32nolock.test ac4f08811a562e45a5755e661f45ca85892bdbbc
F test/window1.test 320d881253330f51e5065fd6e4eae35cedf598bf5b141f49bcf88e4e054da195
F test/window1.test c7c274d5af62f52cbb6294a2bc1db93a8a919fac58abeaccd6684327fd070557
F test/window2.tcl 9bfa842d8a62b0d36dc8c1b5972206393c43847433c6d75940b87fec93ce3143
F test/window2.test 8e6d2a1b9f54dfebee1cde961c8590cd87b4db45c50f44947a211e1b63c2a05e
F test/window3.tcl acea6e86a4324a210fd608d06741010ca83ded9fde438341cb978c49928faf03
@ -1688,8 +1688,8 @@ F test/window5.test d328dd18221217c49c144181975eea17339eaeaf0e9aa558cee3afb84652
F test/window6.test 604890f2b0f976339e6a1774cd90d48840e57a54b4f21a8b4b3047aa2c9787d1
F test/window7.tcl 6a1210f05d40ec89c22960213a22cd3f98d4e2f2eb20646c83c8c30d4d76108f
F test/window7.test ce7f865241fdd1c5c4db869cd7bb2986c3be836bc2e73649a6846dd920f63e0f
F test/window8.tcl 969c2fe8d8f4f33d34011320c56198a833ed2697e3c1074e77d074356749cd3d
F test/window8.test cccb819319b72251b0228abf9dbe009831fe8818c699400bf8ef69b30314bad5
F test/window8.tcl f319644bfb17dd283f9359c3e46426064ed91677637adc5a00aaa2756e260eb5
F test/window8.test ade3404ddd26e75bfb40b9b3399d504213fd484e37a49b06657947ea2e0125a8
F test/windowerr.tcl 727d77959ac512b473dd2d659937f58688ce5460482a442c2d569fc8656491e5
F test/windowerr.test 7962cf9b39f27b11ea5c62105ab2322a61ceac098dce536e2b8569c3053f62e7
F test/windowfault.test cb27a4d8c85982733b123af667921df3a96e23d3739b15d414de75054b334cbe
@ -1813,7 +1813,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 c02f77b1b4d025d4243f883d6f3a2b3abcaf4944e0209f641b62c576415343dc
R 18e02000cd72a7d7f88e0273a7e185eb
P 4f9b93e6cfa0b3b6ab8a126299c2b2a242f840453dc450e84d3df87576cf6cf8
R b15ab65cb7618c5a9e1a72b6396029a6
U dan
Z 942f44c2db480ad33c8951876cbdc05e
Z c24808e31372a4301dc8e3448490f36d

View File

@ -1 +1 @@
4f9b93e6cfa0b3b6ab8a126299c2b2a242f840453dc450e84d3df87576cf6cf8
e195948a6876efe01b5cf2ed67bc9015a781fda39dca668099cb7edc1d331818

View File

@ -970,6 +970,63 @@ foreach {tn expr err} {
" $res
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 23.0 {
CREATE TABLE t5(a, b, c);
CREATE INDEX t5ab ON t5(a, b);
}
proc do_ordercount_test {tn sql nOrderBy} {
set plan [execsql "EXPLAIN QUERY PLAN $sql"]
uplevel [list do_test $tn [list regexp -all ORDER $plan] $nOrderBy]
}
do_ordercount_test 23.1 {
SELECT
sum(c) OVER (ORDER BY a, b),
sum(c) OVER (PARTITION BY a ORDER BY b)
FROM t5
} 0
do_ordercount_test 23.2 {
SELECT
sum(c) OVER (ORDER BY b, a),
sum(c) OVER (PARTITION BY b ORDER BY a)
FROM t5
} 1
do_ordercount_test 23.3 {
SELECT
sum(c) OVER (ORDER BY b, a),
sum(c) OVER (ORDER BY c, b)
FROM t5
} 2
do_ordercount_test 23.4 {
SELECT
sum(c) OVER (ORDER BY b ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),
sum(c) OVER (ORDER BY b RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),
sum(c) OVER (ORDER BY b GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
FROM t5
} 1
do_ordercount_test 23.5 {
SELECT
sum(c) OVER (ORDER BY b+1 ROWS UNBOUNDED PRECEDING),
sum(c) OVER (ORDER BY b+1 RANGE UNBOUNDED PRECEDING),
sum(c) OVER (ORDER BY b+1 GROUPS UNBOUNDED PRECEDING)
FROM t5
} 1
do_ordercount_test 23.6 {
SELECT
sum(c) OVER (ORDER BY b+1 ROWS UNBOUNDED PRECEDING),
sum(c) OVER (ORDER BY b+2 RANGE UNBOUNDED PRECEDING),
sum(c) OVER (ORDER BY b+3 GROUPS UNBOUNDED PRECEDING)
FROM t5
} 3
finish_test

View File

@ -165,6 +165,7 @@ foreach {tn frame} {
10 { ORDER BY a DESC RANGE BETWEEN 5.7 PRECEDING AND 5.8 FOLLOWING }
11 { ORDER BY a DESC RANGE BETWEEN UNBOUNDED PRECEDING AND 5.9 PRECEDING }
12 { ORDER BY a DESC RANGE BETWEEN 2.1 FOLLOWING AND UNBOUNDED FOLLOWING }
13 { ORDER BY a RANGE 5.1 PRECEDING }
} {
execsql_test 3.$tn "
SELECT CAST(a AS INTEGER), sum(b) OVER win FROM t1 WINDOW win AS ($frame)

View File

@ -3494,6 +3494,10 @@ do_execsql_test 3.12 {
SELECT CAST(a AS INTEGER), sum(b) OVER win FROM t1 WINDOW win AS ( ORDER BY a DESC RANGE BETWEEN 2.1 FOLLOWING AND UNBOUNDED FOLLOWING )
} {30 232 22 112 20 112 15 30 13 30 13 30 10 10 5 {}}
do_execsql_test 3.13 {
SELECT CAST(a AS INTEGER), sum(b) OVER win FROM t1 WINDOW win AS ( ORDER BY a RANGE 5.1 PRECEDING )
} {5 10 10 30 13 72 13 72 15 102 20 70 22 120 30 90}
#==========================================================================
do_execsql_test 4.0 {