Fix problems with window frames that use ORDER BY ... NULLS LAST etc.

FossilOrigin-Name: 75d665a494dd7d6e77d5a80af386ee5accc0a53416d5493424dc0fef6c7b01a0
This commit is contained in:
dan 2019-08-19 19:59:50 +00:00
parent 9105fd5189
commit ae8e45cb0c
9 changed files with 1600 additions and 139 deletions

View File

@ -1,5 +1,5 @@
C Prevent\sNULLS\sFIRST/LAST\sfrom\sbeing\sused\sin\sCREATE\sINDEX\sand\sother\sstatements.
D 2019-08-19T17:26:32.202
C Fix\sproblems\swith\swindow\sframes\sthat\suse\sORDER\sBY\s...\sNULLS\sLAST\setc.
D 2019-08-19T19:59:50.467
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -475,7 +475,7 @@ F src/date.c e1d8ac7102f3f283e63e13867acb0efa33861cf34f0faf4cdbaf9fa7a1eb7041
F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7
F src/dbstat.c c12833de69cb655751487d2c5a59607e36be1c58ba1f4bd536609909ad47b319
F src/delete.c d08c9e01a2664afd12edcfa3a9c6578517e8ff8735f35509582693adbe0edeaf
F src/expr.c 0a3442b0df31f1eca86b2aa3634f61bca5f1a6781f543ca9a0d87e29961f7f4f
F src/expr.c 223bd0d5132e217fc0967be55a0a31f5e06d4b61805176d487ffe4ce6b4c6a6e
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 6b79f4c2447691aa9ac86e2a6a774b65f3b3dd053d4220a4893051a0de20f82e
F src/func.c 4ee36219698d50d672a28eca4adb0fd6b92e607a1883d318315e0d2fd5044467
@ -613,7 +613,7 @@ F src/where.c 52c433208eafdc7e1750ea4622cfffb5d14d906a0a9258e07bae4b6fee182fef
F src/whereInt.h 807766a6a92893dbba8a887e5b13466d2257ce07a84cf1be0aae2c41aee3bf4f
F src/wherecode.c 81c5d1eb909f8e1284df58367d25f748d126c475725665e7bb9b10a9bf702242
F src/whereexpr.c 5cce1fd11876086890a27c05e0cb75ca97ba64ba6984f72154039f1cfd2e69cc
F src/window.c 331cdac4992c7402da01c981861f3cc989bf7b4a97dd03eb122993e670f7a588
F src/window.c 94dccce0568dbcc65658d762e5b11c390fd5509d40e73205cb7f0c22f0051532
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
F test/affinity3.test 6a101af2fc945ce2912f6fe54dd646018551710d
@ -1182,7 +1182,7 @@ F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161
F test/notify3.test 10ff25cde502e72a92053a2f215d64bece4ef934
F test/notnull.test a37b663d5bb728d66fc182016613fb8e4a0a4bbf3d75b8876a7527f7d4ed3f18
F test/null.test 0dcce4f04284ec66108c503327ad6d224c0752b3
F test/nulls1.test 6d226787ee0d479bc009e00b7fa812fb261fbb3eab764de18ecb988f4ec69f4a
F test/nulls1.test d2f1da489fd24d7af54aed9d7e117e4c7d6bb3e67f3a87ef54377cc088563073
F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1
F test/numindex1.test 20a5450d4b056e48cd5db30e659f13347a099823
F test/offset1.test f06b83657bcf26f9ce805e67450e189e282143b2
@ -1217,7 +1217,7 @@ F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b
F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442
F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff
F test/permutations.test 4282fb00e5ac0f8c2cd1be62652f6da4ac03ce3c58b7d785fa17f4684492a0e0
F test/pg_common.tcl 4740dc35190d6acdab14c097783331361301ab504a94d948f6afbb56ce0a51e8
F test/pg_common.tcl 222a1bad1c41c308fa366313cd7b51b3be7e9b21c8736a421b974ac941693b54
F test/pragma.test cf066fe0f7f5d49f4758de4986407b8676c61aaa7871599340d64f42a8edc352
F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f
F test/pragma3.test 8300aa9c63cff1027006ca34bf413a148abbd6dcd471fa9a1ded322fe18c0df9
@ -1710,9 +1710,9 @@ F test/window4.test 807f3e6b15f9338e5b9742b87c5c7ca825b42b9657fde6096e8901193708
F test/window5.test d328dd18221217c49c144181975eea17339eaeaf0e9aa558cee3afb84652821e
F test/window6.test f8d674254b23289cc17c84d79dec7eda7caa1dfb7836c43122cfdf3640d1df32
F test/window7.tcl 6a1210f05d40ec89c22960213a22cd3f98d4e2f2eb20646c83c8c30d4d76108f
F test/window7.test ce7f865241fdd1c5c4db869cd7bb2986c3be836bc2e73649a6846dd920f63e0f
F test/window8.tcl 9e9a82ae9eea90a4a83481d641a812b974980c38f9247f3b89a6e3c8bed45518
F test/window8.test df187dc19921f7be0ab709d531d681bd80ccaac96a913a89ecee8b272b91d43f
F test/window7.test 1d31276961ae7801edc72173edaf7593e3cbc79c06d1f1f09e20d8418af403cd
F test/window8.tcl 5884cc884f9605bf88c0d18a534894bf9342f72687bf1bc43ed0cab4c8af7973
F test/window8.test 48590f3737d17eec503d77769c13ead15d12e8819820b1dc68afe8a3c5bc3250
F test/window9.test 20a6b590be718b6bc98a5356d4396d6cdf19329c547da084fa225b92d68e1693
F test/windowerr.tcl f5acd6fbc210d7b5546c0e879d157888455cd4a17a1d3f28f07c1c8a387019e0
F test/windowerr.test a8b752402109c15aa1c5efe1b93ccb0ce1ef84fa964ae1cd6684dd0b3cc1819b
@ -1837,7 +1837,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 f892066425671a8a0ac923e3ad4744677f6434a66f97b91afa8141f11f179975
R 453ca41ba88968d27d033b2c6ac5c131
P bb9767a287097a615aeb4abdba689b10e1a1c36c016c8e55905b508075e62c86
R 0d189432ffc682f45a241a646815eff1
U dan
Z d9760a7ecfe79d11a5b817a651ccacbf
Z 3a5c6bb3c2c9a1118645ddff85026963

View File

@ -1 +1 @@
bb9767a287097a615aeb4abdba689b10e1a1c36c016c8e55905b508075e62c86
75d665a494dd7d6e77d5a80af386ee5accc0a53416d5493424dc0fef6c7b01a0

View File

@ -1401,6 +1401,7 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
pItem->sortFlags = pOldItem->sortFlags;
pItem->done = 0;
pItem->bNulls = pOldItem->bNulls;
pItem->bSpanIsTab = pOldItem->bSpanIsTab;
pItem->bSorterRef = pOldItem->bSorterRef;
pItem->u = pOldItem->u;

View File

@ -1876,12 +1876,13 @@ static void windowCodeRangeTest(
int reg2 = sqlite3GetTempReg(pParse);
int arith = OP_Add;
int addrGe;
ExprList *pOrderBy = p->pMWin->pOrderBy;
int regString = ++pParse->nMem;
assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
assert( p->pMWin->pOrderBy && p->pMWin->pOrderBy->nExpr==1 );
if( p->pMWin->pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
assert( pOrderBy && pOrderBy->nExpr==1 );
if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
switch( op ){
case OP_Ge: op = OP_Le; break;
case OP_Gt: op = OP_Lt; break;
@ -1901,6 +1902,22 @@ static void windowCodeRangeTest(
VdbeCoverage(v);
sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
sqlite3VdbeJumpHere(v, addrGe);
if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
int addr;
addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
switch( op ){
case OP_Ge: sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl); break;
case OP_Gt: sqlite3VdbeAddOp2(v, OP_NotNull, reg2, lbl); break;
case OP_Le: sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); break;
default: assert( op==OP_Lt ); /* no-op */
}
sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
sqlite3VdbeJumpHere(v, addr);
sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
if( op==OP_Gt || op==OP_Ge ){
sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
}
}
sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );

View File

@ -15,8 +15,6 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix nulls1
if 1 {
do_execsql_test 1.0 {
DROP TABLE IF EXISTS t3;
CREATE TABLE t3(a INTEGER);
@ -55,8 +53,6 @@ for {set a 0} {$a < 3} {incr a} {
}
}
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
@ -84,6 +80,7 @@ do_execsql_test 2.2 {
}
#-------------------------------------------------------------------------
#
reset_db
do_execsql_test 3.0 {
CREATE TABLE t1(a, b, c, d, UNIQUE (b));
@ -121,5 +118,4 @@ do_execsql_test 3.2 {
400 300
}
finish_test

View File

@ -70,8 +70,8 @@ proc execsql {sql} {
proc execsql_test {tn sql} {
set res [execsql $sql]
set sql [string map {string_agg group_concat} $sql]
set sql [string map [list {NULLS FIRST} {}] $sql]
set sql [string map [list {NULLS LAST} {}] $sql]
# set sql [string map [list {NULLS FIRST} {}] $sql]
# set sql [string map [list {NULLS LAST} {}] $sql]
puts $::fd "do_execsql_test $tn {"
puts $::fd " [string trim $sql]"
puts $::fd "} {$res}"

View File

@ -41,54 +41,146 @@ do_execsql_test 1.0 {
do_execsql_test 1.1 {
SELECT a, sum(b) FROM t3 GROUP BY a ORDER BY 1;
} {0 550 1 460 2 470 3 480 4 490 5 500 6 510 7 520 8 530 9 540}
} {0 550 1 460 2 470 3 480 4 490 5 500 6 510 7 520 8 530
9 540}
do_execsql_test 1.2 {
SELECT a, sum(b) OVER (
ORDER BY a GROUPS BETWEEN CURRENT ROW AND CURRENT ROW
) FROM t3 ORDER BY 1;
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540}
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550
0 550 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460
1 460 1 460 2 470 2 470 2 470 2 470 2 470 2 470 2 470
2 470 2 470 2 470 3 480 3 480 3 480 3 480 3 480 3 480
3 480 3 480 3 480 3 480 4 490 4 490 4 490 4 490 4 490
4 490 4 490 4 490 4 490 4 490 5 500 5 500 5 500 5 500
5 500 5 500 5 500 5 500 5 500 5 500 6 510 6 510 6 510
6 510 6 510 6 510 6 510 6 510 6 510 6 510 7 520 7 520
7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 8 530
8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530
9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540
9 540}
do_execsql_test 1.3 {
SELECT a, sum(b) OVER (
ORDER BY a GROUPS BETWEEN 0 PRECEDING AND 0 FOLLOWING
) FROM t3 ORDER BY 1;
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540}
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550
0 550 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460
1 460 1 460 2 470 2 470 2 470 2 470 2 470 2 470 2 470
2 470 2 470 2 470 3 480 3 480 3 480 3 480 3 480 3 480
3 480 3 480 3 480 3 480 4 490 4 490 4 490 4 490 4 490
4 490 4 490 4 490 4 490 4 490 5 500 5 500 5 500 5 500
5 500 5 500 5 500 5 500 5 500 5 500 6 510 6 510 6 510
6 510 6 510 6 510 6 510 6 510 6 510 6 510 7 520 7 520
7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 8 530
8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530
9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540
9 540}
do_execsql_test 1.4 {
SELECT a, sum(b) OVER (
ORDER BY a GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING
) FROM t3 ORDER BY 1;
} {0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590}
} {0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480
0 1480 0 1480 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960
1 1960 1 1960 1 1960 1 1960 2 2450 2 2450 2 2450 2 2450
2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 3 2400 3 2400
3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400
4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450
4 2450 4 2450 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500
5 2500 5 2500 5 2500 5 2500 6 2550 6 2550 6 2550 6 2550
6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 7 2600 7 2600
7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600
8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100
8 2100 8 2100 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590
9 1590 9 1590 9 1590 9 1590}
do_execsql_test 1.5 {
SELECT a, sum(b) OVER (
ORDER BY a RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING
) FROM t3 ORDER BY 1;
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 2 470 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 3 480 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 4 490 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 5 500 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 6 510 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540}
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550
0 550 1 460 1 460 1 460 1 460 1 460 1 460 1 460 1 460
1 460 1 460 2 470 2 470 2 470 2 470 2 470 2 470 2 470
2 470 2 470 2 470 3 480 3 480 3 480 3 480 3 480 3 480
3 480 3 480 3 480 3 480 4 490 4 490 4 490 4 490 4 490
4 490 4 490 4 490 4 490 4 490 5 500 5 500 5 500 5 500
5 500 5 500 5 500 5 500 5 500 5 500 6 510 6 510 6 510
6 510 6 510 6 510 6 510 6 510 6 510 6 510 7 520 7 520
7 520 7 520 7 520 7 520 7 520 7 520 7 520 7 520 8 530
8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530 8 530
9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540
9 540}
do_execsql_test 1.6 {
SELECT a, sum(b) OVER (
ORDER BY a RANGE BETWEEN 2 PRECEDING AND 2 FOLLOWING
) FROM t3 ORDER BY 1;
} {0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590}
} {0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480 0 1480
0 1480 0 1480 1 1960 1 1960 1 1960 1 1960 1 1960 1 1960
1 1960 1 1960 1 1960 1 1960 2 2450 2 2450 2 2450 2 2450
2 2450 2 2450 2 2450 2 2450 2 2450 2 2450 3 2400 3 2400
3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400 3 2400
4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450 4 2450
4 2450 4 2450 5 2500 5 2500 5 2500 5 2500 5 2500 5 2500
5 2500 5 2500 5 2500 5 2500 6 2550 6 2550 6 2550 6 2550
6 2550 6 2550 6 2550 6 2550 6 2550 6 2550 7 2600 7 2600
7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600 7 2600
8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100
8 2100 8 2100 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590
9 1590 9 1590 9 1590 9 1590}
do_execsql_test 1.7 {
SELECT a, sum(b) OVER (
ORDER BY a RANGE BETWEEN 2 PRECEDING AND 1 FOLLOWING
) FROM t3 ORDER BY 1;
} {0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 1 1480 1 1480 1 1480 1 1480 1 1480 1 1480 1 1480 1 1480 1 1480 1 1480 2 1960 2 1960 2 1960 2 1960 2 1960 2 1960 2 1960 2 1960 2 1960 2 1960 3 1900 3 1900 3 1900 3 1900 3 1900 3 1900 3 1900 3 1900 3 1900 3 1900 4 1940 4 1940 4 1940 4 1940 4 1940 4 1940 4 1940 4 1940 4 1940 4 1940 5 1980 5 1980 5 1980 5 1980 5 1980 5 1980 5 1980 5 1980 5 1980 5 1980 6 2020 6 2020 6 2020 6 2020 6 2020 6 2020 6 2020 6 2020 6 2020 6 2020 7 2060 7 2060 7 2060 7 2060 7 2060 7 2060 7 2060 7 2060 7 2060 7 2060 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590}
} {0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010
0 1010 0 1010 1 1480 1 1480 1 1480 1 1480 1 1480 1 1480
1 1480 1 1480 1 1480 1 1480 2 1960 2 1960 2 1960 2 1960
2 1960 2 1960 2 1960 2 1960 2 1960 2 1960 3 1900 3 1900
3 1900 3 1900 3 1900 3 1900 3 1900 3 1900 3 1900 3 1900
4 1940 4 1940 4 1940 4 1940 4 1940 4 1940 4 1940 4 1940
4 1940 4 1940 5 1980 5 1980 5 1980 5 1980 5 1980 5 1980
5 1980 5 1980 5 1980 5 1980 6 2020 6 2020 6 2020 6 2020
6 2020 6 2020 6 2020 6 2020 6 2020 6 2020 7 2060 7 2060
7 2060 7 2060 7 2060 7 2060 7 2060 7 2060 7 2060 7 2060
8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100 8 2100
8 2100 8 2100 9 1590 9 1590 9 1590 9 1590 9 1590 9 1590
9 1590 9 1590 9 1590 9 1590}
do_execsql_test 1.8.1 {
SELECT a, sum(b) OVER (
ORDER BY a RANGE BETWEEN 0 PRECEDING AND 1 FOLLOWING
) FROM t3 ORDER BY 1;
} {0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 1 930 1 930 1 930 1 930 1 930 1 930 1 930 1 930 1 930 1 930 2 950 2 950 2 950 2 950 2 950 2 950 2 950 2 950 2 950 2 950 3 970 3 970 3 970 3 970 3 970 3 970 3 970 3 970 3 970 3 970 4 990 4 990 4 990 4 990 4 990 4 990 4 990 4 990 4 990 4 990 5 1010 5 1010 5 1010 5 1010 5 1010 5 1010 5 1010 5 1010 5 1010 5 1010 6 1030 6 1030 6 1030 6 1030 6 1030 6 1030 6 1030 6 1030 6 1030 6 1030 7 1050 7 1050 7 1050 7 1050 7 1050 7 1050 7 1050 7 1050 7 1050 7 1050 8 1070 8 1070 8 1070 8 1070 8 1070 8 1070 8 1070 8 1070 8 1070 8 1070 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540 9 540}
} {0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010 0 1010
0 1010 0 1010 1 930 1 930 1 930 1 930 1 930 1 930 1 930
1 930 1 930 1 930 2 950 2 950 2 950 2 950 2 950 2 950
2 950 2 950 2 950 2 950 3 970 3 970 3 970 3 970 3 970
3 970 3 970 3 970 3 970 3 970 4 990 4 990 4 990 4 990
4 990 4 990 4 990 4 990 4 990 4 990 5 1010 5 1010 5 1010
5 1010 5 1010 5 1010 5 1010 5 1010 5 1010 5 1010 6 1030
6 1030 6 1030 6 1030 6 1030 6 1030 6 1030 6 1030 6 1030
6 1030 7 1050 7 1050 7 1050 7 1050 7 1050 7 1050 7 1050
7 1050 7 1050 7 1050 8 1070 8 1070 8 1070 8 1070 8 1070
8 1070 8 1070 8 1070 8 1070 8 1070 9 540 9 540 9 540 9 540
9 540 9 540 9 540 9 540 9 540 9 540}
do_execsql_test 1.8.2 {
SELECT a, sum(b) OVER (
ORDER BY a DESC RANGE BETWEEN 0 PRECEDING AND 1 FOLLOWING
) FROM t3 ORDER BY 1;
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 1 1010 1 1010 1 1010 1 1010 1 1010 1 1010 1 1010 1 1010 1 1010 1 1010 2 930 2 930 2 930 2 930 2 930 2 930 2 930 2 930 2 930 2 930 3 950 3 950 3 950 3 950 3 950 3 950 3 950 3 950 3 950 3 950 4 970 4 970 4 970 4 970 4 970 4 970 4 970 4 970 4 970 4 970 5 990 5 990 5 990 5 990 5 990 5 990 5 990 5 990 5 990 5 990 6 1010 6 1010 6 1010 6 1010 6 1010 6 1010 6 1010 6 1010 6 1010 6 1010 7 1030 7 1030 7 1030 7 1030 7 1030 7 1030 7 1030 7 1030 7 1030 7 1030 8 1050 8 1050 8 1050 8 1050 8 1050 8 1050 8 1050 8 1050 8 1050 8 1050 9 1070 9 1070 9 1070 9 1070 9 1070 9 1070 9 1070 9 1070 9 1070 9 1070}
} {0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550 0 550
0 550 1 1010 1 1010 1 1010 1 1010 1 1010 1 1010 1 1010
1 1010 1 1010 1 1010 2 930 2 930 2 930 2 930 2 930 2 930
2 930 2 930 2 930 2 930 3 950 3 950 3 950 3 950 3 950
3 950 3 950 3 950 3 950 3 950 4 970 4 970 4 970 4 970
4 970 4 970 4 970 4 970 4 970 4 970 5 990 5 990 5 990
5 990 5 990 5 990 5 990 5 990 5 990 5 990 6 1010 6 1010
6 1010 6 1010 6 1010 6 1010 6 1010 6 1010 6 1010 6 1010
7 1030 7 1030 7 1030 7 1030 7 1030 7 1030 7 1030 7 1030
7 1030 7 1030 8 1050 8 1050 8 1050 8 1050 8 1050 8 1050
8 1050 8 1050 8 1050 8 1050 9 1070 9 1070 9 1070 9 1070
9 1070 9 1070 9 1070 9 1070 9 1070 9 1070}
finish_test

View File

@ -197,30 +197,55 @@ execsql_test 4.2.1 {
ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
) FROM t1 ORDER BY 1 NULLS FIRST;
}
execsql_test 4.2.2 {
SELECT sum(b) OVER (
ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
) FROM t1 ORDER BY 1 NULLS LAST;
}
execsql_test 4.2.3 {
SELECT sum(b) OVER (
ORDER BY a DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
) FROM t1 ORDER BY 1 NULLS FIRST;
}
execsql_test 4.2.4 {
SELECT sum(b) OVER (
ORDER BY a DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
) FROM t1 ORDER BY 1 NULLS LAST;
}
execsql_test 4.3.1 {
SELECT sum(b) OVER (
ORDER BY a NULLS FIRST RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
) FROM t1 ORDER BY 1 NULLS FIRST;
}
execsql_test 4.3.2 {
SELECT sum(b) OVER (
ORDER BY a NULLS LAST RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
) FROM t1 ORDER BY 1 NULLS LAST;
}
execsql_test 4.4.1 {
SELECT sum(b) OVER (
ORDER BY a NULLS FIRST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM t1 ORDER BY 1 NULLS FIRST;
}
execsql_test 4.4.2 {
SELECT sum(b) OVER (
ORDER BY a NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM t1 ORDER BY 1 NULLS LAST;
}
execsql_test 4.4.3 {
SELECT sum(b) OVER (
ORDER BY a DESC NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM t1 ORDER BY 1 NULLS FIRST;
}
execsql_test 4.4.4 {
SELECT sum(b) OVER (
ORDER BY a DESC NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM t1 ORDER BY 1 NULLS LAST;
}
==========
@ -248,6 +273,17 @@ foreach {tn ex} {
6 { ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING }
7 { ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING }
8 { RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
9 { ORDER BY a NULLS LAST
RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
10 { PARTITION BY coalesce(a, '')
RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
11 { ORDER BY a NULLS LAST GROUPS 6 PRECEDING }
12 { ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING }
13 { ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING }
14 { ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING }
} {
execsql_test 5.$tn.$tn2.1 "
SELECT max(c) OVER win,
@ -294,6 +330,7 @@ execsql_test 6.2 {
}
finish_test

File diff suppressed because it is too large Load Diff