SQLite

Check-in [94085fb3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add support for "ORDER BY ... NULLS FIRST" and "ORDER BY ... NULLS LAST". Use this to fix ticket [f8a7060e].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 94085fb3e756bc984237b74b6e29c68462ad860870c64dcb5124feaeec387660
User & Date: dan 2019-08-27 19:59:21
References
2019-08-27
20:00 Closed ticket [f8a7060e]: Incorrect result for query that uses MIN() and a CAST on rowid plus 4 other changes (artifact: 400f3bdf user: dan)
Context
2019-08-29
00:27
Improve Lemon so that it enlarges some of its tables slightly in order to avoid having to index range checks on table lookups for a performance increase. (check-in: 4be6a23a user: drh tags: trunk)
2019-08-28
02:09
Increase the size of the yy_lookahead table so that it is never necessary to down bounds checking on the index. (check-in: bafd8723 user: drh tags: lemon-optimization)
2019-08-27
19:59
Add support for "ORDER BY ... NULLS FIRST" and "ORDER BY ... NULLS LAST". Use this to fix ticket [f8a7060e]. (check-in: 94085fb3 user: dan tags: trunk)
17:59
The ALWAYS() added by the previous check-in was incorrect. Take it back out. (check-in: 336235db user: drh tags: trunk)
2019-08-26
20:41
Merge in recent fixes from trunk. (Closed-Leaf check-in: ad816d01 user: drh tags: nulls-last)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/expert/expert1.test.

130
131
132
133
134
135
136

137
138
139
140
141
142
143

144
145
146
147
148
149
150
} {
  SELECT a FROM t1 WHERE a=? ORDER BY b;
} {
  CREATE INDEX t1_idx_000123a7 ON t1(a, b);
  SEARCH TABLE t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
}


do_setup_rec_test $tn.6 {
  CREATE TABLE t1(a, b, c);
} {
  SELECT min(a) FROM t1
} {
  CREATE INDEX t1_idx_00000061 ON t1(a);
  SEARCH TABLE t1 USING COVERING INDEX t1_idx_00000061

}

do_setup_rec_test $tn.7 {
  CREATE TABLE t1(a, b, c);
} {
  SELECT * FROM t1 ORDER BY a, b, c;
} {







>







>







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
} {
  SELECT a FROM t1 WHERE a=? ORDER BY b;
} {
  CREATE INDEX t1_idx_000123a7 ON t1(a, b);
  SEARCH TABLE t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
}

if 0 {
do_setup_rec_test $tn.6 {
  CREATE TABLE t1(a, b, c);
} {
  SELECT min(a) FROM t1
} {
  CREATE INDEX t1_idx_00000061 ON t1(a);
  SEARCH TABLE t1 USING COVERING INDEX t1_idx_00000061
}
}

do_setup_rec_test $tn.7 {
  CREATE TABLE t1(a, b, c);
} {
  SELECT * FROM t1 ORDER BY a, b, c;
} {

Changes to src/build.c.

1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
      Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
      sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
    }
    pTab->iPKey = iCol;
    pTab->keyConf = (u8)onError;
    assert( autoInc==0 || autoInc==1 );
    pTab->tabFlags |= autoInc*TF_Autoincrement;
    if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
  }else if( autoInc ){
#ifndef SQLITE_OMIT_AUTOINCREMENT
    sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
       "INTEGER PRIMARY KEY");
#endif
  }else{
    sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,







|







1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
      Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
      sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
    }
    pTab->iPKey = iCol;
    pTab->keyConf = (u8)onError;
    assert( autoInc==0 || autoInc==1 );
    pTab->tabFlags |= autoInc*TF_Autoincrement;
    if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
  }else if( autoInc ){
#ifndef SQLITE_OMIT_AUTOINCREMENT
    sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
       "INTEGER PRIMARY KEY");
#endif
  }else{
    sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
    sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
    pList = sqlite3ExprListAppend(pParse, 0, 
                  sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
    if( pList==0 ) return;
    if( IN_RENAME_OBJECT ){
      sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
    }
    pList->a[0].sortOrder = pParse->iPkSortOrder;
    assert( pParse->pNewTable==pTab );
    pTab->iPKey = -1;
    sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
                       SQLITE_IDXTYPE_PRIMARYKEY);
    if( db->mallocFailed || pParse->nErr ) return;
    pPk = sqlite3PrimaryKeyIndex(pTab);
    assert( pPk->nKeyCol==1 );







|







1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
    sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
    pList = sqlite3ExprListAppend(pParse, 0, 
                  sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
    if( pList==0 ) return;
    if( IN_RENAME_OBJECT ){
      sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
    }
    pList->a[0].sortFlags = pParse->iPkSortOrder;
    assert( pParse->pNewTable==pTab );
    pTab->iPKey = -1;
    sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
                       SQLITE_IDXTYPE_PRIMARYKEY);
    if( db->mallocFailed || pParse->nErr ) return;
    pPk = sqlite3PrimaryKeyIndex(pTab);
    assert( pPk->nKeyCol==1 );
3148
3149
3150
3151
3152
3153
3154





















3155
3156
3157
3158
3159
3160
3161
    p->aSortOrder = (u8*)pExtra;
    p->nColumn = nCol;
    p->nKeyCol = nCol - 1;
    *ppExtra = ((char*)p) + nByte;
  }
  return p;
}






















/*
** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
** and pTblList is the name of the table that is to be indexed.  Both will 
** be NULL for a primary key or an index that is created to satisfy a
** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
** as the table to be indexed.  pParse->pNewTable is a table that is







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
    p->aSortOrder = (u8*)pExtra;
    p->nColumn = nCol;
    p->nKeyCol = nCol - 1;
    *ppExtra = ((char*)p) + nByte;
  }
  return p;
}

/*
** If expression list pList contains an expression that was parsed with
** an explicit "NULLS FIRST" or "NULLS LAST" clause, leave an error in
** pParse and return non-zero. Otherwise, return zero.
*/
int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
  if( pList ){
    int i;
    for(i=0; i<pList->nExpr; i++){
      if( pList->a[i].bNulls ){
        u8 sf = pList->a[i].sortFlags;
        sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s", 
            (sf==0 || sf==3) ? "FIRST" : "LAST"
        );
        return 1;
      }
    }
  }
  return 0;
}

/*
** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
** and pTblList is the name of the table that is to be indexed.  Both will 
** be NULL for a primary key or an index that is created to satisfy a
** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
** as the table to be indexed.  pParse->pNewTable is a table that is
3199
3200
3201
3202
3203
3204
3205



3206
3207
3208
3209
3210
3211
3212
    goto exit_create_index;
  }
  if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
    goto exit_create_index;
  }
  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
    goto exit_create_index;



  }

  /*
  ** Find the table that is to be indexed.  Return early if not found.
  */
  if( pTblName!=0 ){








>
>
>







3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
    goto exit_create_index;
  }
  if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
    goto exit_create_index;
  }
  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
    goto exit_create_index;
  }
  if( sqlite3HasExplicitNulls(pParse, pList) ){
    goto exit_create_index;
  }

  /*
  ** Find the table that is to be indexed.  Return early if not found.
  */
  if( pTblName!=0 ){

3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
    Column *pCol = &pTab->aCol[pTab->nCol-1];
    pCol->colFlags |= COLFLAG_UNIQUE;
    sqlite3TokenInit(&prevCol, pCol->zName);
    pList = sqlite3ExprListAppend(pParse, 0,
              sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
    if( pList==0 ) goto exit_create_index;
    assert( pList->nExpr==1 );
    sqlite3ExprListSetSortOrder(pList, sortOrder);
  }else{
    sqlite3ExprListCheckLength(pParse, pList, "index");
    if( pParse->nErr ) goto exit_create_index;
  }

  /* Figure out how many bytes of space are required to store explicitly
  ** specified collation sequence names.







|







3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
    Column *pCol = &pTab->aCol[pTab->nCol-1];
    pCol->colFlags |= COLFLAG_UNIQUE;
    sqlite3TokenInit(&prevCol, pCol->zName);
    pList = sqlite3ExprListAppend(pParse, 0,
              sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
    if( pList==0 ) goto exit_create_index;
    assert( pList->nExpr==1 );
    sqlite3ExprListSetSortOrder(pList, sortOrder, SQLITE_SO_UNDEFINED);
  }else{
    sqlite3ExprListCheckLength(pParse, pList, "index");
    if( pParse->nErr ) goto exit_create_index;
  }

  /* Figure out how many bytes of space are required to store explicitly
  ** specified collation sequence names.
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
      zColl = pTab->aCol[j].zColl;
    }
    if( !zColl ) zColl = sqlite3StrBINARY;
    if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
      goto exit_create_index;
    }
    pIndex->azColl[i] = zColl;
    requestedSortOrder = pListItem->sortOrder & sortOrderMask;
    pIndex->aSortOrder[i] = (u8)requestedSortOrder;
  }

  /* Append the table key to the end of the index.  For WITHOUT ROWID
  ** tables (when pPk!=0) this will be the declared PRIMARY KEY.  For
  ** normal tables (when pPk==0) this will be the rowid.
  */







|







3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
      zColl = pTab->aCol[j].zColl;
    }
    if( !zColl ) zColl = sqlite3StrBINARY;
    if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
      goto exit_create_index;
    }
    pIndex->azColl[i] = zColl;
    requestedSortOrder = pListItem->sortFlags & sortOrderMask;
    pIndex->aSortOrder[i] = (u8)requestedSortOrder;
  }

  /* Append the table key to the end of the index.  For WITHOUT ROWID
  ** tables (when pPk!=0) this will be the declared PRIMARY KEY.  For
  ** normal tables (when pPk==0) this will be the rowid.
  */
4700
4701
4702
4703
4704
4705
4706
4707

4708
4709
4710
4711
4712
4713
4714
  }
  if( pKey ){
    assert( sqlite3KeyInfoIsWriteable(pKey) );
    for(i=0; i<nCol; i++){
      const char *zColl = pIdx->azColl[i];
      pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
                        sqlite3LocateCollSeq(pParse, zColl);
      pKey->aSortOrder[i] = pIdx->aSortOrder[i];

    }
    if( pParse->nErr ){
      assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ );
      if( pIdx->bNoQuery==0 ){
        /* Deactivate the index because it contains an unknown collating
        ** sequence.  The only way to reactive the index is to reload the
        ** schema.  Adding the missing collating sequence later does not







|
>







4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
  }
  if( pKey ){
    assert( sqlite3KeyInfoIsWriteable(pKey) );
    for(i=0; i<nCol; i++){
      const char *zColl = pIdx->azColl[i];
      pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
                        sqlite3LocateCollSeq(pParse, zColl);
      pKey->aSortFlags[i] = pIdx->aSortOrder[i];
      assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
    }
    if( pParse->nErr ){
      assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ );
      if( pIdx->bNoQuery==0 ){
        /* Deactivate the index because it contains an unknown collating
        ** sequence.  The only way to reactive the index is to reload the
        ** schema.  Adding the missing collating sequence later does not

Changes to src/expr.c.

1405
1406
1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
        assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
        assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
        pNewExpr->pLeft = pPriorSelectCol;
      }
    }
    pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
    pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
    pItem->sortOrder = pOldItem->sortOrder;
    pItem->done = 0;

    pItem->bSpanIsTab = pOldItem->bSpanIsTab;
    pItem->bSorterRef = pOldItem->bSorterRef;
    pItem->u = pOldItem->u;
  }
  return pNew;
}








|

>







1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
        assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
        assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
        pNewExpr->pLeft = pPriorSelectCol;
      }
    }
    pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
    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;
  }
  return pNew;
}

1662
1663
1664
1665
1666
1667
1668
1669

1670


1671
1672
1673
1674





1675




1676
1677







1678
1679
1680
1681
1682
1683
1684
  sqlite3IdListDelete(db, pColumns);
  return pList;
}

/*
** Set the sort order for the last element on the given ExprList.
*/
void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder){

  if( p==0 ) return;


  assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC>=0 && SQLITE_SO_DESC>0 );
  assert( p->nExpr>0 );
  if( iSortOrder<0 ){
    assert( p->a[p->nExpr-1].sortOrder==SQLITE_SO_ASC );





    return;




  }
  p->a[p->nExpr-1].sortOrder = (u8)iSortOrder;







}

/*
** Set the ExprList.a[].zName element of the most recently added item
** on the expression list.
**
** pList might be NULL following an OOM error.  But pName should never be







|
>

>
>
|
|
|
|
>
>
>
>
>
|
>
>
>
>

|
>
>
>
>
>
>
>







1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
  sqlite3IdListDelete(db, pColumns);
  return pList;
}

/*
** Set the sort order for the last element on the given ExprList.
*/
void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder, int eNulls){
  struct ExprList_item *pItem;
  if( p==0 ) return;
  assert( p->nExpr>0 );

  assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC==0 && SQLITE_SO_DESC>0 );
  assert( iSortOrder==SQLITE_SO_UNDEFINED 
       || iSortOrder==SQLITE_SO_ASC 
       || iSortOrder==SQLITE_SO_DESC 
  );
  assert( eNulls==SQLITE_SO_UNDEFINED 
       || eNulls==SQLITE_SO_ASC 
       || eNulls==SQLITE_SO_DESC 
  );

  pItem = &p->a[p->nExpr-1];
  assert( pItem->bNulls==0 );
  if( iSortOrder==SQLITE_SO_UNDEFINED ){
    iSortOrder = SQLITE_SO_ASC;
  }
  pItem->sortFlags = (u8)iSortOrder;

  if( eNulls!=SQLITE_SO_UNDEFINED ){
    pItem->bNulls = 1;
    if( iSortOrder!=eNulls ){
      pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
    }
  }
}

/*
** Set the ExprList.a[].zName element of the most recently added item
** on the expression list.
**
** pList might be NULL following an OOM error.  But pName should never be
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
  int i;
  if( pA==0 && pB==0 ) return 0;
  if( pA==0 || pB==0 ) return 1;
  if( pA->nExpr!=pB->nExpr ) return 1;
  for(i=0; i<pA->nExpr; i++){
    Expr *pExprA = pA->a[i].pExpr;
    Expr *pExprB = pB->a[i].pExpr;
    if( pA->a[i].sortOrder!=pB->a[i].sortOrder ) return 1;
    if( sqlite3ExprCompare(0, pExprA, pExprB, iTab) ) return 1;
  }
  return 0;
}

/*
** Like sqlite3ExprCompare() except COLLATE operators at the top-level







|







4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
  int i;
  if( pA==0 && pB==0 ) return 0;
  if( pA==0 || pB==0 ) return 1;
  if( pA->nExpr!=pB->nExpr ) return 1;
  for(i=0; i<pA->nExpr; i++){
    Expr *pExprA = pA->a[i].pExpr;
    Expr *pExprB = pB->a[i].pExpr;
    if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
    if( sqlite3ExprCompare(0, pExprA, pExprB, iTab) ) return 1;
  }
  return 0;
}

/*
** Like sqlite3ExprCompare() except COLLATE operators at the top-level

Changes to src/insert.c.

828
829
830
831
832
833
834



835
836
837
838
839
840
841
  }
#ifndef SQLITE_OMIT_UPSERT
  if( pUpsert ){
    if( IsVirtual(pTab) ){
      sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
              pTab->zName);
      goto insert_cleanup;



    }
    pTabList->a[0].iCursor = iDataCur;
    pUpsert->pUpsertSrc = pTabList;
    pUpsert->regData = regData;
    pUpsert->iDataCur = iDataCur;
    pUpsert->iIdxCur = iIdxCur;
    if( pUpsert->pUpsertTarget ){







>
>
>







828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
  }
#ifndef SQLITE_OMIT_UPSERT
  if( pUpsert ){
    if( IsVirtual(pTab) ){
      sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
              pTab->zName);
      goto insert_cleanup;
    }
    if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
      goto insert_cleanup;
    }
    pTabList->a[0].iCursor = iDataCur;
    pUpsert->pUpsertSrc = pTabList;
    pUpsert->regData = regData;
    pUpsert->iDataCur = iDataCur;
    pUpsert->iIdxCur = iIdxCur;
    if( pUpsert->pUpsertTarget ){

Changes to src/parse.y.

207
208
209
210
211
212
213

214
215
216
217
218
219
220
%fallback ID
  ABORT ACTION AFTER ANALYZE ASC ATTACH BEFORE BEGIN BY CASCADE CAST COLUMNKW
  CONFLICT DATABASE DEFERRED DESC DETACH DO
  EACH END EXCLUSIVE EXPLAIN FAIL FOR
  IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH NO PLAN
  QUERY KEY OF OFFSET PRAGMA RAISE RECURSIVE RELEASE REPLACE RESTRICT ROW ROWS
  ROLLBACK SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL WITH WITHOUT

%ifdef SQLITE_OMIT_COMPOUND_SELECT
  EXCEPT INTERSECT UNION
%endif SQLITE_OMIT_COMPOUND_SELECT
%ifndef SQLITE_OMIT_WINDOWFUNC
  CURRENT FOLLOWING PARTITION PRECEDING RANGE UNBOUNDED
  EXCLUDE GROUPS OTHERS TIES
%endif SQLITE_OMIT_WINDOWFUNC







>







207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
%fallback ID
  ABORT ACTION AFTER ANALYZE ASC ATTACH BEFORE BEGIN BY CASCADE CAST COLUMNKW
  CONFLICT DATABASE DEFERRED DESC DETACH DO
  EACH END EXCLUSIVE EXPLAIN FAIL FOR
  IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH NO PLAN
  QUERY KEY OF OFFSET PRAGMA RAISE RECURSIVE RELEASE REPLACE RESTRICT ROW ROWS
  ROLLBACK SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL WITH WITHOUT
  NULLS FIRST LAST
%ifdef SQLITE_OMIT_COMPOUND_SELECT
  EXCEPT INTERSECT UNION
%endif SQLITE_OMIT_COMPOUND_SELECT
%ifndef SQLITE_OMIT_WINDOWFUNC
  CURRENT FOLLOWING PARTITION PRECEDING RANGE UNBOUNDED
  EXCLUDE GROUPS OTHERS TIES
%endif SQLITE_OMIT_WINDOWFUNC
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798





799
800
801
802
803
804
805
// sort order.
//
%type sortlist {ExprList*}
%destructor sortlist {sqlite3ExprListDelete(pParse->db, $$);}

orderby_opt(A) ::= .                          {A = 0;}
orderby_opt(A) ::= ORDER BY sortlist(X).      {A = X;}
sortlist(A) ::= sortlist(A) COMMA expr(Y) sortorder(Z). {
  A = sqlite3ExprListAppend(pParse,A,Y);
  sqlite3ExprListSetSortOrder(A,Z);
}
sortlist(A) ::= expr(Y) sortorder(Z). {
  A = sqlite3ExprListAppend(pParse,0,Y); /*A-overwrites-Y*/
  sqlite3ExprListSetSortOrder(A,Z);
}

%type sortorder {int}

sortorder(A) ::= ASC.           {A = SQLITE_SO_ASC;}
sortorder(A) ::= DESC.          {A = SQLITE_SO_DESC;}
sortorder(A) ::= .              {A = SQLITE_SO_UNDEFINED;}






%type groupby_opt {ExprList*}
%destructor groupby_opt {sqlite3ExprListDelete(pParse->db, $$);}
groupby_opt(A) ::= .                      {A = 0;}
groupby_opt(A) ::= GROUP BY nexprlist(X). {A = X;}

%type having_opt {Expr*}
%destructor having_opt {sqlite3ExprDelete(pParse->db, $$);}







|

|

|

|








>
>
>
>
>







778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
// sort order.
//
%type sortlist {ExprList*}
%destructor sortlist {sqlite3ExprListDelete(pParse->db, $$);}

orderby_opt(A) ::= .                          {A = 0;}
orderby_opt(A) ::= ORDER BY sortlist(X).      {A = X;}
sortlist(A) ::= sortlist(A) COMMA expr(Y) sortorder(Z) nulls(X). {
  A = sqlite3ExprListAppend(pParse,A,Y);
  sqlite3ExprListSetSortOrder(A,Z,X);
}
sortlist(A) ::= expr(Y) sortorder(Z) nulls(X). {
  A = sqlite3ExprListAppend(pParse,0,Y); /*A-overwrites-Y*/
  sqlite3ExprListSetSortOrder(A,Z,X);
}

%type sortorder {int}

sortorder(A) ::= ASC.           {A = SQLITE_SO_ASC;}
sortorder(A) ::= DESC.          {A = SQLITE_SO_DESC;}
sortorder(A) ::= .              {A = SQLITE_SO_UNDEFINED;}

%type nulls {int}
nulls(A) ::= NULLS FIRST.       {A = SQLITE_SO_ASC;}
nulls(A) ::= NULLS LAST.        {A = SQLITE_SO_DESC;}
nulls(A) ::= .                  {A = SQLITE_SO_UNDEFINED;}

%type groupby_opt {ExprList*}
%destructor groupby_opt {sqlite3ExprListDelete(pParse->db, $$);}
groupby_opt(A) ::= .                      {A = 0;}
groupby_opt(A) ::= GROUP BY nexprlist(X). {A = X;}

%type having_opt {Expr*}
%destructor having_opt {sqlite3ExprDelete(pParse->db, $$);}
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748



1749
1750
1751
1752
1753
1754
1755
%endif /* SQLITE_OMIT_WINDOWFUNC */

/*
** The code generator needs some extra TK_ token values for tokens that
** are synthesized and do not actually appear in the grammar:
*/
%token
  TRUEFALSE       /* True or false keyword */
  ISNOT           /* Combination of IS and NOT */
  FUNCTION        /* A function invocation */
  COLUMN          /* Reference to a table column */
  AGG_FUNCTION    /* An aggregate function */
  AGG_COLUMN      /* An aggregated column */



  UMINUS          /* Unary minus */
  UPLUS           /* Unary plus */
  TRUTH           /* IS TRUE or IS FALSE or IS NOT TRUE or IS NOT FALSE */
  REGISTER        /* Reference to a VDBE register */
  VECTOR          /* Vector */
  SELECT_COLUMN   /* Choose a single column from a multi-column SELECT */
  IF_NULL_ROW     /* the if-null-row operator */







<
<
<



>
>
>







1742
1743
1744
1745
1746
1747
1748



1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
%endif /* SQLITE_OMIT_WINDOWFUNC */

/*
** The code generator needs some extra TK_ token values for tokens that
** are synthesized and do not actually appear in the grammar:
*/
%token



  COLUMN          /* Reference to a table column */
  AGG_FUNCTION    /* An aggregate function */
  AGG_COLUMN      /* An aggregated column */
  TRUEFALSE       /* True or false keyword */
  ISNOT           /* Combination of IS and NOT */
  FUNCTION        /* A function invocation */
  UMINUS          /* Unary minus */
  UPLUS           /* Unary plus */
  TRUTH           /* IS TRUE or IS FALSE or IS NOT TRUE or IS NOT FALSE */
  REGISTER        /* Reference to a VDBE register */
  VECTOR          /* Vector */
  SELECT_COLUMN   /* Choose a single column from a multi-column SELECT */
  IF_NULL_ROW     /* the if-null-row operator */

Changes to src/select.c.

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
    }
    VdbeCoverage(v);
    sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
    pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
    if( pParse->db->mallocFailed ) return;
    pOp->p2 = nKey + nData;
    pKI = pOp->p4.pKeyInfo;
    memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */
    sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
    testcase( pKI->nAllField > pKI->nKeyField+2 );
    pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
                                           pKI->nAllField-pKI->nKeyField-1);
    addrJmp = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
    pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);







|







660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
    }
    VdbeCoverage(v);
    sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
    pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
    if( pParse->db->mallocFailed ) return;
    pOp->p2 = nKey + nData;
    pKI = pOp->p4.pKeyInfo;
    memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
    sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
    testcase( pKI->nAllField > pKI->nKeyField+2 );
    pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
                                           pKI->nAllField-pKI->nKeyField-1);
    addrJmp = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
    pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
** Allocate a KeyInfo object sufficient for an index of N key columns and
** X extra columns.
*/
KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
  int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);
  KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);
  if( p ){
    p->aSortOrder = (u8*)&p->aColl[N+X];
    p->nKeyField = (u16)N;
    p->nAllField = (u16)(N+X);
    p->enc = ENC(db);
    p->db = db;
    p->nRef = 1;
    memset(&p[1], 0, nExtra);
  }else{







|







1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
** Allocate a KeyInfo object sufficient for an index of N key columns and
** X extra columns.
*/
KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
  int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);
  KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);
  if( p ){
    p->aSortFlags = (u8*)&p->aColl[N+X];
    p->nKeyField = (u16)N;
    p->nAllField = (u16)(N+X);
    p->enc = ENC(db);
    p->db = db;
    p->nRef = 1;
    memset(&p[1], 0, nExtra);
  }else{
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362

  nExpr = pList->nExpr;
  pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
  if( pInfo ){
    assert( sqlite3KeyInfoIsWriteable(pInfo) );
    for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
      pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
      pInfo->aSortOrder[i-iStart] = pItem->sortOrder;
    }
  }
  return pInfo;
}

/*
** Name of the connection operator, used for error messages.







|







1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362

  nExpr = pList->nExpr;
  pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
  if( pInfo ){
    assert( sqlite3KeyInfoIsWriteable(pInfo) );
    for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
      pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
      pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
    }
  }
  return pInfo;
}

/*
** Name of the connection operator, used for error messages.
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
        pColl = multiSelectCollSeq(pParse, p, pItem->u.x.iOrderByCol-1);
        if( pColl==0 ) pColl = db->pDfltColl;
        pOrderBy->a[i].pExpr =
          sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
      }
      assert( sqlite3KeyInfoIsWriteable(pRet) );
      pRet->aColl[i] = pColl;
      pRet->aSortOrder[i] = pOrderBy->a[i].sortOrder;
    }
  }

  return pRet;
}

#ifndef SQLITE_OMIT_CTE







|







2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
        pColl = multiSelectCollSeq(pParse, p, pItem->u.x.iOrderByCol-1);
        if( pColl==0 ) pColl = db->pDfltColl;
        pOrderBy->a[i].pExpr =
          sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
      }
      assert( sqlite3KeyInfoIsWriteable(pRet) );
      pRet->aColl[i] = pColl;
      pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
    }
  }

  return pRet;
}

#ifndef SQLITE_OMIT_CTE
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
    pParse->nMem += nExpr+1;
    sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
    pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
    if( pKeyDup ){
      assert( sqlite3KeyInfoIsWriteable(pKeyDup) );
      for(i=0; i<nExpr; i++){
        pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
        pKeyDup->aSortOrder[i] = 0;
      }
    }
  }
 
  /* Separate the left and the right query from one another
  */
  p->pPrior = 0;







|







3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
    pParse->nMem += nExpr+1;
    sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
    pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
    if( pKeyDup ){
      assert( sqlite3KeyInfoIsWriteable(pKeyDup) );
      for(i=0; i<nExpr; i++){
        pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
        pKeyDup->aSortFlags[i] = 0;
      }
    }
  }
 
  /* Separate the left and the right query from one another
  */
  p->pPrior = 0;
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
** analysis.
*/
static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
  int eRet = WHERE_ORDERBY_NORMAL;      /* Return value */
  ExprList *pEList = pFunc->x.pList;    /* Arguments to agg function */
  const char *zFunc;                    /* Name of aggregate function pFunc */
  ExprList *pOrderBy;
  u8 sortOrder;

  assert( *ppMinMax==0 );
  assert( pFunc->op==TK_AGG_FUNCTION );
  assert( !IsWindowFunc(pFunc) );
  if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) ){
    return eRet;
  }
  zFunc = pFunc->u.zToken;
  if( sqlite3StrICmp(zFunc, "min")==0 ){
    eRet = WHERE_ORDERBY_MIN;
    sortOrder = SQLITE_SO_ASC;
  }else if( sqlite3StrICmp(zFunc, "max")==0 ){
    eRet = WHERE_ORDERBY_MAX;
    sortOrder = SQLITE_SO_DESC;
  }else{
    return eRet;
  }
  *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
  assert( pOrderBy!=0 || db->mallocFailed );
  if( pOrderBy ) pOrderBy->a[0].sortOrder = sortOrder;
  return eRet;
}

/*
** The select statement passed as the first argument is an aggregate query.
** The second argument is the associated aggregate-info object. This 
** function tests if the SELECT is of the form:







|










|


|





|







4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
** analysis.
*/
static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
  int eRet = WHERE_ORDERBY_NORMAL;      /* Return value */
  ExprList *pEList = pFunc->x.pList;    /* Arguments to agg function */
  const char *zFunc;                    /* Name of aggregate function pFunc */
  ExprList *pOrderBy;
  u8 sortFlags;

  assert( *ppMinMax==0 );
  assert( pFunc->op==TK_AGG_FUNCTION );
  assert( !IsWindowFunc(pFunc) );
  if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) ){
    return eRet;
  }
  zFunc = pFunc->u.zToken;
  if( sqlite3StrICmp(zFunc, "min")==0 ){
    eRet = WHERE_ORDERBY_MIN;
    sortFlags = KEYINFO_ORDER_BIGNULL;
  }else if( sqlite3StrICmp(zFunc, "max")==0 ){
    eRet = WHERE_ORDERBY_MAX;
    sortFlags = KEYINFO_ORDER_DESC;
  }else{
    return eRet;
  }
  *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
  assert( pOrderBy!=0 || db->mallocFailed );
  if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
  return eRet;
}

/*
** The select statement passed as the first argument is an aggregate query.
** The second argument is the associated aggregate-info object. This 
** function tests if the SELECT is of the form:

Changes to src/sqliteInt.h.

2134
2135
2136
2137
2138
2139
2140
2141
2142
2143



2144
2145
2146
2147
2148
2149
2150
*/
struct KeyInfo {
  u32 nRef;           /* Number of references to this KeyInfo object */
  u8 enc;             /* Text encoding - one of the SQLITE_UTF* values */
  u16 nKeyField;      /* Number of key columns in the index */
  u16 nAllField;      /* Total columns, including key plus others */
  sqlite3 *db;        /* The database connection */
  u8 *aSortOrder;     /* Sort order for each column. */
  CollSeq *aColl[1];  /* Collating sequence for each term of the key */
};




/*
** This object holds a record which has been parsed out into individual
** fields, for the purposes of doing a comparison.
**
** A record is an object that contains one or more fields of data.
** Records are used to store the content of a table row and to store







|


>
>
>







2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
*/
struct KeyInfo {
  u32 nRef;           /* Number of references to this KeyInfo object */
  u8 enc;             /* Text encoding - one of the SQLITE_UTF* values */
  u16 nKeyField;      /* Number of key columns in the index */
  u16 nAllField;      /* Total columns, including key plus others */
  sqlite3 *db;        /* The database connection */
  u8 *aSortFlags;     /* Sort order for each column. */
  CollSeq *aColl[1];  /* Collating sequence for each term of the key */
};

#define KEYINFO_ORDER_DESC    0x01
#define KEYINFO_ORDER_BIGNULL 0x02

/*
** This object holds a record which has been parsed out into individual
** fields, for the purposes of doing a comparison.
**
** A record is an object that contains one or more fields of data.
** Records are used to store the content of a table row and to store
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610

2611
2612
2613
2614
2615
2616
2617
*/
struct ExprList {
  int nExpr;             /* Number of expressions on the list */
  struct ExprList_item { /* For each expression in the list */
    Expr *pExpr;            /* The parse tree for this expression */
    char *zName;            /* Token associated with this expression */
    char *zSpan;            /* Original text of the expression */
    u8 sortOrder;           /* 1 for DESC or 0 for ASC */
    unsigned done :1;       /* A flag to indicate when processing is finished */
    unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
    unsigned reusable :1;   /* Constant expression is reusable */
    unsigned bSorterRef :1; /* Defer evaluation until after sorting */

    union {
      struct {
        u16 iOrderByCol;      /* For ORDER BY, column number in result set */
        u16 iAlias;           /* Index into Parse.aAlias[] for zName */
      } x;
      int iConstExprReg;      /* Register in which Expr value is cached */
    } u;







|




>







2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
*/
struct ExprList {
  int nExpr;             /* Number of expressions on the list */
  struct ExprList_item { /* For each expression in the list */
    Expr *pExpr;            /* The parse tree for this expression */
    char *zName;            /* Token associated with this expression */
    char *zSpan;            /* Original text of the expression */
    u8 sortFlags;           /* Mask of KEYINFO_ORDER_* flags */
    unsigned done :1;       /* A flag to indicate when processing is finished */
    unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
    unsigned reusable :1;   /* Constant expression is reusable */
    unsigned bSorterRef :1; /* Defer evaluation until after sorting */
    unsigned bNulls: 1;     /* True if explicit "NULLS FIRST/LAST" */
    union {
      struct {
        u16 iOrderByCol;      /* For ORDER BY, column number in result set */
        u16 iAlias;           /* Index into Parse.aAlias[] for zName */
      } x;
      int iConstExprReg;      /* Register in which Expr value is cached */
    } u;
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
Expr *sqlite3ExprSimplifiedAndOr(Expr*);
Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
void sqlite3ExprDelete(sqlite3*, Expr*);
void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
void sqlite3ExprListSetSortOrder(ExprList*,int);
void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
void sqlite3ExprListDelete(sqlite3*, ExprList*);
u32 sqlite3ExprListFlags(const ExprList*);
int sqlite3IndexHasDuplicateRootPage(Index*);
int sqlite3Init(sqlite3*, char**);
int sqlite3InitCallback(void*, int, char**, char**);







|







3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
Expr *sqlite3ExprSimplifiedAndOr(Expr*);
Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
void sqlite3ExprDelete(sqlite3*, Expr*);
void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
void sqlite3ExprListSetSortOrder(ExprList*,int,int);
void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
void sqlite3ExprListDelete(sqlite3*, ExprList*);
u32 sqlite3ExprListFlags(const ExprList*);
int sqlite3IndexHasDuplicateRootPage(Index*);
int sqlite3Init(sqlite3*, char**);
int sqlite3InitCallback(void*, int, char**, char**);
4361
4362
4363
4364
4365
4366
4367

4368
4369
4370
4371
4372
4373
4374
Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
void sqlite3KeyInfoUnref(KeyInfo*);
KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);


#ifdef SQLITE_DEBUG
int sqlite3KeyInfoIsWriteable(KeyInfo*);
#endif
int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
  void (*)(sqlite3_context*,int,sqlite3_value **),
  void (*)(sqlite3_context*,int,sqlite3_value **), 







>







4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
void sqlite3KeyInfoUnref(KeyInfo*);
KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);
int sqlite3HasExplicitNulls(Parse*, ExprList*);

#ifdef SQLITE_DEBUG
int sqlite3KeyInfoIsWriteable(KeyInfo*);
#endif
int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
  void (*)(sqlite3_context*,int,sqlite3_value **),
  void (*)(sqlite3_context*,int,sqlite3_value **), 

Changes to src/trigger.c.

459
460
461
462
463
464
465



466
467
468
469
470
471
472
      pSelect = 0;
    }else{
      pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
    }
    pTriggerStep->pIdList = pColumn;
    pTriggerStep->pUpsert = pUpsert;
    pTriggerStep->orconf = orconf;



  }else{
    testcase( pColumn );
    sqlite3IdListDelete(db, pColumn);
    testcase( pUpsert );
    sqlite3UpsertDelete(db, pUpsert);
  }
  sqlite3SelectDelete(db, pSelect);







>
>
>







459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
      pSelect = 0;
    }else{
      pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
    }
    pTriggerStep->pIdList = pColumn;
    pTriggerStep->pUpsert = pUpsert;
    pTriggerStep->orconf = orconf;
    if( pUpsert ){
      sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget);
    }
  }else{
    testcase( pColumn );
    sqlite3IdListDelete(db, pColumn);
    testcase( pUpsert );
    sqlite3UpsertDelete(db, pUpsert);
  }
  sqlite3SelectDelete(db, pSelect);

Changes to src/vdbe.c.

2223
2224
2225
2226
2227
2228
2229
2230
2231
2232





2233
2234
2235
2236
2237
2238
2239
    idx = aPermute ? aPermute[i] : i;
    assert( memIsValid(&aMem[p1+idx]) );
    assert( memIsValid(&aMem[p2+idx]) );
    REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
    REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
    assert( i<pKeyInfo->nKeyField );
    pColl = pKeyInfo->aColl[i];
    bRev = pKeyInfo->aSortOrder[i];
    iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
    if( iCompare ){





      if( bRev ) iCompare = -iCompare;
      break;
    }
  }
  break;
}








|


>
>
>
>
>







2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
    idx = aPermute ? aPermute[i] : i;
    assert( memIsValid(&aMem[p1+idx]) );
    assert( memIsValid(&aMem[p2+idx]) );
    REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
    REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
    assert( i<pKeyInfo->nKeyField );
    pColl = pKeyInfo->aColl[i];
    bRev = (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC);
    iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
    if( iCompare ){
      if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) 
       && ((aMem[p1+idx].flags & MEM_Null) || (aMem[p2+idx].flags & MEM_Null))
      ){
        iCompare = -iCompare;
      }
      if( bRev ) iCompare = -iCompare;
      break;
    }
  }
  break;
}

Changes to src/vdbeaux.c.

1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503


1504
1505
1506
1507
1508
1509
1510
  StrAccum x;
  assert( nTemp>=20 );
  sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0);
  switch( pOp->p4type ){
    case P4_KEYINFO: {
      int j;
      KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
      assert( pKeyInfo->aSortOrder!=0 );
      sqlite3_str_appendf(&x, "k(%d", pKeyInfo->nKeyField);
      for(j=0; j<pKeyInfo->nKeyField; j++){
        CollSeq *pColl = pKeyInfo->aColl[j];
        const char *zColl = pColl ? pColl->zName : "";
        if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
        sqlite3_str_appendf(&x, ",%s%s", 
               pKeyInfo->aSortOrder[j] ? "-" : "", zColl);


      }
      sqlite3_str_append(&x, ")", 1);
      break;
    }
#ifdef SQLITE_ENABLE_CURSOR_HINTS
    case P4_EXPR: {
      displayP4Expr(&x, pOp->p4.pExpr);







|





|
|
>
>







1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
  StrAccum x;
  assert( nTemp>=20 );
  sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0);
  switch( pOp->p4type ){
    case P4_KEYINFO: {
      int j;
      KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
      assert( pKeyInfo->aSortFlags!=0 );
      sqlite3_str_appendf(&x, "k(%d", pKeyInfo->nKeyField);
      for(j=0; j<pKeyInfo->nKeyField; j++){
        CollSeq *pColl = pKeyInfo->aColl[j];
        const char *zColl = pColl ? pColl->zName : "";
        if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
        sqlite3_str_appendf(&x, ",%s%s%s", 
               (pKeyInfo->aSortFlags[j] & KEYINFO_ORDER_DESC) ? "-" : "", 
               (pKeyInfo->aSortFlags[j] & KEYINFO_ORDER_BIGNULL)? "N." : "", 
               zColl);
      }
      sqlite3_str_append(&x, ")", 1);
      break;
    }
#ifdef SQLITE_ENABLE_CURSOR_HINTS
    case P4_EXPR: {
      displayP4Expr(&x, pOp->p4.pExpr);
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
){
  UnpackedRecord *p;              /* Unpacked record to return */
  int nByte;                      /* Number of bytes required for *p */
  nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
  p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
  if( !p ) return 0;
  p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
  assert( pKeyInfo->aSortOrder!=0 );
  p->pKeyInfo = pKeyInfo;
  p->nField = pKeyInfo->nKeyField + 1;
  return p;
}

/*
** Given the nKey-byte encoding of a record in pKey[], populate the 







|







3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
){
  UnpackedRecord *p;              /* Unpacked record to return */
  int nByte;                      /* Number of bytes required for *p */
  nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
  p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
  if( !p ) return 0;
  p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
  assert( pKeyInfo->aSortFlags!=0 );
  p->pKeyInfo = pKeyInfo;
  p->nField = pKeyInfo->nKeyField + 1;
  return p;
}

/*
** Given the nKey-byte encoding of a record in pKey[], populate the 
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
  */
  /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
  
  idx1 = getVarint32(aKey1, szHdr1);
  if( szHdr1>98307 ) return SQLITE_CORRUPT;
  d1 = szHdr1;
  assert( pKeyInfo->nAllField>=pPKey2->nField || CORRUPT_DB );
  assert( pKeyInfo->aSortOrder!=0 );
  assert( pKeyInfo->nKeyField>0 );
  assert( idx1<=szHdr1 || CORRUPT_DB );
  do{
    u32 serial_type1;

    /* Read the serial types for the next element in each key. */
    idx1 += getVarint32( aKey1+idx1, serial_type1 );







|







3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
  */
  /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
  
  idx1 = getVarint32(aKey1, szHdr1);
  if( szHdr1>98307 ) return SQLITE_CORRUPT;
  d1 = szHdr1;
  assert( pKeyInfo->nAllField>=pPKey2->nField || CORRUPT_DB );
  assert( pKeyInfo->aSortFlags!=0 );
  assert( pKeyInfo->nKeyField>0 );
  assert( idx1<=szHdr1 || CORRUPT_DB );
  do{
    u32 serial_type1;

    /* Read the serial types for the next element in each key. */
    idx1 += getVarint32( aKey1+idx1, serial_type1 );
3939
3940
3941
3942
3943
3944
3945





3946
3947
3948
3949
3950
3951
3952
3953

    /* Do the comparison
    */
    rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
                           pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
    if( rc!=0 ){
      assert( mem1.szMalloc==0 );  /* See comment below */





      if( pKeyInfo->aSortOrder[i] ){
        rc = -rc;  /* Invert the result for DESC sort order. */
      }
      goto debugCompareEnd;
    }
    i++;
  }while( idx1<szHdr1 && i<pPKey2->nField );








>
>
>
>
>
|







3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960

    /* Do the comparison
    */
    rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
                           pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
    if( rc!=0 ){
      assert( mem1.szMalloc==0 );  /* See comment below */
      if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL)
       && ((mem1.flags & MEM_Null) || (pPKey2->aMem[i].flags & MEM_Null)) 
      ){
        rc = -rc;
      }
      if( pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC ){
        rc = -rc;  /* Invert the result for DESC sort order. */
      }
      goto debugCompareEnd;
    }
    i++;
  }while( idx1<szHdr1 && i<pPKey2->nField );

4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
    pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
    return 0;  /* Corruption */
  }

  VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
  assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField 
       || CORRUPT_DB );
  assert( pPKey2->pKeyInfo->aSortOrder!=0 );
  assert( pPKey2->pKeyInfo->nKeyField>0 );
  assert( idx1<=szHdr1 || CORRUPT_DB );
  do{
    u32 serial_type;

    /* RHS is an integer */
    if( pRhs->flags & (MEM_Int|MEM_IntReal) ){







|







4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
    pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
    return 0;  /* Corruption */
  }

  VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
  assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField 
       || CORRUPT_DB );
  assert( pPKey2->pKeyInfo->aSortFlags!=0 );
  assert( pPKey2->pKeyInfo->nKeyField>0 );
  assert( idx1<=szHdr1 || CORRUPT_DB );
  do{
    u32 serial_type;

    /* RHS is an integer */
    if( pRhs->flags & (MEM_Int|MEM_IntReal) ){
4438
4439
4440
4441
4442
4443
4444
4445





4446

4447
4448
4449
4450
4451
4452
4453
    /* RHS is null */
    else{
      serial_type = aKey1[idx1];
      rc = (serial_type!=0);
    }

    if( rc!=0 ){
      if( pPKey2->pKeyInfo->aSortOrder[i] ){





        rc = -rc;

      }
      assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
      assert( mem1.szMalloc==0 );  /* See comment below */
      return rc;
    }

    i++;







|
>
>
>
>
>
|
>







4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
    /* RHS is null */
    else{
      serial_type = aKey1[idx1];
      rc = (serial_type!=0);
    }

    if( rc!=0 ){
      int sortFlags = pPKey2->pKeyInfo->aSortFlags[i];
      if( sortFlags ){
        if( (sortFlags & KEYINFO_ORDER_BIGNULL)==0
         || ((sortFlags & KEYINFO_ORDER_DESC)
           !=(serial_type==0 || (pRhs->flags&MEM_Null)))
        ){
          rc = -rc;
        }
      }
      assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
      assert( mem1.szMalloc==0 );  /* See comment below */
      return rc;
    }

    i++;
4656
4657
4658
4659
4660
4661
4662
4663



4664
4665
4666
4667
4668
4669
4670
  ** is an integer.
  **
  ** The easiest way to enforce this limit is to consider only records with
  ** 13 fields or less. If the first field is an integer, the maximum legal
  ** header size is (12*5 + 1 + 1) bytes.  */
  if( p->pKeyInfo->nAllField<=13 ){
    int flags = p->aMem[0].flags;
    if( p->pKeyInfo->aSortOrder[0] ){



      p->r1 = 1;
      p->r2 = -1;
    }else{
      p->r1 = -1;
      p->r2 = 1;
    }
    if( (flags & MEM_Int) ){







|
>
>
>







4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
  ** is an integer.
  **
  ** The easiest way to enforce this limit is to consider only records with
  ** 13 fields or less. If the first field is an integer, the maximum legal
  ** header size is (12*5 + 1 + 1) bytes.  */
  if( p->pKeyInfo->nAllField<=13 ){
    int flags = p->aMem[0].flags;
    if( p->pKeyInfo->aSortFlags[0] ){
      if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
        return sqlite3VdbeRecordCompare;
      }
      p->r1 = 1;
      p->r2 = -1;
    }else{
      p->r1 = -1;
      p->r2 = 1;
    }
    if( (flags & MEM_Int) ){
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
  preupdate.v = v;
  preupdate.pCsr = pCsr;
  preupdate.op = op;
  preupdate.iNewReg = iReg;
  preupdate.keyinfo.db = db;
  preupdate.keyinfo.enc = ENC(db);
  preupdate.keyinfo.nKeyField = pTab->nCol;
  preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder;
  preupdate.iKey1 = iKey1;
  preupdate.iKey2 = iKey2;
  preupdate.pTab = pTab;

  db->pPreUpdate = &preupdate;
  db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
  db->pPreUpdate = 0;







|







5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
  preupdate.v = v;
  preupdate.pCsr = pCsr;
  preupdate.op = op;
  preupdate.iNewReg = iReg;
  preupdate.keyinfo.db = db;
  preupdate.keyinfo.enc = ENC(db);
  preupdate.keyinfo.nKeyField = pTab->nCol;
  preupdate.keyinfo.aSortFlags = (u8*)&fakeSortOrder;
  preupdate.iKey1 = iKey1;
  preupdate.iKey2 = iKey2;
  preupdate.pTab = pTab;

  db->pPreUpdate = &preupdate;
  db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
  db->pPreUpdate = 0;

Changes to src/vdbesort.c.

825
826
827
828
829
830
831

832
833
834
835
836
837
838
839
  if( res==0 ){
    if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
      res = vdbeSorterCompareTail(
          pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
      );
    }
  }else{

    if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
      res = res * -1;
    }
  }

  return res;
}








>
|







825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
  if( res==0 ){
    if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
      res = vdbeSorterCompareTail(
          pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
      );
    }
  }else{
    assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
    if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
      res = res * -1;
    }
  }

  return res;
}

893
894
895
896
897
898
899
900

901
902
903
904
905
906
907

  if( res==0 ){
    if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
      res = vdbeSorterCompareTail(
          pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
      );
    }
  }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){

    res = res * -1;
  }

  return res;
}

/*







|
>







894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909

  if( res==0 ){
    if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
      res = vdbeSorterCompareTail(
          pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
      );
    }
  }else if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
    assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
    res = res * -1;
  }

  return res;
}

/*
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
        pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
        if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
      }
    }

    if( pKeyInfo->nAllField<13 
     && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)

    ){
      pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
    }
  }

  return rc;
}







>







1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
        pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
        if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
      }
    }

    if( pKeyInfo->nAllField<13 
     && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
     && (pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL)==0
    ){
      pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
    }
  }

  return rc;
}

Changes to src/where.c.

930
931
932
933
934
935
936

937
938
939
940
941
942
943
  */
  nOrderBy = 0;
  if( pOrderBy ){
    int n = pOrderBy->nExpr;
    for(i=0; i<n; i++){
      Expr *pExpr = pOrderBy->a[i].pExpr;
      if( pExpr->op!=TK_COLUMN || pExpr->iTable!=pSrc->iCursor ) break;

    }
    if( i==n){
      nOrderBy = n;
    }
  }

  /* Allocate the sqlite3_index_info structure







>







930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
  */
  nOrderBy = 0;
  if( pOrderBy ){
    int n = pOrderBy->nExpr;
    for(i=0; i<n; i++){
      Expr *pExpr = pOrderBy->a[i].pExpr;
      if( pExpr->op!=TK_COLUMN || pExpr->iTable!=pSrc->iCursor ) break;
      if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
    }
    if( i==n){
      nOrderBy = n;
    }
  }

  /* Allocate the sqlite3_index_info structure
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
    }

    j++;
  }
  for(i=0; i<nOrderBy; i++){
    Expr *pExpr = pOrderBy->a[i].pExpr;
    pIdxOrderBy[i].iColumn = pExpr->iColumn;
    pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder;
  }

  *pmNoOmit = mNoOmit;
  return pIdxInfo;
}

/*







|







1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
    }

    j++;
  }
  for(i=0; i<nOrderBy; i++){
    Expr *pExpr = pOrderBy->a[i].pExpr;
    pIdxOrderBy[i].iColumn = pExpr->iColumn;
    pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
  }

  *pmNoOmit = mNoOmit;
  return pIdxInfo;
}

/*
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
        }

        /* Get the column number in the table (iColumn) and sort order
        ** (revIdx) for the j-th column of the index.
        */
        if( pIndex ){
          iColumn = pIndex->aiColumn[j];
          revIdx = pIndex->aSortOrder[j];
          if( iColumn==pIndex->pTable->iPKey ) iColumn = XN_ROWID;
        }else{
          iColumn = XN_ROWID;
          revIdx = 0;
        }

        /* An unconstrained column that might be NULL means that this







|







3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
        }

        /* Get the column number in the table (iColumn) and sort order
        ** (revIdx) for the j-th column of the index.
        */
        if( pIndex ){
          iColumn = pIndex->aiColumn[j];
          revIdx = pIndex->aSortOrder[j] & KEYINFO_ORDER_DESC;
          if( iColumn==pIndex->pTable->iPKey ) iColumn = XN_ROWID;
        }else{
          iColumn = XN_ROWID;
          revIdx = 0;
        }

        /* An unconstrained column that might be NULL means that this
3852
3853
3854
3855
3856
3857
3858

3859

3860
3861
3862
3863
3864







3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
          isMatch = 1;
          break;
        }
        if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
          /* Make sure the sort order is compatible in an ORDER BY clause.
          ** Sort order is irrelevant for a GROUP BY clause. */
          if( revSet ){

            if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;

          }else{
            rev = revIdx ^ pOrderBy->a[i].sortOrder;
            if( rev ) *pRevMask |= MASKBIT(iLoop);
            revSet = 1;
          }







        }
        if( isMatch ){
          if( iColumn==XN_ROWID ){
            testcase( distinctColumns==0 );
            distinctColumns = 1;
          }
          obSat |= MASKBIT(i);
          if( (wctrlFlags & WHERE_ORDERBY_MIN) && j==pLoop->u.btree.nEq ){
            pLoop->wsFlags |= WHERE_MIN_ORDERED;
          }
        }else{
          /* No match found */
          if( j==0 || j<nKeyCol ){
            testcase( isOrderDistinct!=0 );
            isOrderDistinct = 0;
          }
          break;







>
|
>

|



>
>
>
>
>
>
>







<
<
<







3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881



3882
3883
3884
3885
3886
3887
3888
          isMatch = 1;
          break;
        }
        if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
          /* Make sure the sort order is compatible in an ORDER BY clause.
          ** Sort order is irrelevant for a GROUP BY clause. */
          if( revSet ){
            if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
              isMatch = 0;
            }
          }else{
            rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
            if( rev ) *pRevMask |= MASKBIT(iLoop);
            revSet = 1;
          }
        }
        if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
          if( j==pLoop->u.btree.nEq ){
            pLoop->wsFlags |= WHERE_BIGNULL_SORT;
          }else{
            isMatch = 0;
          }
        }
        if( isMatch ){
          if( iColumn==XN_ROWID ){
            testcase( distinctColumns==0 );
            distinctColumns = 1;
          }
          obSat |= MASKBIT(i);



        }else{
          /* No match found */
          if( j==0 || j<nKeyCol ){
            testcase( isOrderDistinct!=0 );
            isOrderDistinct = 0;
          }
          break;
5061
5062
5063
5064
5065
5066
5067

5068
5069
5070
5071
5072
5073
5074
      assert( pIx->pSchema==pTab->pSchema );
      assert( iIndexCur>=0 );
      if( op ){
        sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
        sqlite3VdbeSetP4KeyInfo(pParse, pIx);
        if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
         && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0

         && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
         && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
        ){
          sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
        }
        VdbeComment((v, "%s", pIx->zName));
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK







>







5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
      assert( pIx->pSchema==pTab->pSchema );
      assert( iIndexCur>=0 );
      if( op ){
        sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
        sqlite3VdbeSetP4KeyInfo(pParse, pIx);
        if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
         && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
         && (pLoop->wsFlags & WHERE_BIGNULL_SORT)==0
         && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
         && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
        ){
          sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
        }
        VdbeComment((v, "%s", pIx->zName));
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
5202
5203
5204
5205
5206
5207
5208




5209
5210
5211
5212
5213
5214
5215
      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
      sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
      sqlite3VdbeChangeP5(v, pLevel->p5);
      VdbeCoverage(v);
      VdbeCoverageIf(v, pLevel->op==OP_Next);
      VdbeCoverageIf(v, pLevel->op==OP_Prev);
      VdbeCoverageIf(v, pLevel->op==OP_VNext);




#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
      if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
#endif
    }else{
      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
    }
    if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){







>
>
>
>







5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
      sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
      sqlite3VdbeChangeP5(v, pLevel->p5);
      VdbeCoverage(v);
      VdbeCoverageIf(v, pLevel->op==OP_Next);
      VdbeCoverageIf(v, pLevel->op==OP_Prev);
      VdbeCoverageIf(v, pLevel->op==OP_VNext);
      if( pLevel->regBignull ){
        sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
        sqlite3VdbeAddOp2(v, OP_IfNotZero, pLevel->regBignull, pLevel->p2-1);
      }
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
      if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
#endif
    }else{
      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
    }
    if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){

Changes to src/whereInt.h.

67
68
69
70
71
72
73


74
75
76
77
78
79
80
81
82
83
84
85
86
87
  int iIdxCur;          /* The VDBE cursor used to access pIdx */
  int addrBrk;          /* Jump here to break out of the loop */
  int addrNxt;          /* Jump here to start the next IN combination */
  int addrSkip;         /* Jump here for next iteration of skip-scan */
  int addrCont;         /* Jump here to continue with the next loop cycle */
  int addrFirst;        /* First instruction of interior of the loop */
  int addrBody;         /* Beginning of the body of this loop */


#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
  u32 iLikeRepCntr;     /* LIKE range processing counter register (times 2) */
  int addrLikeRep;      /* LIKE range processing address */
#endif
  u8 iFrom;             /* Which entry in the FROM clause */
  u8 op, p3, p5;        /* Opcode, P3 & P5 of the opcode that ends the loop */
  int p1, p2;           /* Operands of the opcode used to ends the loop */
  union {               /* Information that depends on pWLoop->wsFlags */
    struct {
      int nIn;              /* Number of entries in aInLoop[] */
      struct InLoop {
        int iCur;              /* The VDBE cursor used by this IN operator */
        int addrInTop;         /* Top of the IN loop */
        int iBase;             /* Base register of multi-key index record */







>
>






|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  int iIdxCur;          /* The VDBE cursor used to access pIdx */
  int addrBrk;          /* Jump here to break out of the loop */
  int addrNxt;          /* Jump here to start the next IN combination */
  int addrSkip;         /* Jump here for next iteration of skip-scan */
  int addrCont;         /* Jump here to continue with the next loop cycle */
  int addrFirst;        /* First instruction of interior of the loop */
  int addrBody;         /* Beginning of the body of this loop */
  int regBignull;       /* big-null flag reg. True if a NULL-scan is needed */
  int addrBignull;      /* Jump here for next part of big-null scan */
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
  u32 iLikeRepCntr;     /* LIKE range processing counter register (times 2) */
  int addrLikeRep;      /* LIKE range processing address */
#endif
  u8 iFrom;             /* Which entry in the FROM clause */
  u8 op, p3, p5;        /* Opcode, P3 & P5 of the opcode that ends the loop */
  int p1, p2;           /* Operands of the opcode used to end the loop */
  union {               /* Information that depends on pWLoop->wsFlags */
    struct {
      int nIn;              /* Number of entries in aInLoop[] */
      struct InLoop {
        int iCur;              /* The VDBE cursor used by this IN operator */
        int addrInTop;         /* Top of the IN loop */
        int iBase;             /* Base register of multi-key index record */
582
583
584
585
586
587
588
589
590
591
#define WHERE_ONEROW       0x00001000  /* Selects no more than one row */
#define WHERE_MULTI_OR     0x00002000  /* OR using multiple indices */
#define WHERE_AUTO_INDEX   0x00004000  /* Uses an ephemeral index */
#define WHERE_SKIPSCAN     0x00008000  /* Uses the skip-scan algorithm */
#define WHERE_UNQ_WANTED   0x00010000  /* WHERE_ONEROW would have been helpful*/
#define WHERE_PARTIALIDX   0x00020000  /* The automatic index is partial */
#define WHERE_IN_EARLYOUT  0x00040000  /* Perhaps quit IN loops early */
#define WHERE_MIN_ORDERED  0x00080000  /* Column nEq of index is min() expr */

#endif /* !defined(SQLITE_WHEREINT_H) */







|


584
585
586
587
588
589
590
591
592
593
#define WHERE_ONEROW       0x00001000  /* Selects no more than one row */
#define WHERE_MULTI_OR     0x00002000  /* OR using multiple indices */
#define WHERE_AUTO_INDEX   0x00004000  /* Uses an ephemeral index */
#define WHERE_SKIPSCAN     0x00008000  /* Uses the skip-scan algorithm */
#define WHERE_UNQ_WANTED   0x00010000  /* WHERE_ONEROW would have been helpful*/
#define WHERE_PARTIALIDX   0x00020000  /* The automatic index is partial */
#define WHERE_IN_EARLYOUT  0x00040000  /* Perhaps quit IN loops early */
#define WHERE_BIGNULL_SORT 0x00080000  /* Column nEq of index is BIGNULL */

#endif /* !defined(SQLITE_WHEREINT_H) */

Changes to src/wherecode.c.

1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
    int nExtraReg = 0;           /* Number of extra registers needed */
    int op;                      /* Instruction opcode */
    char *zStartAff;             /* Affinity for start of range constraint */
    char *zEndAff = 0;           /* Affinity for end of range constraint */
    u8 bSeekPastNull = 0;        /* True to seek past initial nulls */
    u8 bStopAtNull = 0;          /* Add condition to terminate at NULLs */
    int omitTable;               /* True if we use the index only */


    pIdx = pLoop->u.btree.pIndex;
    iIdxCur = pLevel->iIdxCur;
    assert( nEq>=pLoop->nSkip );

    /* If this loop satisfies a sort order (pOrderBy) request that 
    ** was passed to this function to implement a "SELECT min(x) ..." 
    ** query, then the caller will only allow the loop to run for
    ** a single iteration. This means that the first row returned
    ** should not have a NULL value stored in 'x'. If column 'x' is
    ** the first one after the nEq equality constraints in the index,
    ** this requires some special handling.
    */
    assert( (pWInfo->pOrderBy!=0 && pWInfo->pOrderBy->nExpr==1)
         || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
    if( pLoop->wsFlags & WHERE_MIN_ORDERED ){
      assert( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN) );
      assert( pWInfo->nOBSat );
      assert( pIdx->nColumn>nEq );
      assert( pLoop->nSkip==0 );
      bSeekPastNull = 1;
      nExtraReg = 1;
    }

    /* Find any inequality constraint terms for the start and end 
    ** of the range. 
    */
    j = nEq;
    if( pLoop->wsFlags & WHERE_BTM_LIMIT ){
      pRangeStart = pLoop->aLTerm[j++];
      nExtraReg = MAX(nExtraReg, pLoop->u.btree.nBtm);







|





<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558



















1559
1560
1561
1562
1563
1564
1565
    int nExtraReg = 0;           /* Number of extra registers needed */
    int op;                      /* Instruction opcode */
    char *zStartAff;             /* Affinity for start of range constraint */
    char *zEndAff = 0;           /* Affinity for end of range constraint */
    u8 bSeekPastNull = 0;        /* True to seek past initial nulls */
    u8 bStopAtNull = 0;          /* Add condition to terminate at NULLs */
    int omitTable;               /* True if we use the index only */
    int regBignull = 0;          /* big-null flag register */

    pIdx = pLoop->u.btree.pIndex;
    iIdxCur = pLevel->iIdxCur;
    assert( nEq>=pLoop->nSkip );




















    /* Find any inequality constraint terms for the start and end 
    ** of the range. 
    */
    j = nEq;
    if( pLoop->wsFlags & WHERE_BTM_LIMIT ){
      pRangeStart = pLoop->aLTerm[j++];
      nExtraReg = MAX(nExtraReg, pLoop->u.btree.nBtm);
1610
1611
1612
1613
1614
1615
1616



















1617
1618
1619
1620
1621
1622
1623
        j = pIdx->aiColumn[nEq];
        if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
          bSeekPastNull = 1;
        }
      }
    }
    assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 );




















    /* If we are doing a reverse order scan on an ascending index, or
    ** a forward order scan on a descending index, interchange the 
    ** start and end terms (pRangeStart and pRangeEnd).
    */
    if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
     || (bRev && pIdx->nKeyCol==nEq)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
        j = pIdx->aiColumn[nEq];
        if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
          bSeekPastNull = 1;
        }
      }
    }
    assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 );

    /* If the WHERE_BIGNULL_SORT flag is set, then index column nEq uses
    ** a non-default "big-null" sort (either ASC NULLS LAST or DESC NULLS 
    ** FIRST). In both cases separate ordered scans are made of those
    ** index entries for which the column is null and for those for which
    ** it is not. For an ASC sort, the non-NULL entries are scanned first.
    ** For DESC, NULL entries are scanned first.
    */
    if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
     && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
    ){
      assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
      assert( pRangeEnd==0 && pRangeStart==0 );
      assert( pLoop->nSkip==0 );
      nExtraReg = 1;
      bSeekPastNull = 1;
      pLevel->regBignull = regBignull = ++pParse->nMem;
      pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse);
    }

    /* If we are doing a reverse order scan on an ascending index, or
    ** a forward order scan on a descending index, interchange the 
    ** start and end terms (pRangeStart and pRangeEnd).
    */
    if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
     || (bRev && pIdx->nKeyCol==nEq)
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
    */
    codeCursorHint(pTabItem, pWInfo, pLevel, pRangeEnd);
    regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
    assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
    if( zStartAff && nTop ){
      zEndAff = sqlite3DbStrDup(db, &zStartAff[nEq]);
    }
    addrNxt = pLevel->addrNxt;

    testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
    testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
    testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
    testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
    startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
    endEq =   !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);







|







1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
    */
    codeCursorHint(pTabItem, pWInfo, pLevel, pRangeEnd);
    regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
    assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
    if( zStartAff && nTop ){
      zEndAff = sqlite3DbStrDup(db, &zStartAff[nEq]);
    }
    addrNxt = (regBignull ? pLevel->addrBignull : pLevel->addrNxt);

    testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
    testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
    testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
    testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
    startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
    endEq =   !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);
1667
1668
1669
1670
1671
1672
1673

1674

1675
1676


1677

1678
1679
1680
1681
1682
1683
1684
1685
1686
1687





1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699

1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712

1713


1714
1715

1716
1717
1718
1719
1720
1721
1722
      if( sqlite3ExprIsVector(pRight)==0 ){
        disableTerm(pLevel, pRangeStart);
      }else{
        startEq = 1;
      }
      bSeekPastNull = 0;
    }else if( bSeekPastNull ){

      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);

      nConstraint++;
      startEq = 0;


      start_constraints = 1;

    }
    codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
    if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){
      /* The skip-scan logic inside the call to codeAllEqualityConstraints()
      ** above has already left the cursor sitting on the correct row,
      ** so no further seeking is needed */
    }else{
      if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){
        sqlite3VdbeAddOp1(v, OP_SeekHit, iIdxCur);
      }





      op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
      assert( op!=0 );
      sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
      VdbeCoverage(v);
      VdbeCoverageIf(v, op==OP_Rewind);  testcase( op==OP_Rewind );
      VdbeCoverageIf(v, op==OP_Last);    testcase( op==OP_Last );
      VdbeCoverageIf(v, op==OP_SeekGT);  testcase( op==OP_SeekGT );
      VdbeCoverageIf(v, op==OP_SeekGE);  testcase( op==OP_SeekGE );
      VdbeCoverageIf(v, op==OP_SeekLE);  testcase( op==OP_SeekLE );
      VdbeCoverageIf(v, op==OP_SeekLT);  testcase( op==OP_SeekLT );

      if( bSeekPastNull && (pLoop->wsFlags & WHERE_TOP_LIMIT)==0 ){

        /* If bSeekPastNull is set only to skip past the NULL values for
        ** a query like "SELECT min(a), b FROM t1", then add code so that
        ** if there are no rows with (a IS NOT NULL), then do the seek 
        ** without jumping past NULLs instead. This allows the code in 
        ** select.c to pick a value for "b" in the above query.  */
        assert( startEq==0 && (op==OP_SeekGT || op==OP_SeekLT) );
        assert( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 && pWInfo->nOBSat>0 );
        sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
        sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);

        op = aStartOp[(start_constraints<<2) + (1<<1) + bRev];
        assert( op==OP_SeekGE || op==OP_SeekLE );
        sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);

        VdbeCoverage(v);


        VdbeCoverageIf(v, op==OP_SeekGE);  testcase( op==OP_SeekGE );
        VdbeCoverageIf(v, op==OP_SeekLE);  testcase( op==OP_SeekLE );

      }
    }

    /* Load the value for the inequality constraint at the end of the
    ** range (if any).
    */
    nConstraint = nEq;







>

>

<
>
>

>










>
>
>
>
>











|
>
|
<
<
<
<
|
|
<

|
<
<
|
>

>
>


>







1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677

1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710




1711
1712

1713
1714


1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
      if( sqlite3ExprIsVector(pRight)==0 ){
        disableTerm(pLevel, pRangeStart);
      }else{
        startEq = 1;
      }
      bSeekPastNull = 0;
    }else if( bSeekPastNull ){
      startEq = 0;
      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
      start_constraints = 1;
      nConstraint++;

    }else if( regBignull ){
      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
      start_constraints = 1;
      nConstraint++;
    }
    codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
    if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){
      /* The skip-scan logic inside the call to codeAllEqualityConstraints()
      ** above has already left the cursor sitting on the correct row,
      ** so no further seeking is needed */
    }else{
      if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){
        sqlite3VdbeAddOp1(v, OP_SeekHit, iIdxCur);
      }
      if( regBignull ){
        sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
        VdbeComment((v, "NULL-scan pass ctr"));
      }

      op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
      assert( op!=0 );
      sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
      VdbeCoverage(v);
      VdbeCoverageIf(v, op==OP_Rewind);  testcase( op==OP_Rewind );
      VdbeCoverageIf(v, op==OP_Last);    testcase( op==OP_Last );
      VdbeCoverageIf(v, op==OP_SeekGT);  testcase( op==OP_SeekGT );
      VdbeCoverageIf(v, op==OP_SeekGE);  testcase( op==OP_SeekGE );
      VdbeCoverageIf(v, op==OP_SeekLE);  testcase( op==OP_SeekLE );
      VdbeCoverageIf(v, op==OP_SeekLT);  testcase( op==OP_SeekLT );

      assert( bSeekPastNull==0 || bStopAtNull==0 );
      if( regBignull ){
        assert( bSeekPastNull==1 || bStopAtNull==1 );




        assert( bSeekPastNull==!bStopAtNull );
        assert( bStopAtNull==startEq );

        sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
        op = aStartOp[(nConstraint>1)*4 + 2 + bRev];


        sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, 
                             nConstraint-startEq);
        VdbeCoverage(v);
        VdbeCoverageIf(v, op==OP_Rewind);  testcase( op==OP_Rewind );
        VdbeCoverageIf(v, op==OP_Last);    testcase( op==OP_Last );
        VdbeCoverageIf(v, op==OP_SeekGE);  testcase( op==OP_SeekGE );
        VdbeCoverageIf(v, op==OP_SeekLE);  testcase( op==OP_SeekLE );
        assert( op==OP_Rewind || op==OP_Last || op==OP_SeekGE || op==OP_SeekLE);
      }
    }

    /* Load the value for the inequality constraint at the end of the
    ** range (if any).
    */
    nConstraint = nEq;
1741
1742
1743
1744
1745
1746
1747

1748
1749

1750
1751
1752
1753
1754
1755
1756
1757
1758
1759






1760
1761

















1762
1763
1764
1765
1766
1767
1768

      if( sqlite3ExprIsVector(pRight)==0 ){
        disableTerm(pLevel, pRangeEnd);
      }else{
        endEq = 1;
      }
    }else if( bStopAtNull ){

      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
      endEq = 0;

      nConstraint++;
    }
    sqlite3DbFree(db, zStartAff);
    sqlite3DbFree(db, zEndAff);

    /* Top of the loop body */
    pLevel->p2 = sqlite3VdbeCurrentAddr(v);

    /* Check if the index cursor is past the end of the range. */
    if( nConstraint ){






      op = aEndOp[bRev*2 + endEq];
      sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);

















      testcase( op==OP_IdxGT );  VdbeCoverageIf(v, op==OP_IdxGT );
      testcase( op==OP_IdxGE );  VdbeCoverageIf(v, op==OP_IdxGE );
      testcase( op==OP_IdxLT );  VdbeCoverageIf(v, op==OP_IdxLT );
      testcase( op==OP_IdxLE );  VdbeCoverageIf(v, op==OP_IdxLE );
    }

    if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){







>
|
|
>










>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800

      if( sqlite3ExprIsVector(pRight)==0 ){
        disableTerm(pLevel, pRangeEnd);
      }else{
        endEq = 1;
      }
    }else if( bStopAtNull ){
      if( regBignull==0 ){
        sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
        endEq = 0;
      }
      nConstraint++;
    }
    sqlite3DbFree(db, zStartAff);
    sqlite3DbFree(db, zEndAff);

    /* Top of the loop body */
    pLevel->p2 = sqlite3VdbeCurrentAddr(v);

    /* Check if the index cursor is past the end of the range. */
    if( nConstraint ){
      if( regBignull ){
        /* Except, skip the end-of-range check while doing the NULL-scan */
        sqlite3VdbeAddOp2(v, OP_IfNot, regBignull, sqlite3VdbeCurrentAddr(v)+3);
        VdbeComment((v, "If NULL-scan 2nd pass"));
        VdbeCoverage(v);
      }
      op = aEndOp[bRev*2 + endEq];
      sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
      testcase( op==OP_IdxGT );  VdbeCoverageIf(v, op==OP_IdxGT );
      testcase( op==OP_IdxGE );  VdbeCoverageIf(v, op==OP_IdxGE );
      testcase( op==OP_IdxLT );  VdbeCoverageIf(v, op==OP_IdxLT );
      testcase( op==OP_IdxLE );  VdbeCoverageIf(v, op==OP_IdxLE );
    }
    if( regBignull ){
      /* During a NULL-scan, check to see if we have reached the end of
      ** the NULLs */
      assert( bSeekPastNull==!bStopAtNull );
      assert( bSeekPastNull+bStopAtNull==1 );
      assert( nConstraint+bSeekPastNull>0 );
      sqlite3VdbeAddOp2(v, OP_If, regBignull, sqlite3VdbeCurrentAddr(v)+2);
      VdbeComment((v, "If NULL-scan 1st pass"));
      VdbeCoverage(v);
      op = aEndOp[bRev*2 + bSeekPastNull];
      sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase,
                           nConstraint+bSeekPastNull);
      testcase( op==OP_IdxGT );  VdbeCoverageIf(v, op==OP_IdxGT );
      testcase( op==OP_IdxGE );  VdbeCoverageIf(v, op==OP_IdxGE );
      testcase( op==OP_IdxLT );  VdbeCoverageIf(v, op==OP_IdxLT );
      testcase( op==OP_IdxLE );  VdbeCoverageIf(v, op==OP_IdxLE );
    }

    if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){

Changes to src/window.c.

884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
    for(i=0; i<pAppend->nExpr; i++){
      Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
      if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
        pDup->op = TK_NULL;
        pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
      }
      pList = sqlite3ExprListAppend(pParse, pList, pDup);
      if( pList ) pList->a[nInit+i].sortOrder = pAppend->a[i].sortOrder;
    }
  }
  return pList;
}

/*
** If the SELECT statement passed as the second argument does not invoke







|







884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
    for(i=0; i<pAppend->nExpr; i++){
      Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
      if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
        pDup->op = TK_NULL;
        pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
      }
      pList = sqlite3ExprListAppend(pParse, pList, pDup);
      if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
    }
  }
  return pList;
}

/*
** If the SELECT statement passed as the second argument does not invoke
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
      */
      ExprList *pList = pWin->pOwner->x.pList;
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
      pWin->csrApp = pParse->nTab++;
      pWin->regApp = pParse->nMem+1;
      pParse->nMem += 3;
      if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
        assert( pKeyInfo->aSortOrder[0]==0 );
        pKeyInfo->aSortOrder[0] = 1;
      }
      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2);
      sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
    }
    else if( p->zName==nth_valueName || p->zName==first_valueName ){
      /* Allocate two registers at pWin->regApp. These will be used to







|
|







1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
      */
      ExprList *pList = pWin->pOwner->x.pList;
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
      pWin->csrApp = pParse->nTab++;
      pWin->regApp = pParse->nMem+1;
      pParse->nMem += 3;
      if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
        assert( pKeyInfo->aSortFlags[0]==0 );
        pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
      }
      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2);
      sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
    }
    else if( p->zName==nth_valueName || p->zName==first_valueName ){
      /* Allocate two registers at pWin->regApp. These will be used to
1872
1873
1874
1875
1876
1877
1878

1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903






















1904
1905
1906
1907
1908
1909
1910
){
  Parse *pParse = p->pParse;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int reg1 = sqlite3GetTempReg(pParse);
  int reg2 = sqlite3GetTempReg(pParse);
  int arith = OP_Add;
  int addrGe;


  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].sortOrder ){
    switch( op ){
      case OP_Ge: op = OP_Le; break;
      case OP_Gt: op = OP_Lt; break;
      default: assert( op==OP_Le ); op = OP_Ge; break;
    }
    arith = OP_Subtract;
  }

  windowReadPeerValues(p, csr1, reg1);
  windowReadPeerValues(p, csr2, reg2);

  /* Check if the peer value for csr1 value is a text or blob by comparing
  ** it to the smallest possible string - ''. If it is, jump over the
  ** OP_Add or OP_Subtract operation and proceed directly to the comparison. */
  sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
  addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
  VdbeCoverage(v);
  sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
  sqlite3VdbeJumpHere(v, addrGe);






















  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 );
  testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
  testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
  testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
  testcase(op==OP_Gt); VdbeCoverageIf(v, op==OP_Gt);







>




|
|



















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
){
  Parse *pParse = p->pParse;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int reg1 = sqlite3GetTempReg(pParse);
  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( 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;
      default: assert( op==OP_Le ); op = OP_Ge; break;
    }
    arith = OP_Subtract;
  }

  windowReadPeerValues(p, csr1, reg1);
  windowReadPeerValues(p, csr2, reg2);

  /* Check if the peer value for csr1 value is a text or blob by comparing
  ** it to the smallest possible string - ''. If it is, jump over the
  ** OP_Add or OP_Subtract operation and proceed directly to the comparison. */
  sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
  addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
  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); 
        VdbeCoverage(v); 
        break;
      case OP_Le: 
        sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); 
        VdbeCoverage(v); 
        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 );
  testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
  testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
  testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
  testcase(op==OP_Gt); VdbeCoverageIf(v, op==OP_Gt);

Changes to test/minmax4.test.

195
196
197
198
199
200
201

































202
203
  CREATE TABLE t1 (a, b);
  INSERT INTO t1 VALUES(123, NULL);
  CREATE INDEX i1 ON t1(a, b DESC);
}
do_execsql_test 5.1 {
  SELECT MIN(a) FROM t1 WHERE a=123;
} {123}


































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  CREATE TABLE t1 (a, b);
  INSERT INTO t1 VALUES(123, NULL);
  CREATE INDEX i1 ON t1(a, b DESC);
}
do_execsql_test 5.1 {
  SELECT MIN(a) FROM t1 WHERE a=123;
} {123}

#-------------------------------------------------------------------------
# Tests for ticket f8a7060ece.
#
reset_db
do_execsql_test 6.1.0 {
  CREATE TABLE t1(a, b, c);
  INSERT INTO t1 VALUES(NULL, 1, 'x');
  CREATE INDEX i1 ON t1(a);
}
do_execsql_test 6.1.1 {
  SELECT min(a), b, c FROM t1 WHERE c='x';
} {{} 1 x}
do_execsql_test 6.1.2 {
  INSERT INTO t1 VALUES(1,    2, 'y');
} {}
do_execsql_test 6.1.3 {
  SELECT min(a), b, c FROM t1 WHERE c='x';
} {{} 1 x}

do_execsql_test 6.2.0 {
  CREATE TABLE t0(c0 UNIQUE, c1);
  INSERT INTO t0(c1) VALUES (0);
  INSERT INTO t0(c0) VALUES (0);
  CREATE VIEW v0(c0, c1) AS 
      SELECT t0.c1, t0.c0 FROM t0 WHERE CAST(t0.rowid AS INT) = 1;
}
do_execsql_test 6.2.1 {
  SELECT c0, c1 FROM v0;
} {0 {}}
do_execsql_test 6.2.2 {
  SELECT v0.c0, MIN(v0.c1) FROM v0;
} {0 {}}

finish_test

Added test/nulls1.test.





































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# 2019 August 10
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix nulls1

do_execsql_test 1.0 {
  DROP TABLE IF EXISTS t3;
  CREATE TABLE t3(a INTEGER);
  INSERT INTO t3 VALUES(NULL), (10), (30), (20), (NULL);
} {}

for {set a 0} {$a < 3} {incr a} {
  foreach {tn limit} {
    1 ""
    2 "LIMIT 10"
  } {
    do_execsql_test 1.$a.$tn.1 "
      SELECT a FROM t3 ORDER BY a nULLS FIRST $limit
    " {{}   {}   10   20   30}
    
    do_execsql_test 1.$a.$tn.2 "
      SELECT a FROM t3 ORDER BY a nULLS LAST $limit
    " {10   20   30   {}   {}}
    
    do_execsql_test 1.$a.$tn.3 "
      SELECT a FROM t3 ORDER BY a DESC nULLS FIRST $limit
    " {{}   {}   30   20   10}
    
    do_execsql_test 1.$a.$tn.4 "
      SELECT a FROM t3 ORDER BY a DESC nULLS LAST $limit
    " {30   20   10   {}   {}}
  }

  switch $a {
    0 {
      execsql { CREATE INDEX i1 ON t3(a) }
    }
    1 {
      execsql { DROP INDEX i1 ; CREATE INDEX i1 ON t3(a DESC) }
    }
  }
}

#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
  CREATE TABLE t2(a, b, c);
  CREATE INDEX i2 ON t2(a, b);
  INSERT INTO t2 VALUES(1, 1, 1);
  INSERT INTO t2 VALUES(1, NULL, 2);
  INSERT INTO t2 VALUES(1, NULL, 3);
  INSERT INTO t2 VALUES(1, 4, 4);
}

do_execsql_test 2.1 {
  SELECT * FROM t2 WHERE a=1 ORDER BY b NULLS LAST
} {
  1 1 1    1 4 4   1 {} 2   1 {} 3
}

do_execsql_test 2.2 {
  SELECT * FROM t2 WHERE a=1 ORDER BY b DESC NULLS FIRST
} {
  1 {} 3
  1 {} 2     
  1 4 4     
  1 1 1
}

#-------------------------------------------------------------------------
#
reset_db
do_execsql_test 3.0 {
  CREATE TABLE t1(a, b, c, d, UNIQUE (b));
}
foreach {tn sql err}  {
  1 { CREATE INDEX i1 ON t1(a ASC NULLS LAST) }           LAST
  2 { CREATE INDEX i1 ON t1(a ASC NULLS FIRST) }          FIRST
  3 { CREATE INDEX i1 ON t1(a, b ASC NULLS LAST) }        LAST
  4 { CREATE INDEX i1 ON t1(a, b ASC NULLS FIRST) }       FIRST
  5 { CREATE INDEX i1 ON t1(a DESC NULLS LAST) }          LAST
  6 { CREATE INDEX i1 ON t1(a DESC NULLS FIRST) }         FIRST
  7 { CREATE INDEX i1 ON t1(a, b DESC NULLS LAST) }       LAST
  8 { CREATE INDEX i1 ON t1(a, b DESC NULLS FIRST) }      FIRST
  9  { CREATE TABLE t2(a, b, PRIMARY KEY(a DESC, b NULLS FIRST)) } FIRST
  10 { CREATE TABLE t2(a, b, UNIQUE(a DESC NULLS FIRST, b)) }      FIRST
  11 { INSERT INTO t1 VALUES(1, 2, 3, 4)
          ON CONFLICT (b DESC NULLS LAST) DO UPDATE SET a = a+1 } LAST
  12 {
    CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
      INSERT INTO t1 VALUES(1, 2, 3, 4)
      ON CONFLICT (b DESC NULLS FIRST) DO UPDATE SET a = a+1;
    END
  } FIRST
} {
  do_catchsql_test 3.1.$tn $sql "1 {unsupported use of NULLS $err}"
}

do_execsql_test 3.2 {
  CREATE TABLE first(nulls, last);
  INSERT INTO first(last, nulls) VALUES(100,200), (300,400), (200,300);
  SELECT * FROM first ORDER BY nulls;
} {
  200 100
  300 200
  400 300
}

#-------------------------------------------------------------------------
#
ifcapable vtab {
  register_echo_module db
  do_execsql_test 4.0 {
    CREATE TABLE tx(a INTEGER PRIMARY KEY, b, c);
    CREATE INDEX i1 ON tx(b);
    INSERT INTO tx VALUES(1, 1, 1);
    INSERT INTO tx VALUES(2, NULL, 2);
    INSERT INTO tx VALUES(3, 3, 3);
    INSERT INTO tx VALUES(4, NULL, 4);
    INSERT INTO tx VALUES(5, 5, 5);
    CREATE VIRTUAL TABLE te USING echo(tx);
  }

  do_execsql_test 4.1 {
    SELECT * FROM tx ORDER BY b NULLS FIRST;
  } {2 {} 2  4 {} 4  1 1 1  3 3 3  5 5 5}
  do_execsql_test 4.2 {
    SELECT * FROM te ORDER BY b NULLS FIRST;
  } {2 {} 2  4 {} 4  1 1 1  3 3 3  5 5 5}

  do_execsql_test 4.3 {
    SELECT * FROM tx ORDER BY b NULLS LAST;
  } {1 1 1  3 3 3  5 5 5  2 {} 2  4 {} 4}
  do_execsql_test 4.4 {
    SELECT * FROM te ORDER BY b NULLS LAST;
  } {1 1 1  3 3 3  5 5 5  2 {} 2  4 {} 4}
}

#-------------------------------------------------------------------------
#
do_execsql_test 5.0 {
  CREATE TABLE t4(a, b, c);
  INSERT INTO t4 VALUES(1, 1, 11);
  INSERT INTO t4 VALUES(1, 2, 12);
  INSERT INTO t4 VALUES(1, NULL, 1);

  INSERT INTO t4 VALUES(2, NULL, 1);
  INSERT INTO t4 VALUES(2, 2, 12);
  INSERT INTO t4 VALUES(2, 1, 11);

  INSERT INTO t4 VALUES(3, NULL, 1);
  INSERT INTO t4 VALUES(3, 2, 12);
  INSERT INTO t4 VALUES(3, NULL, 3);
}

do_execsql_test 5.1 {
  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a, b NULLS LAST
} {
  1 1 11   1 2 12   1 {} 1   
  2 1 11   2 2 12   2 {} 1 
  3 2 12   3 {} 1   3 {} 3
}
do_execsql_test 5.2 {
  CREATE INDEX t4ab ON t4(a, b);
  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a, b NULLS LAST
} {
  1 1 11   1 2 12   1 {} 1   
  2 1 11   2 2 12   2 {} 1 
  3 2 12   3 {} 1   3 {} 3
}
do_eqp_test 5.3 {
  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a, b NULLS LAST
} {
  QUERY PLAN
  `--SEARCH TABLE t4 USING INDEX t4ab (a=?)
}

do_execsql_test 5.4 {
  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a DESC, b DESC NULLS FIRST
} {
  3 {} 3   3 {} 1   3 2 12   
  2 {} 1   2 2 12   2 1 11   
  1 {} 1   1 2 12   1 1 11   
}
do_eqp_test 5.5 {
  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a DESC, b DESC NULLS FIRST
} {
  QUERY PLAN
  `--SEARCH TABLE t4 USING INDEX t4ab (a=?)
}

#-------------------------------------------------------------------------
#
do_execsql_test 6.0 {
  CREATE TABLE t5(a, b, c);
  WITH s(i) AS (
    VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<200
  ) 
  INSERT INTO t5 SELECT i%2, CASE WHEN (i%10)==0 THEN NULL ELSE i END, i FROM s;
}

set res1 [db eval { SELECT a,b FROM t5 WHERE a=1 ORDER BY b NULLS LAST, c }]
set res2 [db eval { 
  SELECT a,b FROM t5 WHERE a=1 ORDER BY b DESC NULLS FIRST, c DESC 
}]

do_execsql_test 6.1.1 {
  CREATE INDEX t5ab ON t5(a, b, c);
  SELECT a,b FROM t5 WHERE a=1 ORDER BY b NULLS LAST, c;
} $res1
do_eqp_test 6.1.2 {
  SELECT a,b FROM t5 WHERE a=1 ORDER BY b NULLS LAST, c;
} {
  QUERY PLAN
  `--SEARCH TABLE t5 USING COVERING INDEX t5ab (a=?)
}
do_execsql_test 6.2.1 {
  SELECT a,b FROM t5 WHERE a=1 ORDER BY b DESC NULLS FIRST, c DESC 
} $res2
do_eqp_test 6.2.2 {
  SELECT a,b FROM t5 WHERE a=1 ORDER BY b DESC NULLS FIRST, c DESC 
} {
  QUERY PLAN
  `--SEARCH TABLE t5 USING COVERING INDEX t5ab (a=?)
}


finish_test


Changes to test/pg_common.tcl.

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

  set ret
}

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]
  puts $::fd "do_execsql_test $tn {"
  puts $::fd "  [string trim $sql]"
  puts $::fd "} {$res}"
  puts $::fd ""
}

proc errorsql_test {tn sql} {







|
|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

  set ret
}

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]
  puts $::fd "do_execsql_test $tn {"
  puts $::fd "  [string trim $sql]"
  puts $::fd "} {$res}"
  puts $::fd ""
}

proc errorsql_test {tn sql} {

Changes to test/window7.test.

37
38
39
40
41
42
43
44

45
46
47
48
49
50











51
52
53
54
55
56











57
58
59
60
61
62












63
64
65
66
67
68











69
70
71
72
73
74












75
76
77
78
79
80












81
82
83
84
85
86











87
88
89
90
91
92











93
94
    (1, 81), (2, 82), (3, 83), (4, 84), (5, 85), (6, 86), (7, 87), (8, 88), 
    (9, 89), (0, 90), (1, 91), (2, 92), (3, 93), (4, 94), (5, 95), (6, 96), 
    (7, 97), (8, 98), (9, 99), (0, 100);
} {}

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}


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}












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}












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}













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}












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}













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}













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}












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}












finish_test







|
>





|
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>
>





|
>
>
>
>
>
>
>
>
>
>
>


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
    (1, 81), (2, 82), (3, 83), (4, 84), (5, 85), (6, 86), (7, 87), (8, 88), 
    (9, 89), (0, 90), (1, 91), (2, 92), (3, 93), (4, 94), (5, 95), (6, 96), 
    (7, 97), (8, 98), (9, 99), (0, 100);
} {}

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}

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}

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}

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}

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}

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}

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}

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}

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}

finish_test

Changes to test/window8.tcl.

193
194
195
196
197
198
199




200

201
202
203
204
205





206
207
208
209
210
211





212
213
214
215
216
217




218

219
220
221
222
223





224
225
226
227
228
229
230
}

execsql_test 4.2.1 {
  SELECT sum(b) OVER (
    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 DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
  ) FROM t1 ORDER BY 1 NULLS FIRST;
}






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.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 DESC NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
  ) FROM t1 ORDER BY 1 NULLS FIRST;
}






==========

execsql_test 5.0 {
  INSERT INTO t3 VALUES
    (NULL, 'bb', 355), (NULL, 'cc', 158), (NULL, 'aa', 399), 
    ('JJ', NULL, 839), ('FF', NULL, 618), ('BB', NULL, 393), 







>
>
>
>
|
>
|




>
>
>
>
>






>
>
>
>
>






>
>
>
>
|
>
|




>
>
>
>
>







193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
}

execsql_test 4.2.1 {
  SELECT sum(b) OVER (
    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;
}

==========

execsql_test 5.0 {
  INSERT INTO t3 VALUES
    (NULL, 'bb', 355), (NULL, 'cc', 158), (NULL, 'aa', 399), 
    ('JJ', NULL, 839), ('FF', NULL, 618), ('BB', NULL, 393), 
244
245
246
247
248
249
250











251
252
253
254
255
256
257
    3 { PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
    4 { ORDER BY a NULLS FIRST GROUPS 6 PRECEDING }
    5 { ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING }
    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 }











  } {
    execsql_test 5.$tn.$tn2.1 "
      SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS ( $frame $ex )







>
>
>
>
>
>
>
>
>
>
>







269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
    3 { PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
    4 { ORDER BY a NULLS FIRST GROUPS 6 PRECEDING }
    5 { ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING }
    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,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS ( $frame $ex )
288
289
290
291
292
293
294

295
296
297
298
299

execsql_test 6.2 {
  SELECT string_agg(a, '.') OVER (
    ORDER BY b DESC NULLS LAST RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  )
  FROM t2
}



finish_test









>





324
325
326
327
328
329
330
331
332
333
334
335
336

execsql_test 6.2 {
  SELECT string_agg(a, '.') OVER (
    ORDER BY b DESC NULLS LAST RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  )
  FROM t2
}



finish_test


Changes to test/window8.test.

3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529






3530
3531
3532






3533
3534
3535
3536
3537
3538
3539






3540
3541
3542
3543
3544
3545
3546
3547
3548
3549












3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
    ORDER BY a DESC RANGE BETWEEN 5 PRECEDING AND 10 FOLLOWING
  ) FROM t1 ORDER BY 1;
} {6   6   6   9   9}

do_execsql_test 4.2.1 {
  SELECT sum(b) OVER (
    ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
  ) FROM t1 ORDER BY 1 ;
} {{}   {}   6   6   6}

do_execsql_test 4.2.2 {
  SELECT sum(b) OVER (






    ORDER BY a DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
  ) FROM t1 ORDER BY 1 ;
} {{}   {}   6   6   6}







do_execsql_test 4.3.1 {
  SELECT sum(b) OVER (
    ORDER BY a  RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
  ) FROM t1 ORDER BY 1 ;
} {6   6   6   15   15}







do_execsql_test 4.4.1 {
  SELECT sum(b) OVER (
    ORDER BY a  ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
  ) FROM t1 ORDER BY 1 ;
} {3   6   9   9   12}

do_execsql_test 4.4.2 {
  SELECT sum(b) OVER (
    ORDER BY a DESC  ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
  ) FROM t1 ORDER BY 1 ;












} {5   6   8   9   10}

#==========================================================================

do_execsql_test 5.0 {
  INSERT INTO t3 VALUES
    (NULL, 'bb', 355), (NULL, 'cc', 158), (NULL, 'aa', 399), 
    ('JJ', NULL, 839), ('FF', NULL, 618), ('BB', NULL, 393), 
    (NULL, 'bb', 629), (NULL, NULL, 667), (NULL, NULL, 870);
} {}

do_execsql_test 5.1.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83







|




>
>
>
>
>
>

|

>
>
>
>
>
>



|
|


>
>
>
>
>
>


|
|




|
|
>
>
>
>
>
>
>
>
>
>
>
>

















|







3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
    ORDER BY a DESC RANGE BETWEEN 5 PRECEDING AND 10 FOLLOWING
  ) FROM t1 ORDER BY 1;
} {6   6   6   9   9}

do_execsql_test 4.2.1 {
  SELECT sum(b) OVER (
    ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
  ) FROM t1 ORDER BY 1 NULLS FIRST;
} {{}   {}   6   6   6}

do_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;
} {6   6   6   {}   {}}

do_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;
} {{}   {}   6   6   6}

do_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;
} {6   6   6   {}   {}}

do_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;
} {6   6   6   15   15}

do_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;
} {9   9   15   15   15}

do_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;
} {3   6   9   9   12}

do_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;
} {5   6   8   9   10}

do_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;
} {5   6   8   9   10}

do_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;
} {5   6   8   9   10}

#==========================================================================

do_execsql_test 5.0 {
  INSERT INTO t3 VALUES
    (NULL, 'bb', 355), (NULL, 'cc', 158), (NULL, 'aa', 399), 
    ('JJ', NULL, 839), ('FF', NULL, 618), ('BB', NULL, 393), 
    (NULL, 'bb', 629), (NULL, NULL, 667), (NULL, NULL, 870);
} {}

do_execsql_test 5.1.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597

do_execsql_test 5.1.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1







|







3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627

do_execsql_test 5.1.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.1.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {899 113 9   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  899 113 16   899 113 16   899 113 16   899 113 16   979 102 44   979 102 44
  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 44
  979 102 44   979 102 44   979 102 44   979 102 49   979 102 49   979 102 49
  979 102 49   979 102 49   979 102 56   979 102 56   979 102 56   979 102 56
  979 102 56   979 102 56   979 102 56   979 102 62   979 102 62   979 102 62







|

|







3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.1.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {899 113 9   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  899 113 16   899 113 16   899 113 16   899 113 16   979 102 44   979 102 44
  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 44
  979 102 44   979 102 44   979 102 44   979 102 49   979 102 49   979 102 49
  979 102 49   979 102 49   979 102 56   979 102 56   979 102 56   979 102 56
  979 102 56   979 102 56   979 102 56   979 102 62   979 102 62   979 102 62
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
  979 113 33   979 113 33   979 113 33   979 113 33   979 113 33}

do_execsql_test 5.1.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {2947 81 11   2947 81 11   2947 81 11   2947 81 11   2947 81 11   2947 81 11
  2947 81 11   2947 81 11   2947 81 11   5287 74 10   5287 74 10   5287 74 10
  5287 74 10   5287 74 10   5287 74 10   5287 74 10   8400 65 9   8400 65 9
  8400 65 9   8400 65 9   8400 65 9   8400 65 9   8400 65 9   8400 65 9
  8400 65 9   9664 57 8   9664 57 8   9664 57 8   9664 57 8   9664 57 8
  9664 57 8   9664 57 8   9664 57 8   10626 46 7   10626 46 7   10626 46 7
  10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7







|

|







3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
  979 113 33   979 113 33   979 113 33   979 113 33   979 113 33}

do_execsql_test 5.1.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2947 81 11   2947 81 11   2947 81 11   2947 81 11   2947 81 11   2947 81 11
  2947 81 11   2947 81 11   2947 81 11   5287 74 10   5287 74 10   5287 74 10
  5287 74 10   5287 74 10   5287 74 10   5287 74 10   8400 65 9   8400 65 9
  8400 65 9   8400 65 9   8400 65 9   8400 65 9   8400 65 9   8400 65 9
  8400 65 9   9664 57 8   9664 57 8   9664 57 8   9664 57 8   9664 57 8
  9664 57 8   9664 57 8   9664 57 8   10626 46 7   10626 46 7   10626 46 7
  10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
do_execsql_test 5.1.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {777 113 5   777 113 5   777 113 5   777 113 5   777 113 5   805 250 7
  805 250 7   805 250 7   805 250 7   805 250 7   805 250 7   805 250 7
  822 158 6   822 158 6   822 158 6   822 158 6   822 158 6   822 158 6
  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  840 247 13   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  870 158 0   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9







|







3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
do_execsql_test 5.1.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {777 113 5   777 113 5   777 113 5   777 113 5   777 113 5   805 250 7
  805 250 7   805 250 7   805 250 7   805 250 7   805 250 7   805 250 7
  822 158 6   822 158 6   822 158 6   822 158 6   822 158 6   822 158 6
  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  840 247 13   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  870 158 0   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
do_execsql_test 5.1.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1   1264 1 1
  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1
  1366 1 1   1366 1 1   1366 1 1   1366 1 1   1519 1 1   1519 1 1   1519 1 1
  1519 1 1   1519 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1
  1804 1 1   1804 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1
  2050 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1
  2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1
  2340 1 1   2340 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1
  2947 1 1   2947 1 1   2947 1 1   2947 1 1   3113 1 1   3113 1 1   3113 1 1
  3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}

do_execsql_test 5.1.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  934 158 8   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  934 158 8   934 158 8   934 158 21   934 158 21   934 158 21   934 158 21
  934 158 21   934 158 21   934 158 21   934 158 21   934 158 21   934 158 21
  934 158 21   934 158 21   934 158 21   934 158 27   934 158 27   934 158 27
  934 158 27   934 158 27   934 158 27   959 102 50   959 102 50   959 102 50
  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50







|



















|
|







3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
do_execsql_test 5.1.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1   1264 1 1
  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1
  1366 1 1   1366 1 1   1366 1 1   1366 1 1   1519 1 1   1519 1 1   1519 1 1
  1519 1 1   1519 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1
  1804 1 1   1804 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1
  2050 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1
  2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1
  2340 1 1   2340 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1
  2947 1 1   2947 1 1   2947 1 1   2947 1 1   3113 1 1   3113 1 1   3113 1 1
  3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}

do_execsql_test 5.1.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  934 158 8   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  934 158 8   934 158 8   934 158 21   934 158 21   934 158 21   934 158 21
  934 158 21   934 158 21   934 158 21   934 158 21   934 158 21   934 158 21
  934 158 21   934 158 21   934 158 21   934 158 27   934 158 27   934 158 27
  934 158 27   934 158 27   934 158 27   959 102 50   959 102 50   959 102 50
  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
  979 102 59   979 102 59   979 102 59   979 102 59   979 102 59}

do_execsql_test 5.1.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   4359 7 2
  4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2
  7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  7840 15 3   9206 28 4   9206 28 4   9206 28 4   9206 28 4   9206 28 4
  9206 28 4   11010 34 5   11010 34 5   11010 34 5   11010 34 5   11010 34 5
  11010 34 5   11010 34 5   12368 74 10   12368 74 10   12368 74 10







|
|







3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
  979 102 59   979 102 59   979 102 59   979 102 59   979 102 59}

do_execsql_test 5.1.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   4359 7 2
  4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2
  7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  7840 15 3   9206 28 4   9206 28 4   9206 28 4   9206 28 4   9206 28 4
  9206 28 4   11010 34 5   11010 34 5   11010 34 5   11010 34 5   11010 34 5
  11010 34 5   11010 34 5   12368 74 10   12368 74 10   12368 74 10
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
  13949 81 11}

do_execsql_test 5.1.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   160 158 2
  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  346 346 1   355 354 2   355 354 2   355 354 2   399 393 4   399 393 4
  399 393 4   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 2   480 480 2   574 572 2   574 572 2   607 607 1







|
|







3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
  13949 81 11}

do_execsql_test 5.1.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   160 158 2
  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  346 346 1   355 354 2   355 354 2   355 354 2   399 393 4   399 393 4
  399 393 4   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 2   480 480 2   574 572 2   574 572 2   607 607 1
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
  938 934 3   938 934 3   963 959 2   963 959 2   979 979 1}

do_execsql_test 5.1.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  {} 85 72   133 4 3   223 10 8   223 11 9   226 2 2   226 2 2   239 12 10
  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  309 21 19   335 22 20   335 23 21   335 24 22   421 35 30   443 37 32
  504 16 14   504 17 15   607 42 36   683 56 47   710 26 24   710 27 25
  710 27 25   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1334 51 43
  1416 57 48   1416 58 49   1584 29 26   1584 29 26   1584 31 27   1584 32 28
  1584 32 28   1891 49 41   1922 87 73   1922 88 74   2005 52 44   2005 52 44
  2005 54 45   2005 55 46   2518 45 38   2518 46 39   2518 46 39   2518 48 40
  2523 73 63   2523 73 63   2523 75 64   2523 76 65   2523 77 66}

do_execsql_test 5.1.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   158 158 1
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 1   355 355 1   393 393 2   393 393 2
  398 398 1   399 399 1   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 2   480 480 2   572 572 1   574 574 1   607 607 1







|
|




















|
|







3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
  938 934 3   938 934 3   963 959 2   963 959 2   979 979 1}

do_execsql_test 5.1.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  {} 85 72   133 4 3   223 10 8   223 11 9   226 2 2   226 2 2   239 12 10
  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  309 21 19   335 22 20   335 23 21   335 24 22   421 35 30   443 37 32
  504 16 14   504 17 15   607 42 36   683 56 47   710 26 24   710 27 25
  710 27 25   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1334 51 43
  1416 57 48   1416 58 49   1584 29 26   1584 29 26   1584 31 27   1584 32 28
  1584 32 28   1891 49 41   1922 87 73   1922 88 74   2005 52 44   2005 52 44
  2005 54 45   2005 55 46   2518 45 38   2518 46 39   2518 46 39   2518 48 40
  2523 73 63   2523 73 63   2523 75 64   2523 76 65   2523 77 66}

do_execsql_test 5.1.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   158 158 1
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 1   355 355 1   393 393 2   393 393 2
  398 398 1   399 399 1   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 2   480 480 2   572 572 1   574 574 1   607 607 1
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
  938 938 2   938 938 2   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.1.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   133 4 3   223 10 8
  226 2 2   226 2 2   239 14 12   247 15 13   257 19 17   295 20 18
  309 21 19   335 23 21   421 35 30   443 37 32   607 42 36   627 45 38
  633 48 40   671 55 46   683 56 47   705 57 48   710 27 25   710 27 25
  711 58 49   759 62 53   777 66 56   786 29 26   786 29 26   798 32 28
  798 32 28   805 71 61   845 77 66   899 81 68   911 82 69   929 83 70
  959 87 73   963 88 74   979 89 75   1258 46 39   1258 46 39   1334 52 44
  1334 52 44   1678 73 63   1678 73 63}

do_execsql_test 5.1.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c , b , a 
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  979 346 60   979 354 59   979 355 58   979 355 58   979 393 56   979 393 57
  979 398 55   979 399 54   979 399 54   979 412 53   979 421 52   979 430 51







|
|




















|

|







3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
  938 938 2   938 938 2   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.1.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   133 4 3   223 10 8
  226 2 2   226 2 2   239 14 12   247 15 13   257 19 17   295 20 18
  309 21 19   335 23 21   421 35 30   443 37 32   607 42 36   627 45 38
  633 48 40   671 55 46   683 56 47   705 57 48   710 27 25   710 27 25
  711 58 49   759 62 53   777 66 56   786 29 26   786 29 26   798 32 28
  798 32 28   805 71 61   845 77 66   899 81 68   911 82 69   929 83 70
  959 87 73   963 88 74   979 89 75   1258 46 39   1258 46 39   1334 52 44
  1334 52 44   1678 73 63   1678 73 63}

do_execsql_test 5.1.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  979 346 60   979 354 59   979 355 58   979 355 58   979 393 56   979 393 57
  979 398 55   979 399 54   979 399 54   979 412 53   979 421 52   979 430 51
3860
3861
3862
3863
3864
3865
3866








































































3867






































































































































































































































3868
3869
























3870
3871
3872
3873
3874
3875
3876
  979 870 11   979 870 11   979 899 9   979 911 8   979 929 7}

do_execsql_test 5.1.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3








































































      WINDOW win AS (  ORDER BY c , b , a 






































































































































































































































        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 , 2 , 3
























} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
  979 870 11   979 870 11   979 899 9   979 911 8   979 929 7}

do_execsql_test 5.1.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
  17126 49 49   17126 50 50   17126 51 51   17733 44 44   17733 45 45
  17733 46 46   17733 47 47   17733 48 48   18176 42 42   18176 43 43
  18597 40 40   18597 41 41   18996 39 39   19395 37 37   19395 38 38
  19788 36 36   20181 35 35   20536 34 34   20891 30 30   20891 31 31
  20891 32 32   20891 33 33   21226 28 28   21226 29 29   21535 27 27
  21830 26 26   22087 22 22   22087 23 23   22087 24 24   22087 25 25
  22334 21 21   22573 17 17   22573 18 18   22573 19 19   22573 20 20
  22796 11 11   22796 12 12   22796 13 13   22796 14 14   22796 15 15
  22796 16 16   22929 10 10   23042 9 9   23155 1 1   23155 2 2   23155 3 3
  23155 4 4   23155 5 5   23155 6 6   23155 7 7   23155 8 8}

do_execsql_test 5.1.8.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83}

do_execsql_test 5.1.8.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.1.9.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  899 113 9   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  899 113 16   899 113 16   899 113 16   899 113 16   979 102 44   979 102 44
  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 44
  979 102 44   979 102 44   979 102 44   979 102 49   979 102 49   979 102 49
  979 102 49   979 102 49   979 102 56   979 102 56   979 102 56   979 102 56
  979 102 56   979 102 56   979 102 56   979 102 62   979 102 62   979 102 62
  979 102 62   979 102 62   979 102 62   979 102 75   979 102 75   979 102 75
  979 102 75   979 102 75   979 102 75   979 102 75   979 102 75   979 102 75
  979 102 75   979 102 75   979 102 75   979 102 75   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 113 25   979 113 25   979 113 25   979 113 25   979 113 25   979 113 25
  979 113 25   979 113 25   979 113 25   979 113 33   979 113 33   979 113 33
  979 113 33   979 113 33   979 113 33   979 113 33   979 113 33}

do_execsql_test 5.1.9.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2050 84 11   2050 84 11   2050 84 11   2050 84 11   2050 84 11   2050 84 11
  4997 75 10   4997 75 10   4997 75 10   4997 75 10   4997 75 10   4997 75 10
  4997 75 10   4997 75 10   4997 75 10   7337 68 9   7337 68 9   7337 68 9
  7337 68 9   7337 68 9   7337 68 9   7337 68 9   10450 59 8   10450 59 8
  10450 59 8   10450 59 8   10450 59 8   10450 59 8   10450 59 8   10450 59 8
  10450 59 8   11714 51 7   11714 51 7   11714 51 7   11714 51 7   11714 51 7
  11714 51 7   11714 51 7   11714 51 7   12676 40 6   12676 40 6   12676 40 6
  12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6
  12676 40 6   12676 40 6   14195 35 5   14195 35 5   14195 35 5   14195 35 5
  14195 35 5   15999 28 4   15999 28 4   15999 28 4   15999 28 4   15999 28 4
  15999 28 4   15999 28 4   17365 22 3   17365 22 3   17365 22 3   17365 22 3
  17365 22 3   17365 22 3   20846 9 2   20846 9 2   20846 9 2   20846 9 2
  20846 9 2   20846 9 2   20846 9 2   20846 9 2   20846 9 2   20846 9 2
  20846 9 2   20846 9 2   20846 9 2   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.1.10.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {777 113 5   777 113 5   777 113 5   777 113 5   777 113 5   805 250 7
  805 250 7   805 250 7   805 250 7   805 250 7   805 250 7   805 250 7
  822 158 6   822 158 6   822 158 6   822 158 6   822 158 6   822 158 6
  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  840 247 13   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  870 158 0   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
  899 113 9   899 113 9   899 113 9   899 113 9   934 223 8   934 223 8
  934 223 8   934 223 8   934 223 8   934 223 8   934 223 8   934 223 8
  938 102 11   938 102 11   938 102 11   938 102 11   938 102 11   938 102 11
  938 102 11   938 102 11   938 102 11   938 102 11   938 102 11   938 148 8
  938 148 8   938 148 8   938 148 8   938 148 8   938 148 8   938 148 8
  938 148 8   959 224 7   959 224 7   959 224 7   959 224 7   959 224 7
  959 224 7   959 224 7   979 133 9   979 133 9   979 133 9   979 133 9
  979 133 9   979 133 9   979 133 9   979 133 9   979 133 9}

do_execsql_test 5.1.10.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1   1264 1 1
  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1
  1366 1 1   1366 1 1   1366 1 1   1366 1 1   1519 1 1   1519 1 1   1519 1 1
  1519 1 1   1519 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1
  1804 1 1   1804 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1
  2050 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1
  2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1
  2340 1 1   2340 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1
  2947 1 1   2947 1 1   2947 1 1   2947 1 1   3113 1 1   3113 1 1   3113 1 1
  3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}

do_execsql_test 5.1.11.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {934 158 27   934 158 27   934 158 27   934 158 27   934 158 27   934 158 27
  934 223 8   934 223 8   934 223 8   934 223 8   934 223 8   934 223 8
  934 223 8   934 223 8   934 223 21   934 223 21   934 223 21   934 223 21
  934 223 21   934 223 21   934 223 21   934 223 21   934 223 21   934 223 21
  934 223 21   934 223 21   934 223 21   959 102 50   959 102 50   959 102 50
  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
  959 102 50   959 102 50   959 102 58   959 102 58   959 102 58   959 102 58
  959 102 58   959 102 58   959 102 58   959 102 58   959 113 39   959 113 39
  959 113 39   959 113 39   959 113 39   959 158 34   959 158 34   959 158 34
  959 158 34   959 158 34   959 158 34   959 158 34   979 102 49   979 102 49
  979 102 49   979 102 49   979 102 49   979 102 49   979 102 53   979 102 53
  979 102 53   979 102 53   979 102 53   979 102 53   979 102 53   979 102 56
  979 102 56   979 102 56   979 102 56   979 102 56   979 102 56   979 102 56
  979 102 56   979 102 56   979 102 59   979 102 59   979 102 59   979 102 59
  979 102 59   979 102 59   979 102 59   979 102 59   979 102 59}

do_execsql_test 5.1.11.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1
  2309 1 1   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2
  5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2
  7156 22 3   7156 22 3   7156 22 3   7156 22 3   7156 22 3   7156 22 3
  8960 28 4   8960 28 4   8960 28 4   8960 28 4   8960 28 4   8960 28 4
  8960 28 4   10479 35 5   10479 35 5   10479 35 5   10479 35 5   10479 35 5
  11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6
  11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6   12368 68 9
  12368 68 9   12368 68 9   12368 68 9   12368 68 9   12368 68 9   12368 68 9
  12705 51 7   12705 51 7   12705 51 7   12705 51 7   12705 51 7   12705 51 7
  12705 51 7   12705 51 7   13509 59 8   13509 59 8   13509 59 8   13509 59 8
  13509 59 8   13509 59 8   13509 59 8   13509 59 8   13509 59 8
  13949 75 10   13949 75 10   13949 75 10   13949 75 10   13949 75 10
  13949 75 10   13949 75 10   13949 75 10   13949 75 10   14195 84 11
  14195 84 11   14195 84 11   14195 84 11   14195 84 11   14195 84 11}

do_execsql_test 5.1.12.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   160 158 2
  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  346 346 1   355 354 2   355 354 2   355 354 2   399 393 4   399 393 4
  399 393 4   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 2   480 480 2   574 572 2   574 572 2   607 607 1
  618 618 2   618 618 2   634 627 4   634 627 4   634 627 4   634 627 4
  634 629 3   652 652 1   667 660 2   671 667 3   671 667 3   671 667 3
  671 667 3   683 683 1   711 705 2   716 705 3   716 711 2   730 726 2
  730 726 2   762 759 2   768 759 4   768 762 3   768 762 3   777 777 1
  792 786 3   794 786 4   794 786 4   794 790 3   805 805 1   822 822 1
  845 839 5   845 839 5   845 839 5   845 839 5   845 839 5   870 870 2
  870 870 2   870 870 2   899 899 1   911 911 1   934 929 2   938 929 4
  938 934 3   938 934 3   963 959 2   963 959 2   979 979 1}

do_execsql_test 5.1.12.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  {} 85 72   133 4 3   223 10 8   223 11 9   226 2 2   226 2 2   239 12 10
  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  309 21 19   335 22 20   335 23 21   335 24 22   421 35 30   443 37 32
  504 16 14   504 17 15   607 42 36   683 56 47   710 26 24   710 27 25
  710 27 25   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1334 51 43
  1416 57 48   1416 58 49   1584 29 26   1584 29 26   1584 31 27   1584 32 28
  1584 32 28   1891 49 41   1922 87 73   1922 88 74   2005 52 44   2005 52 44
  2005 54 45   2005 55 46   2518 45 38   2518 46 39   2518 46 39   2518 48 40
  2523 73 63   2523 73 63   2523 75 64   2523 76 65   2523 77 66}

do_execsql_test 5.1.13.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   158 158 1
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 1   355 355 1   393 393 2   393 393 2
  398 398 1   399 399 1   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 2   480 480 2   572 572 1   574 574 1   607 607 1
  618 618 2   618 618 2   627 627 1   629 629 1   629 629 1   633 633 1
  634 634 1   652 652 1   660 660 1   667 667 1   667 667 1   670 670 1
  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
  730 730 1   759 759 1   762 762 1   768 768 2   768 768 2   777 777 1
  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
  839 839 2   839 839 2   840 840 1   844 844 1   845 845 1   870 870 2
  870 870 2   870 870 2   899 899 1   911 911 1   929 929 1   934 934 1
  938 938 2   938 938 2   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.1.13.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   133 4 3   223 10 8
  226 2 2   226 2 2   239 14 12   247 15 13   257 19 17   295 20 18
  309 21 19   335 23 21   421 35 30   443 37 32   607 42 36   627 45 38
  633 48 40   671 55 46   683 56 47   705 57 48   710 27 25   710 27 25
  711 58 49   759 62 53   777 66 56   786 29 26   786 29 26   798 32 28
  798 32 28   805 71 61   845 77 66   899 81 68   911 82 69   929 83 70
  959 87 73   963 88 74   979 89 75   1258 46 39   1258 46 39   1334 52 44
  1334 52 44   1678 73 63   1678 73 63}

do_execsql_test 5.1.14.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  979 346 60   979 354 59   979 355 57   979 355 58   979 393 56   979 393 57
  979 398 55   979 399 53   979 399 54   979 412 53   979 421 52   979 430 51
  979 443 50   979 480 48   979 480 49   979 572 47   979 574 46   979 607 45
  979 618 43   979 618 44   979 627 42   979 629 40   979 629 41   979 633 40
  979 634 39   979 652 38   979 660 37   979 667 35   979 667 36   979 670 35
  979 671 34   979 683 33   979 705 32   979 711 31   979 716 30   979 726 29
  979 730 28   979 759 27   979 762 26   979 768 24   979 768 25   979 777 23
  979 786 22   979 790 21   979 792 20   979 794 19   979 805 18   979 822 17
  979 839 15   979 839 16   979 840 14   979 844 13   979 845 12   979 870 9
  979 870 10   979 870 11   979 899 9   979 911 8   979 929 7}

do_execsql_test 5.1.14.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901

do_execsql_test 5.2.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {963 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82







|







4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257

do_execsql_test 5.2.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {963 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924

do_execsql_test 5.2.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {22176 1 1   22192 1 1   22196 1 1   22226 1 1   22244 1 1   22256 1 1
  22310 1 1   22316 1 1   22316 1 1   22350 1 1   22378 1 1   22396 1 1
  22444 1 1   22450 1 1   22472 1 1   22484 1 1   22488 1 1   22488 1 1
  22522 1 1   22526 1 1   22526 1 1   22528 1 1   22548 1 1   22712 1 1
  22734 1 1   22756 1 1   22756 1 1   22762 1 1   22762 1 1   22800 1 1
  22800 1 1   22820 1 1   22846 1 1   22860 1 1   22898 1 1   22908 1 1
  22916 1 1   22932 1 1   23022 1 1   23042 1 1   23042 1 1   23155 1 1







|







4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280

do_execsql_test 5.2.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {22176 1 1   22192 1 1   22196 1 1   22226 1 1   22244 1 1   22256 1 1
  22310 1 1   22316 1 1   22316 1 1   22350 1 1   22378 1 1   22396 1 1
  22444 1 1   22450 1 1   22472 1 1   22484 1 1   22488 1 1   22488 1 1
  22522 1 1   22526 1 1   22526 1 1   22528 1 1   22548 1 1   22712 1 1
  22734 1 1   22756 1 1   22756 1 1   22762 1 1   22762 1 1   22800 1 1
  22800 1 1   22820 1 1   22846 1 1   22860 1 1   22898 1 1   22908 1 1
  22916 1 1   22932 1 1   23022 1 1   23042 1 1   23042 1 1   23155 1 1
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.2.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {839 113 8   899 113 8   899 113 8   899 113 8   899 113 8   899 113 8
  899 113 8   899 113 8   899 113 15   899 113 15   899 113 15   899 113 15
  899 113 15   899 113 15   899 113 15   899 234 8   963 113 24   979 102 43
  979 102 43   979 102 43   979 102 43   979 102 43   979 102 43   979 102 43
  979 102 43   979 102 43   979 102 43   979 102 48   979 102 48   979 102 48
  979 102 48   979 102 48   979 102 55   979 102 55   979 102 55   979 102 55
  979 102 55   979 102 55   979 102 55   979 102 61   979 102 61   979 102 61







|

|







4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.2.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {839 113 8   899 113 8   899 113 8   899 113 8   899 113 8   899 113 8
  899 113 8   899 113 8   899 113 15   899 113 15   899 113 15   899 113 15
  899 113 15   899 113 15   899 113 15   899 234 8   963 113 24   979 102 43
  979 102 43   979 102 43   979 102 43   979 102 43   979 102 43   979 102 43
  979 102 43   979 102 43   979 102 43   979 102 48   979 102 48   979 102 48
  979 102 48   979 102 48   979 102 55   979 102 55   979 102 55   979 102 55
  979 102 55   979 102 55   979 102 55   979 102 61   979 102 61   979 102 61
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
  979 113 32   979 113 32   979 113 32   979 113 32   979 113 43}

do_execsql_test 5.2.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {2048 81 11   2108 81 11   2108 81 11   2690 81 11   2834 81 11   2947 81 11
  2947 81 11   2947 81 11   2947 81 11   4482 74 10   4616 74 10   4844 74 10
  4866 74 10   5287 74 10   5287 74 10   5287 74 10   7421 65 9   7437 65 9
  7717 65 9   8045 65 9   8267 65 9   8400 65 9   8400 65 9   8400 65 9
  8400 65 9   8735 57 8   9329 57 8   9664 57 8   9664 57 8   9664 57 8
  9664 57 8   9664 57 8   9664 57 8   9959 46 7   10331 46 7   10626 46 7
  10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7







|

|







4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
  979 113 32   979 113 32   979 113 32   979 113 32   979 113 43}

do_execsql_test 5.2.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2048 81 11   2108 81 11   2108 81 11   2690 81 11   2834 81 11   2947 81 11
  2947 81 11   2947 81 11   2947 81 11   4482 74 10   4616 74 10   4844 74 10
  4866 74 10   5287 74 10   5287 74 10   5287 74 10   7421 65 9   7437 65 9
  7717 65 9   8045 65 9   8267 65 9   8400 65 9   8400 65 9   8400 65 9
  8400 65 9   8735 57 8   9329 57 8   9664 57 8   9664 57 8   9664 57 8
  9664 57 8   9664 57 8   9664 57 8   9959 46 7   10331 46 7   10626 46 7
  10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
do_execsql_test 5.2.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {667 158 0   671 250 6   759 158 5   768 113 4   777 113 4   777 113 4
  777 113 4   777 252 4   792 247 12   805 250 6   805 250 6   805 250 6
  805 250 6   805 250 6   805 398 6   822 158 5   822 158 5   822 158 5
  822 158 5   822 346 5   839 113 8   840 247 12   840 247 12   840 247 12
  840 247 12   840 247 12   840 247 12   840 247 12   840 247 12   840 247 12
  840 247 12   840 247 12   840 393 12   845 224 6   870 102 10   870 158 0
  870 158 0   870 158 0   870 158 0   870 355 0   899 113 8   899 113 8







|







4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
do_execsql_test 5.2.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {667 158 0   671 250 6   759 158 5   768 113 4   777 113 4   777 113 4
  777 113 4   777 252 4   792 247 12   805 250 6   805 250 6   805 250 6
  805 250 6   805 250 6   805 398 6   822 158 5   822 158 5   822 158 5
  822 158 5   822 346 5   839 113 8   840 247 12   840 247 12   840 247 12
  840 247 12   840 247 12   840 247 12   840 247 12   840 247 12   840 247 12
  840 247 12   840 247 12   840 393 12   845 224 6   870 102 10   870 158 0
  870 158 0   870 158 0   870 158 0   870 355 0   899 113 8   899 113 8
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
do_execsql_test 5.2.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {295 1 1   335 1 1   607 1 1   667 1 1   742 1 1   759 1 1   845 1 1
  890 1 1   929 1 1   959 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1
  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1   1366 1 1
  1366 1 1   1383 1 1   1398 1 1   1406 1 1   1421 1 1   1519 1 1   1519 1 1
  1535 1 1   1651 1 1   1669 1 1   1682 1 1   1695 1 1   1804 1 1   1804 1 1
  1804 1 1   1804 1 1   1804 1 1   1897 1 1   1919 1 1   2000 1 1   2048 1 1
  2050 1 1   2050 1 1   2070 1 1   2086 1 1   2108 1 1   2108 1 1   2134 1 1
  2150 1 1   2309 1 1   2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1
  2430 1 1   2690 1 1   2758 1 1   2770 1 1   2776 1 1   2834 1 1   2848 1 1
  2947 1 1   2947 1 1   2947 1 1   2947 1 1   2980 1 1   3082 1 1   3088 1 1
  3088 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3234 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}

do_execsql_test 5.2.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {667 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 355 0
  911 158 7   934 158 7   934 158 7   934 158 7   934 158 7   934 158 7
  934 158 7   934 158 7   934 158 20   934 158 20   934 158 20   934 158 20
  934 158 20   934 158 20   934 158 20   934 158 20   934 158 20   934 158 20
  934 158 20   934 158 20   934 158 20   934 158 26   934 158 26   934 158 26
  934 158 26   934 158 26   934 158 26   934 158 33   959 102 49   959 102 49
  959 102 49   959 102 49   959 102 49   959 102 49   959 102 49   959 102 49







|



















|
|







4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
do_execsql_test 5.2.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {295 1 1   335 1 1   607 1 1   667 1 1   742 1 1   759 1 1   845 1 1
  890 1 1   929 1 1   959 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1
  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1   1366 1 1
  1366 1 1   1383 1 1   1398 1 1   1406 1 1   1421 1 1   1519 1 1   1519 1 1
  1535 1 1   1651 1 1   1669 1 1   1682 1 1   1695 1 1   1804 1 1   1804 1 1
  1804 1 1   1804 1 1   1804 1 1   1897 1 1   1919 1 1   2000 1 1   2048 1 1
  2050 1 1   2050 1 1   2070 1 1   2086 1 1   2108 1 1   2108 1 1   2134 1 1
  2150 1 1   2309 1 1   2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1
  2430 1 1   2690 1 1   2758 1 1   2770 1 1   2776 1 1   2834 1 1   2848 1 1
  2947 1 1   2947 1 1   2947 1 1   2947 1 1   2980 1 1   3082 1 1   3088 1 1
  3088 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3234 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}

do_execsql_test 5.2.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {667 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 355 0
  911 158 7   934 158 7   934 158 7   934 158 7   934 158 7   934 158 7
  934 158 7   934 158 7   934 158 20   934 158 20   934 158 20   934 158 20
  934 158 20   934 158 20   934 158 20   934 158 20   934 158 20   934 158 20
  934 158 20   934 158 20   934 158 20   934 158 26   934 158 26   934 158 26
  934 158 26   934 158 26   934 158 26   934 158 33   959 102 49   959 102 49
  959 102 49   959 102 49   959 102 49   959 102 49   959 102 49   959 102 49
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
  979 102 58   979 102 58   979 102 58   979 102 58   979 102 58}

do_execsql_test 5.2.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {1383 1 1   1421 1 1   1651 1 1   1695 1 1   2050 1 1   2050 1 1   3448 7 2
  3732 7 2   4050 7 2   4120 7 2   4136 7 2   4359 7 2   4359 7 2   4359 7 2
  7129 15 3   7135 15 3   7207 15 3   7441 15 3   7447 15 3   7447 15 3
  7593 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  7840 15 3   8447 28 4   8599 28 4   9206 28 4   9206 28 4   9206 28 4
  9206 28 4   10051 34 5   10165 34 5   11010 34 5   11010 34 5   11010 34 5
  11010 34 5   11010 34 5   11563 74 10   11697 74 10   11752 41 6







|
|







4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
  979 102 58   979 102 58   979 102 58   979 102 58   979 102 58}

do_execsql_test 5.2.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {1383 1 1   1421 1 1   1651 1 1   1695 1 1   2050 1 1   2050 1 1   3448 7 2
  3732 7 2   4050 7 2   4120 7 2   4136 7 2   4359 7 2   4359 7 2   4359 7 2
  7129 15 3   7135 15 3   7207 15 3   7441 15 3   7447 15 3   7447 15 3
  7593 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  7840 15 3   8447 28 4   8599 28 4   9206 28 4   9206 28 4   9206 28 4
  9206 28 4   10051 34 5   10165 34 5   11010 34 5   11010 34 5   11010 34 5
  11010 34 5   11010 34 5   11563 74 10   11697 74 10   11752 41 6
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
  13949 81 11   13949 81 11   13949 81 11}

do_execsql_test 5.2.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
  113 113 1   158 158 1   160 158 1   160 158 2   223 223 1   224 224 1
  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   355 354 1
  355 354 2   355 355 1   399 393 3   399 393 3   399 393 3   399 393 3







|
|







4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
  13949 81 11   13949 81 11   13949 81 11}

do_execsql_test 5.2.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
  113 113 1   158 158 1   160 158 1   160 158 2   223 223 1   224 224 1
  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   355 354 1
  355 354 2   355 355 1   399 393 3   399 393 3   399 393 3   399 393 3
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
  959 959 1   963 963 1}

do_execsql_test 5.2.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19   {} 23 21   {} 25 23
  {} 34 29   {} 35 30   {} 36 31   {} 37 32   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 42 36   {} 43 37   {} 43 37   {} 50 42   {} 56 47   {} 60 51
  {} 61 52   {} 62 53   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 71 61   {} 72 62   {} 78 67   {} 78 67   {} 78 67
  {} 81 68   {} 82 69   {} 83 70   {} 85 72   {} 85 72   {} 89 75   113 2 2
  113 2 2   223 11 9   239 12 10   239 13 11   257 18 16   335 22 20
  335 24 22   355 27 25   355 27 25   504 16 14   504 17 15   705 58 49
  710 26 24   711 57 48   711 59 50   759 63 54   929 84 71   959 88 74
  963 87 73   1185 32 28   1185 32 28   1191 29 26   1191 29 26   1334 51 43
  1334 55 46   1338 52 44   1338 52 44   1584 31 27   1678 77 66   1684 73 63
  1684 73 63   1885 48 40   1889 46 39   1889 46 39   1891 45 38   1891 49 41
  2005 54 45   2523 75 64   2523 76 65}

do_execsql_test 5.2.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
  113 113 1   158 158 0   158 158 1   355 355 0   355 355 1   393 393 1
  393 393 1   399 399 0   399 399 1   480 480 1   480 480 1   618 618 1
  618 618 1   629 629 0   629 629 1   667 667 0   667 667 1   768 768 1
  768 768 1   839 839 1   839 839 1   870 870 1   870 870 1   870 870 2
  938 938 1   938 938 1}

do_execsql_test 5.2.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13   {} 16 14   {} 17 15
  {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20   {} 23 21   {} 24 22
  {} 25 23   {} 26 24   {} 31 27   {} 34 29   {} 35 30   {} 36 31   {} 37 32
  {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37   {} 43 37
  {} 45 38   {} 48 40   {} 49 41   {} 50 42   {} 51 43   {} 54 45   {} 55 46
  {} 56 47   {} 57 48   {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53
  {} 63 54   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59
  {} 70 60   {} 71 61   {} 72 62   {} 75 64   {} 76 65   {} 77 66   {} 78 67
  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
  {} 85 72   {} 87 73   {} 88 74   {} 89 75   113 2 2   113 2 2   355 27 25
  355 27 25   393 29 26   393 29 26   399 32 28   399 32 28   629 46 39
  629 46 39   667 52 44   667 52 44   839 73 63   839 73 63}

do_execsql_test 5.2.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c , b , a 
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  979 256 66   979 257 65   979 295 64   979 309 64   979 330 62   979 335 61
  979 336 60   979 346 59   979 354 59   979 355 57   979 355 57   979 393 55
  979 393 56   979 398 54   979 399 53   979 399 53   979 412 52   979 421 51







|
|




















|
|




















|
|



















|

|







4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
  959 959 1   963 963 1}

do_execsql_test 5.2.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19   {} 23 21   {} 25 23
  {} 34 29   {} 35 30   {} 36 31   {} 37 32   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 42 36   {} 43 37   {} 43 37   {} 50 42   {} 56 47   {} 60 51
  {} 61 52   {} 62 53   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 71 61   {} 72 62   {} 78 67   {} 78 67   {} 78 67
  {} 81 68   {} 82 69   {} 83 70   {} 85 72   {} 85 72   {} 89 75   113 2 2
  113 2 2   223 11 9   239 12 10   239 13 11   257 18 16   335 22 20
  335 24 22   355 27 25   355 27 25   504 16 14   504 17 15   705 58 49
  710 26 24   711 57 48   711 59 50   759 63 54   929 84 71   959 88 74
  963 87 73   1185 32 28   1185 32 28   1191 29 26   1191 29 26   1334 51 43
  1334 55 46   1338 52 44   1338 52 44   1584 31 27   1678 77 66   1684 73 63
  1684 73 63   1885 48 40   1889 46 39   1889 46 39   1891 45 38   1891 49 41
  2005 54 45   2523 75 64   2523 76 65}

do_execsql_test 5.2.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
  113 113 1   158 158 0   158 158 1   355 355 0   355 355 1   393 393 1
  393 393 1   399 399 0   399 399 1   480 480 1   480 480 1   618 618 1
  618 618 1   629 629 0   629 629 1   667 667 0   667 667 1   768 768 1
  768 768 1   839 839 1   839 839 1   870 870 1   870 870 1   870 870 2
  938 938 1   938 938 1}

do_execsql_test 5.2.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13   {} 16 14   {} 17 15
  {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20   {} 23 21   {} 24 22
  {} 25 23   {} 26 24   {} 31 27   {} 34 29   {} 35 30   {} 36 31   {} 37 32
  {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37   {} 43 37
  {} 45 38   {} 48 40   {} 49 41   {} 50 42   {} 51 43   {} 54 45   {} 55 46
  {} 56 47   {} 57 48   {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53
  {} 63 54   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59
  {} 70 60   {} 71 61   {} 72 62   {} 75 64   {} 76 65   {} 77 66   {} 78 67
  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
  {} 85 72   {} 87 73   {} 88 74   {} 89 75   113 2 2   113 2 2   355 27 25
  355 27 25   393 29 26   393 29 26   399 32 28   399 32 28   629 46 39
  629 46 39   667 52 44   667 52 44   839 73 63   839 73 63}

do_execsql_test 5.2.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  979 256 66   979 257 65   979 295 64   979 309 64   979 330 62   979 335 61
  979 336 60   979 346 59   979 354 59   979 355 57   979 355 57   979 393 55
  979 393 56   979 398 54   979 399 53   979 399 53   979 412 52   979 421 51
4185
4186
4187
4188
4189
4190
4191








































































4192





































































































































































































































4193
4194
























4195
4196
4197
4198
4199
4200
4201
  979 870 9   979 870 10   979 870 10   979 899 8   979 911 7}

do_execsql_test 5.2.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3








































































      WINDOW win AS (  ORDER BY c , b , a 





































































































































































































































        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 , 2 , 3
























} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
  979 870 9   979 870 10   979 870 10   979 899 8   979 911 7}

do_execsql_test 5.2.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
  17100 48 48   17104 46 46   17104 47 47   17106 45 45   17126 49 49
  17126 50 50   17126 51 51   17569 42 42   17733 44 44   18176 43 43
  18597 40 40   18597 41 41   18952 37 37   18996 39 39   19395 38 38
  19760 35 35   19788 36 36   20492 32 32   20492 33 33   20498 30 30
  20536 34 34   20833 29 29   20871 28 28   20891 31 31   21180 27 27
  21752 23 23   21830 26 26   22025 21 21   22087 22 22   22087 24 24
  22087 25 25   22278 20 20   22316 19 19   22549 15 15   22557 14 14
  22573 17 17   22573 18 18   22706 10 10   22796 11 11   22796 12 12
  22796 13 13   22796 16 16   23022 4 4   23042 2 2   23042 3 3   23042 9 9
  23155 1 1   23155 5 5   23155 6 6   23155 7 7   23155 8 8}

do_execsql_test 5.2.8.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {963 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 83   979 102 83
  979 102 83   979 102 83   979 102 83   979 102 83   979 113 82}

do_execsql_test 5.2.8.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {22176 1 1   22192 1 1   22196 1 1   22226 1 1   22244 1 1   22256 1 1
  22310 1 1   22316 1 1   22316 1 1   22350 1 1   22378 1 1   22396 1 1
  22444 1 1   22450 1 1   22472 1 1   22484 1 1   22488 1 1   22488 1 1
  22522 1 1   22526 1 1   22526 1 1   22528 1 1   22548 1 1   22712 1 1
  22734 1 1   22756 1 1   22756 1 1   22762 1 1   22762 1 1   22800 1 1
  22800 1 1   22820 1 1   22846 1 1   22860 1 1   22898 1 1   22908 1 1
  22916 1 1   22932 1 1   23022 1 1   23042 1 1   23042 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.2.9.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {667 158 0   870 113 8   870 158 0   870 158 0   870 158 0   870 158 0
  870 355 0   899 113 8   899 113 8   899 113 8   899 113 8   899 113 8
  899 113 8   899 113 8   899 113 15   899 113 15   899 113 15   899 113 15
  899 113 15   899 113 15   899 113 15   899 158 8   963 113 24   979 102 43
  979 102 43   979 102 43   979 102 43   979 102 43   979 102 43   979 102 43
  979 102 43   979 102 43   979 102 43   979 102 48   979 102 48   979 102 48
  979 102 48   979 102 48   979 102 55   979 102 55   979 102 55   979 102 55
  979 102 55   979 102 55   979 102 55   979 102 61   979 102 61   979 102 61
  979 102 61   979 102 61   979 102 61   979 102 74   979 102 74   979 102 74
  979 102 74   979 102 74   979 102 74   979 102 74   979 102 74   979 102 74
  979 102 74   979 102 74   979 102 74   979 102 74   979 102 82   979 102 82
  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 113 24   979 113 24   979 113 24   979 113 24   979 113 24   979 113 24
  979 113 24   979 113 24   979 113 32   979 113 32   979 113 32   979 113 32
  979 113 32   979 113 32   979 113 32   979 113 32   979 113 43}

do_execsql_test 5.2.9.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {1383 84 11   1421 84 11   1651 84 11   1695 84 11   2050 84 11   2050 84 11
  4098 75 10   4158 75 10   4158 75 10   4740 75 10   4884 75 10   4997 75 10
  4997 75 10   4997 75 10   4997 75 10   6532 68 9   6666 68 9   6894 68 9
  6916 68 9   7337 68 9   7337 68 9   7337 68 9   9471 59 8   9487 59 8
  9767 59 8   10095 59 8   10317 59 8   10450 59 8   10450 59 8   10450 59 8
  10450 59 8   10785 51 7   11379 51 7   11714 51 7   11714 51 7   11714 51 7
  11714 51 7   11714 51 7   11714 51 7   12009 40 6   12381 40 6   12676 40 6
  12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6
  12676 40 6   12676 40 6   13418 35 5   13566 35 5   14082 35 5   14195 35 5
  14195 35 5   15040 28 4   15154 28 4   15999 28 4   15999 28 4   15999 28 4
  15999 28 4   15999 28 4   16606 22 3   16758 22 3   17365 22 3   17365 22 3
  17365 22 3   17365 22 3   20135 9 2   20141 9 2   20213 9 2   20447 9 2
  20453 9 2   20453 9 2   20599 9 2   20846 9 2   20846 9 2   20846 9 2
  20846 9 2   20846 9 2   20846 9 2   22244 1 1   22528 1 1   22846 1 1
  22916 1 1   22932 1 1   23155 1 1   23155 1 1   23155 1 1}

do_execsql_test 5.2.10.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {667 158 0   671 250 6   759 158 5   768 113 4   777 113 4   777 113 4
  777 113 4   777 252 4   792 247 12   805 250 6   805 250 6   805 250 6
  805 250 6   805 250 6   805 398 6   822 158 5   822 158 5   822 158 5
  822 158 5   822 346 5   839 113 8   840 247 12   840 247 12   840 247 12
  840 247 12   840 247 12   840 247 12   840 247 12   840 247 12   840 247 12
  840 247 12   840 247 12   840 393 12   845 224 6   870 102 10   870 158 0
  870 158 0   870 158 0   870 158 0   870 355 0   899 113 8   899 113 8
  899 113 8   899 113 8   899 113 8   899 113 8   899 113 8   899 234 8
  911 223 7   929 148 7   934 223 7   934 223 7   934 223 7   934 223 7
  934 223 7   934 223 7   934 239 7   938 102 10   938 102 10   938 102 10
  938 102 10   938 102 10   938 102 10   938 102 10   938 102 10   938 102 10
  938 148 7   938 148 7   938 148 7   938 148 7   938 148 7   938 148 7
  938 160 7   938 208 10   959 224 6   959 224 6   959 224 6   959 224 6
  959 224 6   959 238 6   963 133 8   979 133 8   979 133 8   979 133 8
  979 133 8   979 133 8   979 133 8   979 133 8   979 330 8}

do_execsql_test 5.2.10.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {295 1 1   335 1 1   607 1 1   667 1 1   742 1 1   759 1 1   845 1 1
  890 1 1   929 1 1   959 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1
  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1   1366 1 1
  1366 1 1   1383 1 1   1398 1 1   1406 1 1   1421 1 1   1519 1 1   1519 1 1
  1535 1 1   1651 1 1   1669 1 1   1682 1 1   1695 1 1   1804 1 1   1804 1 1
  1804 1 1   1804 1 1   1804 1 1   1897 1 1   1919 1 1   2000 1 1   2048 1 1
  2050 1 1   2050 1 1   2070 1 1   2086 1 1   2108 1 1   2108 1 1   2134 1 1
  2150 1 1   2309 1 1   2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1
  2430 1 1   2690 1 1   2758 1 1   2770 1 1   2776 1 1   2834 1 1   2848 1 1
  2947 1 1   2947 1 1   2947 1 1   2947 1 1   2980 1 1   3082 1 1   3088 1 1
  3088 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3234 1 1   3481 1 1
  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}

do_execsql_test 5.2.11.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {911 223 7   934 158 26   934 158 26   934 158 26   934 158 26   934 158 26
  934 158 33   934 223 7   934 223 7   934 223 7   934 223 7   934 223 7
  934 223 7   934 223 20   934 223 20   934 223 20   934 223 20   934 223 20
  934 223 20   934 223 20   934 223 20   934 223 20   934 223 20   934 223 20
  934 223 20   934 223 20   934 223 26   934 239 7   959 102 49   959 102 49
  959 102 49   959 102 49   959 102 49   959 102 49   959 102 49   959 102 49
  959 102 49   959 102 49   959 102 57   959 102 57   959 102 57   959 102 57
  959 102 57   959 102 57   959 102 57   959 102 57   959 113 38   959 113 38
  959 113 38   959 113 38   959 113 49   959 158 33   959 158 33   959 158 33
  959 158 33   959 158 33   959 158 33   959 158 38   963 102 58   979 102 49
  979 102 49   979 102 49   979 102 49   979 102 49   979 102 49   979 102 52
  979 102 52   979 102 52   979 102 52   979 102 52   979 102 52   979 102 52
  979 102 55   979 102 55   979 102 55   979 102 55   979 102 55   979 102 55
  979 102 55   979 102 55   979 102 55   979 102 58   979 102 58   979 102 58
  979 102 58   979 102 58   979 102 58   979 102 58   979 102 58}

do_execsql_test 5.2.11.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {1398 1 1   1682 1 1   2000 1 1   2070 1 1   2086 1 1   2309 1 1   2309 1 1
  2309 1 1   5079 9 2   5085 9 2   5157 9 2   5391 9 2   5397 9 2   5397 9 2
  5543 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2
  6397 22 3   6549 22 3   7156 22 3   7156 22 3   7156 22 3   7156 22 3
  8001 28 4   8115 28 4   8960 28 4   8960 28 4   8960 28 4   8960 28 4
  8960 28 4   9702 35 5   9850 35 5   10366 35 5   10479 35 5   10479 35 5
  10774 40 6   11146 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6
  11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6   11563 68 9
  11697 68 9   11776 51 7   11925 68 9   11947 68 9   12368 68 9   12368 68 9
  12368 68 9   12370 51 7   12530 59 8   12546 59 8   12705 51 7   12705 51 7
  12705 51 7   12705 51 7   12705 51 7   12705 51 7   12826 59 8
  13050 75 10   13110 75 10   13110 75 10   13154 59 8   13376 59 8
  13509 59 8   13509 59 8   13509 59 8   13509 59 8   13528 84 11
  13566 84 11   13692 75 10   13796 84 11   13836 75 10   13840 84 11
  13949 75 10   13949 75 10   13949 75 10   13949 75 10   14195 84 11
  14195 84 11}

do_execsql_test 5.2.12.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
  113 113 1   158 158 1   160 158 1   160 158 2   223 223 1   224 224 1
  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   355 354 1
  355 354 2   355 355 1   399 393 3   399 393 3   399 393 3   399 393 3
  399 393 4   480 480 1   480 480 1   572 572 1   574 574 1   618 618 1
  618 618 1   633 629 2   634 627 3   634 627 3   634 627 4   634 629 3
  667 667 1   670 667 2   671 667 2   671 667 2   671 667 3   711 711 1
  711 711 1   716 705 2   726 726 1   730 730 1   762 762 1   768 759 3
  768 762 2   768 762 2   792 790 2   792 790 2   794 786 3   794 786 3
  844 839 4   845 839 4   845 839 4   845 839 4   845 839 4   870 870 1
  870 870 1   870 870 2   934 934 1   938 929 3   938 934 2   938 934 2
  959 959 1   963 963 1}

do_execsql_test 5.2.12.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19   {} 23 21   {} 25 23
  {} 34 29   {} 35 30   {} 36 31   {} 37 32   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 42 36   {} 43 37   {} 43 37   {} 50 42   {} 56 47   {} 60 51
  {} 61 52   {} 62 53   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 71 61   {} 72 62   {} 78 67   {} 78 67   {} 78 67
  {} 81 68   {} 82 69   {} 83 70   {} 85 72   {} 85 72   {} 89 75   113 2 2
  113 2 2   223 11 9   239 12 10   239 13 11   257 18 16   335 22 20
  335 24 22   355 27 25   355 27 25   504 16 14   504 17 15   705 58 49
  710 26 24   711 57 48   711 59 50   759 63 54   929 84 71   959 88 74
  963 87 73   1185 32 28   1185 32 28   1191 29 26   1191 29 26   1334 51 43
  1334 55 46   1338 52 44   1338 52 44   1584 31 27   1678 77 66   1684 73 63
  1684 73 63   1885 48 40   1889 46 39   1889 46 39   1891 45 38   1891 49 41
  2005 54 45   2523 75 64   2523 76 65}

do_execsql_test 5.2.13.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
  113 113 1   158 158 0   158 158 1   355 355 0   355 355 1   393 393 1
  393 393 1   399 399 0   399 399 1   480 480 1   480 480 1   618 618 1
  618 618 1   629 629 0   629 629 1   667 667 0   667 667 1   768 768 1
  768 768 1   839 839 1   839 839 1   870 870 1   870 870 1   870 870 2
  938 938 1   938 938 1}

do_execsql_test 5.2.13.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13   {} 16 14   {} 17 15
  {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20   {} 23 21   {} 24 22
  {} 25 23   {} 26 24   {} 31 27   {} 34 29   {} 35 30   {} 36 31   {} 37 32
  {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37   {} 43 37
  {} 45 38   {} 48 40   {} 49 41   {} 50 42   {} 51 43   {} 54 45   {} 55 46
  {} 56 47   {} 57 48   {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53
  {} 63 54   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59
  {} 70 60   {} 71 61   {} 72 62   {} 75 64   {} 76 65   {} 77 66   {} 78 67
  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
  {} 85 72   {} 87 73   {} 88 74   {} 89 75   113 2 2   113 2 2   355 27 25
  355 27 25   393 29 26   393 29 26   399 32 28   399 32 28   629 46 39
  629 46 39   667 52 44   667 52 44   839 73 63   839 73 63}

do_execsql_test 5.2.14.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  979 256 66   979 257 65   979 295 64   979 309 63   979 330 63   979 335 61
  979 336 60   979 346 59   979 354 58   979 355 56   979 355 58   979 393 55
  979 393 56   979 398 54   979 399 52   979 399 53   979 412 52   979 421 51
  979 430 50   979 443 49   979 480 47   979 480 48   979 572 46   979 574 46
  979 607 44   979 618 42   979 618 43   979 627 41   979 629 40   979 629 40
  979 633 39   979 634 38   979 652 37   979 660 36   979 667 34   979 667 35
  979 670 34   979 671 33   979 683 32   979 705 31   979 711 30   979 716 29
  979 726 28   979 730 27   979 759 26   979 762 25   979 768 23   979 768 24
  979 777 22   979 786 21   979 790 20   979 792 19   979 794 18   979 805 17
  979 822 16   979 839 15   979 839 15   979 840 13   979 844 12   979 845 11
  979 870 8   979 870 9   979 870 10   979 899 8   979 911 7}

do_execsql_test 5.2.14.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268

do_execsql_test 5.3.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}

do_execsql_test 5.3.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1}

do_execsql_test 5.3.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   899 113 9   899 113 9   899 113 9   899 113 9
  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  899 113 16   899 113 16   899 113 16   899 113 16   899 113 16   899 113 16
  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 49
  979 102 49   979 102 49   979 102 49   979 102 49   979 102 49   979 102 49
  979 102 56   979 102 56   979 102 56   979 102 56   979 102 56   979 102 56







|




















|


















|

|







4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949

do_execsql_test 5.3.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}

do_execsql_test 5.3.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1}

do_execsql_test 5.3.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   899 113 9   899 113 9   899 113 9   899 113 9
  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  899 113 16   899 113 16   899 113 16   899 113 16   899 113 16   899 113 16
  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 49
  979 102 49   979 102 49   979 102 49   979 102 49   979 102 49   979 102 49
  979 102 56   979 102 56   979 102 56   979 102 56   979 102 56   979 102 56
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
  979 113 33   979 113 33   979 113 33   979 113 33}

do_execsql_test 5.3.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11
  {} 81 11   {} 81 11   2947 74 10   2947 74 10   2947 74 10   2947 74 10
  2947 74 10   2947 74 10   2947 74 10   5287 65 9   5287 65 9   5287 65 9
  5287 65 9   5287 65 9   5287 65 9   5287 65 9   5287 65 9   5287 65 9
  8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8
  8400 57 8   8400 57 8   9664 46 7   9664 46 7   9664 46 7   9664 46 7
  9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7







|

|







4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
  979 113 33   979 113 33   979 113 33   979 113 33}

do_execsql_test 5.3.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11
  {} 81 11   {} 81 11   2947 74 10   2947 74 10   2947 74 10   2947 74 10
  2947 74 10   2947 74 10   2947 74 10   5287 65 9   5287 65 9   5287 65 9
  5287 65 9   5287 65 9   5287 65 9   5287 65 9   5287 65 9   5287 65 9
  8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8
  8400 57 8   8400 57 8   9664 46 7   9664 46 7   9664 46 7   9664 46 7
  9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
do_execsql_test 5.3.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0







|







4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
do_execsql_test 5.3.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
do_execsql_test 5.3.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1}

do_execsql_test 5.3.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   870 158 0
  870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  870 158 0   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  934 158 8   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  934 158 8   934 158 8   934 158 21   934 158 21   934 158 21   934 158 21
  934 158 21   934 158 21   934 158 27   934 158 27   934 158 27   934 158 27
  934 158 27   934 158 27   934 158 27   959 102 50   959 102 50   959 102 50







|


















|
|







5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
do_execsql_test 5.3.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1}

do_execsql_test 5.3.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   870 158 0
  870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  870 158 0   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  934 158 8   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  934 158 8   934 158 8   934 158 21   934 158 21   934 158 21   934 158 21
  934 158 21   934 158 21   934 158 27   934 158 27   934 158 27   934 158 27
  934 158 27   934 158 27   934 158 27   959 102 50   959 102 50   959 102 50
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
  979 102 47   979 102 47   979 102 47   979 102 47}

do_execsql_test 5.3.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   2050 7 2   2050 7 2
  2050 7 2   2050 7 2   2050 7 2   2050 7 2   2050 7 2   2050 7 2   4359 15 3
  4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  7840 28 4   7840 28 4   7840 28 4   7840 28 4   7840 28 4   7840 28 4
  9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5
  9206 34 5   10028 74 10   10028 74 10   10028 74 10   10028 74 10







|
|







5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
  979 102 47   979 102 47   979 102 47   979 102 47}

do_execsql_test 5.3.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   2050 7 2   2050 7 2
  2050 7 2   2050 7 2   2050 7 2   2050 7 2   2050 7 2   2050 7 2   4359 15 3
  4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  7840 28 4   7840 28 4   7840 28 4   7840 28 4   7840 28 4   7840 28 4
  9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5
  9206 34 5   10028 74 10   10028 74 10   10028 74 10   10028 74 10
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
  12529 46 7   12529 46 7   12529 46 7   12529 46 7   12529 46 7   12529 46 7}

do_execsql_test 5.3.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   158 158 1   160 160 1   160 160 1   223 223 1   224 224 1
  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   354 354 1







|
|







5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
  12529 46 7   12529 46 7   12529 46 7   12529 46 7   12529 46 7   12529 46 7}

do_execsql_test 5.3.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   158 158 1   160 160 1   160 160 1   223 223 1   224 224 1
  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   354 354 1
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
  963 963 1}

do_execsql_test 5.3.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  {} 9 7   {} 10 8   {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19
  {} 23 21   {} 25 23   {} 27 25   {} 27 25   {} 34 29   {} 35 30   {} 36 31
  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  {} 43 37   {} 50 42   {} 56 47   {} 60 51   {} 61 52   {} 62 53   {} 64 55
  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
  {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70
  {} 85 72   {} 85 72   {} 89 75   223 11 9   239 12 10   239 13 11
  257 18 16   335 22 20   335 24 22   504 16 14   504 17 15   671 52 44
  671 52 44   705 58 49   710 26 24   711 57 48   711 59 50   759 63 54
  786 32 28   786 32 28   798 29 26   798 29 26   845 73 63   845 73 63
  929 84 71   959 88 74   963 87 73   1260 46 39   1260 46 39   1334 51 43
  1334 55 46   1584 31 27   1678 77 66   1885 48 40   1891 45 38   1891 49 41
  2005 54 45   2523 75 64   2523 76 65}

do_execsql_test 5.3.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}

do_execsql_test 5.3.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  {} 9 7   {} 10 8   {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13
  {} 16 14   {} 17 15   {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20
  {} 23 21   {} 24 22   {} 25 23   {} 26 24   {} 27 25   {} 27 25   {} 29 26
  {} 29 26   {} 31 27   {} 32 28   {} 32 28   {} 34 29   {} 35 30   {} 36 31
  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  {} 43 37   {} 45 38   {} 46 39   {} 46 39   {} 48 40   {} 49 41   {} 50 42
  {} 51 43   {} 52 44   {} 52 44   {} 54 45   {} 55 46   {} 56 47   {} 57 48
  {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53   {} 63 54   {} 64 55
  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
  {} 72 62   {} 73 63   {} 73 63   {} 75 64   {} 76 65   {} 77 66   {} 78 67
  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
  {} 85 72   {} 87 73   {} 88 74   {} 89 75}

do_execsql_test 5.3.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c , b , a 
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  979 256 66   979 257 65   979 295 64   979 309 64   979 330 62   979 335 61
  979 336 60   979 346 59   979 354 59   979 355 57   979 355 57   979 393 55
  979 393 56   979 398 54   979 399 53   979 399 53   979 412 52   979 421 51







|
|




















|
|



















|
|



















|

|







5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
  963 963 1}

do_execsql_test 5.3.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  {} 9 7   {} 10 8   {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19
  {} 23 21   {} 25 23   {} 27 25   {} 27 25   {} 34 29   {} 35 30   {} 36 31
  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  {} 43 37   {} 50 42   {} 56 47   {} 60 51   {} 61 52   {} 62 53   {} 64 55
  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
  {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70
  {} 85 72   {} 85 72   {} 89 75   223 11 9   239 12 10   239 13 11
  257 18 16   335 22 20   335 24 22   504 16 14   504 17 15   671 52 44
  671 52 44   705 58 49   710 26 24   711 57 48   711 59 50   759 63 54
  786 32 28   786 32 28   798 29 26   798 29 26   845 73 63   845 73 63
  929 84 71   959 88 74   963 87 73   1260 46 39   1260 46 39   1334 51 43
  1334 55 46   1584 31 27   1678 77 66   1885 48 40   1891 45 38   1891 49 41
  2005 54 45   2523 75 64   2523 76 65}

do_execsql_test 5.3.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}

do_execsql_test 5.3.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  {} 9 7   {} 10 8   {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13
  {} 16 14   {} 17 15   {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20
  {} 23 21   {} 24 22   {} 25 23   {} 26 24   {} 27 25   {} 27 25   {} 29 26
  {} 29 26   {} 31 27   {} 32 28   {} 32 28   {} 34 29   {} 35 30   {} 36 31
  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  {} 43 37   {} 45 38   {} 46 39   {} 46 39   {} 48 40   {} 49 41   {} 50 42
  {} 51 43   {} 52 44   {} 52 44   {} 54 45   {} 55 46   {} 56 47   {} 57 48
  {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53   {} 63 54   {} 64 55
  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
  {} 72 62   {} 73 63   {} 73 63   {} 75 64   {} 76 65   {} 77 66   {} 78 67
  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
  {} 85 72   {} 87 73   {} 88 74   {} 89 75}

do_execsql_test 5.3.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  979 256 66   979 257 65   979 295 64   979 309 64   979 330 62   979 335 61
  979 336 60   979 346 59   979 354 59   979 355 57   979 355 57   979 393 55
  979 393 56   979 398 54   979 399 53   979 399 53   979 412 52   979 421 51
4500
4501
4502
4503
4504
4505
4506



































































4507
































































































































































































































4508
4509
























4510
4511
4512
4513
4514
4515
4516
  979 870 9   979 870 10   979 870 10   979 899 8   979 911 7}

do_execsql_test 5.3.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3



































































      WINDOW win AS (  ORDER BY c , b , a 
































































































































































































































        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 , 2 , 3
























} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
  979 870 9   979 870 10   979 870 10   979 899 8   979 911 7}

do_execsql_test 5.3.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
  17100 48 48   17104 46 46   17104 47 47   17106 45 45   17126 49 49
  17126 50 50   17126 51 51   17569 42 42   17733 44 44   18176 43 43
  18597 40 40   18597 41 41   18952 37 37   18996 39 39   19395 38 38
  19760 35 35   19788 36 36   20492 32 32   20492 33 33   20498 30 30
  20536 34 34   20833 29 29   20871 28 28   20891 31 31   21180 27 27
  21752 23 23   21830 26 26   22025 21 21   22087 22 22   22087 24 24
  22087 25 25   22278 20 20   22316 19 19   22549 15 15   22557 14 14
  22573 17 17   22573 18 18   22706 10 10   22796 11 11   22796 12 12
  22796 13 13   22796 16 16   23022 4 4   23042 2 2   23042 3 3   23042 9 9
  23155 1 1   23155 5 5   23155 6 6   23155 7 7   23155 8 8}

do_execsql_test 5.3.8.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}

do_execsql_test 5.3.8.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1}

do_execsql_test 5.3.9.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   870 158 0
  870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  870 158 0   870 158 0   899 113 9   899 113 9   899 113 9   899 113 9
  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  899 113 16   899 113 16   899 113 16   899 113 16   899 113 16   899 113 16
  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 49
  979 102 49   979 102 49   979 102 49   979 102 49   979 102 49   979 102 49
  979 102 56   979 102 56   979 102 56   979 102 56   979 102 56   979 102 56
  979 102 62   979 102 62   979 102 62   979 102 62   979 102 62   979 102 62
  979 102 62   979 102 62   979 102 62   979 102 62   979 102 62   979 102 62
  979 102 62   979 102 75   979 102 75   979 102 75   979 102 75   979 102 75
  979 102 75   979 102 75   979 102 75   979 113 25   979 113 25   979 113 25
  979 113 25   979 113 25   979 113 25   979 113 25   979 113 25   979 113 33
  979 113 33   979 113 33   979 113 33   979 113 33   979 113 33   979 113 33
  979 113 33   979 113 33   979 113 33   979 113 33}

do_execsql_test 5.3.9.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 84 11   {} 84 11   {} 84 11   {} 84 11   {} 84 11   {} 84 11
  2050 75 10   2050 75 10   2050 75 10   2050 75 10   2050 75 10   2050 75 10
  2050 75 10   2050 75 10   2050 75 10   4997 68 9   4997 68 9   4997 68 9
  4997 68 9   4997 68 9   4997 68 9   4997 68 9   7337 59 8   7337 59 8
  7337 59 8   7337 59 8   7337 59 8   7337 59 8   7337 59 8   7337 59 8
  7337 59 8   10450 51 7   10450 51 7   10450 51 7   10450 51 7   10450 51 7
  10450 51 7   10450 51 7   10450 51 7   11714 40 6   11714 40 6   11714 40 6
  11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6
  11714 40 6   11714 40 6   12676 35 5   12676 35 5   12676 35 5   12676 35 5
  12676 35 5   14195 28 4   14195 28 4   14195 28 4   14195 28 4   14195 28 4
  14195 28 4   14195 28 4   15999 22 3   15999 22 3   15999 22 3   15999 22 3
  15999 22 3   15999 22 3   17365 9 2   17365 9 2   17365 9 2   17365 9 2
  17365 9 2   17365 9 2   17365 9 2   17365 9 2   17365 9 2   17365 9 2
  17365 9 2   17365 9 2   17365 9 2   20846 1 1   20846 1 1   20846 1 1
  20846 1 1   20846 1 1   20846 1 1   20846 1 1   20846 1 1}

do_execsql_test 5.3.10.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}

do_execsql_test 5.3.10.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1}

do_execsql_test 5.3.11.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   934 158 27   934 158 27   934 158 27   934 158 27   934 158 27
  934 158 27   934 158 27   934 223 8   934 223 8   934 223 8   934 223 8
  934 223 8   934 223 8   934 223 8   934 223 8   934 223 8   934 223 8
  934 223 8   934 223 8   934 223 8   934 223 21   934 223 21   934 223 21
  934 223 21   934 223 21   934 223 21   959 102 50   959 102 50   959 102 50
  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
  959 102 50   959 102 50   959 113 39   959 113 39   959 113 39   959 113 39
  959 113 39   959 113 39   959 113 39   959 113 39   959 113 39   959 113 39
  959 113 39   959 158 34   959 158 34   959 158 34   959 158 34   959 158 34
  979 102 46   979 102 46   979 102 46   979 102 46   979 102 46   979 102 46
  979 102 46   979 102 47   979 102 47   979 102 47   979 102 47   979 102 47
  979 102 47   979 102 47   979 102 47   979 102 47   979 102 49   979 102 49
  979 102 49   979 102 49   979 102 49   979 102 49}

do_execsql_test 5.3.11.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2
  2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   5790 22 3
  5790 22 3   5790 22 3   5790 22 3   5790 22 3   5790 22 3   7156 28 4
  7156 28 4   7156 28 4   7156 28 4   7156 28 4   7156 28 4   7156 28 4
  8960 35 5   8960 35 5   8960 35 5   8960 35 5   8960 35 5   10028 68 9
  10028 68 9   10028 68 9   10028 68 9   10028 68 9   10028 68 9   10028 68 9
  10396 59 8   10396 59 8   10396 59 8   10396 59 8   10396 59 8   10396 59 8
  10396 59 8   10396 59 8   10396 59 8   10479 40 6   10479 40 6   10479 40 6
  10479 40 6   10479 40 6   10479 40 6   10479 40 6   10479 40 6   10479 40 6
  10479 40 6   10479 40 6   11002 75 10   11002 75 10   11002 75 10
  11002 75 10   11002 75 10   11002 75 10   11002 75 10   11002 75 10
  11002 75 10   11441 51 7   11441 51 7   11441 51 7   11441 51 7
  11441 51 7   11441 51 7   11441 51 7   11441 51 7   12145 84 11
  12145 84 11   12145 84 11   12145 84 11   12145 84 11   12145 84 11}

do_execsql_test 5.3.12.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   158 158 1   160 160 1   160 160 1   223 223 1   224 224 1
  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   354 354 1
  354 354 1   355 355 1   398 393 3   398 393 3   399 393 3   399 398 2
  399 398 2   572 572 1   574 574 1   633 629 2   634 627 3   634 627 3
  634 627 3   634 629 3   667 667 1   670 667 2   671 667 2   671 670 2
  671 670 2   711 711 1   711 711 1   716 705 2   726 726 1   730 730 1
  762 762 1   762 762 1   762 762 1   768 759 3   792 790 2   792 790 2
  794 786 3   794 786 3   844 839 4   845 839 4   845 839 4   845 840 3
  845 840 3   934 934 1   934 934 1   934 934 1   938 929 3   959 959 1
  963 963 1}

do_execsql_test 5.3.12.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  {} 9 7   {} 10 8   {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19
  {} 23 21   {} 25 23   {} 27 25   {} 27 25   {} 34 29   {} 35 30   {} 36 31
  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  {} 43 37   {} 50 42   {} 56 47   {} 60 51   {} 61 52   {} 62 53   {} 64 55
  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
  {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70
  {} 85 72   {} 85 72   {} 89 75   223 11 9   239 12 10   239 13 11
  257 18 16   335 22 20   335 24 22   504 16 14   504 17 15   671 52 44
  671 52 44   705 58 49   710 26 24   711 57 48   711 59 50   759 63 54
  786 32 28   786 32 28   798 29 26   798 29 26   845 73 63   845 73 63
  929 84 71   959 88 74   963 87 73   1260 46 39   1260 46 39   1334 51 43
  1334 55 46   1584 31 27   1678 77 66   1885 48 40   1891 45 38   1891 49 41
  2005 54 45   2523 75 64   2523 76 65}

do_execsql_test 5.3.13.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}

do_execsql_test 5.3.13.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  {} 9 7   {} 10 8   {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13
  {} 16 14   {} 17 15   {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20
  {} 23 21   {} 24 22   {} 25 23   {} 26 24   {} 27 25   {} 27 25   {} 29 26
  {} 29 26   {} 31 27   {} 32 28   {} 32 28   {} 34 29   {} 35 30   {} 36 31
  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  {} 43 37   {} 45 38   {} 46 39   {} 46 39   {} 48 40   {} 49 41   {} 50 42
  {} 51 43   {} 52 44   {} 52 44   {} 54 45   {} 55 46   {} 56 47   {} 57 48
  {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53   {} 63 54   {} 64 55
  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
  {} 72 62   {} 73 63   {} 73 63   {} 75 64   {} 76 65   {} 77 66   {} 78 67
  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
  {} 85 72   {} 87 73   {} 88 74   {} 89 75}

do_execsql_test 5.3.14.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  979 256 66   979 257 65   979 295 64   979 309 63   979 330 63   979 335 61
  979 336 60   979 346 59   979 354 58   979 355 56   979 355 58   979 393 55
  979 393 56   979 398 54   979 399 52   979 399 53   979 412 52   979 421 51
  979 430 50   979 443 49   979 480 47   979 480 48   979 572 46   979 574 46
  979 607 44   979 618 42   979 618 43   979 627 41   979 629 40   979 629 40
  979 633 39   979 634 38   979 652 37   979 660 36   979 667 34   979 667 35
  979 670 34   979 671 33   979 683 32   979 705 31   979 711 30   979 716 29
  979 726 28   979 730 27   979 759 26   979 762 25   979 768 23   979 768 24
  979 777 22   979 786 21   979 790 20   979 792 19   979 794 18   979 805 17
  979 822 16   979 839 15   979 839 15   979 840 13   979 844 12   979 845 11
  979 870 8   979 870 9   979 870 10   979 899 8   979 911 7}

do_execsql_test 5.3.14.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541

do_execsql_test 5.4.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1







|







5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537

do_execsql_test 5.4.1.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585

do_execsql_test 5.4.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}

do_execsql_test 5.4.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {113 113 1   234 234 1   257 257 1   336 336 1   354 354 1   768 768 1
  839 839 1   839 839 1   899 113 10   899 113 10   899 113 10   899 113 10
  899 113 10   899 113 10   899 113 10   899 113 17   899 113 17   899 113 17
  899 113 17   899 113 17   899 113 17   899 113 17   899 899 1   963 113 17
  979 102 34   979 102 45   979 102 45   979 102 45   979 102 45   979 102 45
  979 102 50   979 102 50   979 102 50   979 102 50   979 102 50   979 102 50
  979 102 50   979 102 57   979 102 57   979 102 57   979 102 57   979 102 57







|


















|

|







5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581

do_execsql_test 5.4.1.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}

do_execsql_test 5.4.2.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {113 113 1   234 234 1   257 257 1   336 336 1   354 354 1   768 768 1
  839 839 1   839 839 1   899 113 10   899 113 10   899 113 10   899 113 10
  899 113 10   899 113 10   899 113 10   899 113 17   899 113 17   899 113 17
  899 113 17   899 113 17   899 113 17   899 113 17   899 899 1   963 113 17
  979 102 34   979 102 45   979 102 45   979 102 45   979 102 45   979 102 45
  979 102 50   979 102 50   979 102 50   979 102 50   979 102 50   979 102 50
  979 102 50   979 102 57   979 102 57   979 102 57   979 102 57   979 102 57
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
  979 113 34   979 113 34   979 113 34   979 113 34   979 113 34}

do_execsql_test 5.4.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {{} 81 11   {} 81 11   {} 81 11   {} 81 11   113 81 11   257 81 11
  839 81 11   839 81 11   899 81 11   2947 74 10   2947 74 10   2947 74 10
  3368 74 10   3390 74 10   3618 74 10   3752 74 10   5287 65 9   5287 65 9
  5287 65 9   5287 65 9   5420 65 9   5642 65 9   5970 65 9   6250 65 9
  6266 65 9   8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8
  8400 57 8   8735 57 8   9329 57 8   9664 46 7   9664 46 7   9664 46 7
  9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7







|

|







5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
  979 113 34   979 113 34   979 113 34   979 113 34   979 113 34}

do_execsql_test 5.4.2.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 81 11   {} 81 11   {} 81 11   {} 81 11   113 81 11   257 81 11
  839 81 11   839 81 11   899 81 11   2947 74 10   2947 74 10   2947 74 10
  3368 74 10   3390 74 10   3618 74 10   3752 74 10   5287 65 9   5287 65 9
  5287 65 9   5287 65 9   5420 65 9   5642 65 9   5970 65 9   6250 65 9
  6266 65 9   8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8
  8400 57 8   8735 57 8   9329 57 8   9664 46 7   9664 46 7   9664 46 7
  9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
do_execsql_test 5.4.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1







|







5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
do_execsql_test 5.4.3.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
do_execsql_test 5.4.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}

do_execsql_test 5.4.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {158 158 0   355 355 0   399 399 0   629 629 0   667 667 0   870 158 1
  870 158 1   870 158 1   870 158 1   870 158 1   870 158 1   870 870 0
  911 158 1   934 158 1   934 158 9   934 158 9   934 158 9   934 158 9
  934 158 9   934 158 9   934 158 9   934 158 9   934 158 9   934 158 9
  934 158 9   934 158 9   934 158 9   934 158 22   934 158 22   934 158 22
  934 158 22   934 158 22   934 158 22   934 158 28   934 158 28   934 158 28
  934 158 28   934 158 28   934 158 28   959 102 40   959 102 51   959 102 51







|


















|
|







5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
do_execsql_test 5.4.3.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}

do_execsql_test 5.4.4.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {158 158 0   355 355 0   399 399 0   629 629 0   667 667 0   870 158 1
  870 158 1   870 158 1   870 158 1   870 158 1   870 158 1   870 870 0
  911 158 1   934 158 1   934 158 9   934 158 9   934 158 9   934 158 9
  934 158 9   934 158 9   934 158 9   934 158 9   934 158 9   934 158 9
  934 158 9   934 158 9   934 158 9   934 158 22   934 158 22   934 158 22
  934 158 22   934 158 22   934 158 22   934 158 28   934 158 28   934 158 28
  934 158 28   934 158 28   934 158 28   959 102 40   959 102 51   959 102 51
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
  979 102 48   979 102 48   979 102 48   979 102 48   979 102 51}

do_execsql_test 5.4.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 1 1   355 1 1   399 1 1   629 1 1   667 1 1   2050 7 2
  2050 7 2   2050 7 2   2273 7 2   2289 7 2   2359 7 2   2677 7 2   2961 7 2
  4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  4606 15 3   4752 15 3   4752 15 3   4758 15 3   4992 15 3   5064 15 3
  5070 15 3   7840 28 4   7840 28 4   7840 28 4   7840 28 4   8447 28 4
  8599 28 4   9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5
  10028 74 10   10028 74 10   10028 74 10   10051 34 5   10165 34 5







|
|







5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
  979 102 48   979 102 48   979 102 48   979 102 48   979 102 51}

do_execsql_test 5.4.4.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   355 1 1   399 1 1   629 1 1   667 1 1   2050 7 2
  2050 7 2   2050 7 2   2273 7 2   2289 7 2   2359 7 2   2677 7 2   2961 7 2
  4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  4606 15 3   4752 15 3   4752 15 3   4758 15 3   4992 15 3   5064 15 3
  5070 15 3   7840 28 4   7840 28 4   7840 28 4   7840 28 4   8447 28 4
  8599 28 4   9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5
  10028 74 10   10028 74 10   10028 74 10   10051 34 5   10165 34 5
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
  12529 46 7   12529 46 7   12824 46 7   13196 46 7}

do_execsql_test 5.4.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   160 158 1
  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  346 346 1   355 354 1   355 354 2   355 354 2   399 393 3   399 393 3
  399 393 3   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   574 572 2   574 572 2   607 607 1







|
|







5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
  12529 46 7   12529 46 7   12824 46 7   13196 46 7}

do_execsql_test 5.4.5.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   160 158 1
  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  346 346 1   355 354 1   355 354 2   355 354 2   399 393 3   399 393 3
  399 393 3   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   574 572 2   574 572 2   607 607 1
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
  938 934 2   938 934 2   963 959 2   963 959 2   979 979 1}

do_execsql_test 5.4.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  {} 85 72   113 2 2   113 2 2   133 4 3   223 10 8   223 11 9   239 12 10
  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  309 21 19   335 22 20   335 23 21   335 24 22   355 27 25   355 27 25
  421 35 30   443 37 32   504 16 14   504 17 15   607 42 36   683 56 47
  710 26 24   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1185 32 28
  1185 32 28   1191 29 26   1191 29 26   1334 51 43   1338 52 44   1338 52 44
  1416 57 48   1416 58 49   1584 31 27   1684 73 63   1684 73 63   1889 46 39
  1889 46 39   1891 49 41   1922 87 73   1922 88 74   2005 54 45   2005 55 46
  2518 45 38   2518 48 40   2523 75 64   2523 76 65   2523 77 66}

do_execsql_test 5.4.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1







|
|




















|
|







5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
  938 934 2   938 934 2   963 959 2   963 959 2   979 979 1}

do_execsql_test 5.4.5.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  {} 85 72   113 2 2   113 2 2   133 4 3   223 10 8   223 11 9   239 12 10
  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  309 21 19   335 22 20   335 23 21   335 24 22   355 27 25   355 27 25
  421 35 30   443 37 32   504 16 14   504 17 15   607 42 36   683 56 47
  710 26 24   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1185 32 28
  1185 32 28   1191 29 26   1191 29 26   1334 51 43   1338 52 44   1338 52 44
  1416 57 48   1416 58 49   1584 31 27   1684 73 63   1684 73 63   1889 46 39
  1889 46 39   1891 49 41   1922 87 73   1922 88 74   2005 54 45   2005 55 46
  2518 45 38   2518 48 40   2523 75 64   2523 76 65   2523 77 66}

do_execsql_test 5.4.6.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.4.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   113 2 2   113 2 2
  133 4 3   223 10 8   239 14 12   247 15 13   257 19 17   295 20 18
  309 21 19   335 23 21   355 27 25   355 27 25   393 29 26   393 29 26
  399 32 28   399 32 28   421 35 30   443 37 32   607 42 36   627 45 38
  629 46 39   629 46 39   633 48 40   667 52 44   667 52 44   671 55 46
  683 56 47   705 57 48   711 58 49   759 62 53   777 66 56   805 71 61
  839 73 63   839 73 63   845 77 66   899 81 68   911 82 69   929 83 70
  959 87 73   963 88 74   979 89 75}

do_execsql_test 5.4.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c , b , a 
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  979 346 60   979 354 59   979 355 58   979 355 58   979 393 56   979 393 57
  979 398 55   979 399 54   979 399 54   979 412 53   979 421 52   979 430 51







|
|




















|

|







5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.4.6.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   113 2 2   113 2 2
  133 4 3   223 10 8   239 14 12   247 15 13   257 19 17   295 20 18
  309 21 19   335 23 21   355 27 25   355 27 25   393 29 26   393 29 26
  399 32 28   399 32 28   421 35 30   443 37 32   607 42 36   627 45 38
  629 46 39   629 46 39   633 48 40   667 52 44   667 52 44   671 55 46
  683 56 47   705 57 48   711 58 49   759 62 53   777 66 56   805 71 61
  839 73 63   839 73 63   845 77 66   899 81 68   911 82 69   929 83 70
  959 87 73   963 88 74   979 89 75}

do_execsql_test 5.4.7.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  979 346 60   979 354 59   979 355 58   979 355 58   979 393 56   979 393 57
  979 398 55   979 399 54   979 399 54   979 412 53   979 421 52   979 430 51
4823
4824
4825
4826
4827
4828
4829





































































4830





































































































































































































































4831
4832
























4833
4834
4835
4836
4837
4838
4839
  979 870 11   979 870 11   979 899 9   979 911 8   979 929 7}

do_execsql_test 5.4.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3





































































      WINDOW win AS (  ORDER BY c , b , a 





































































































































































































































        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 , 2 , 3
























} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
  979 870 11   979 870 11   979 899 9   979 911 8   979 929 7}

do_execsql_test 5.4.7.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
  17126 49 49   17126 50 50   17126 51 51   17733 44 44   17733 45 45
  17733 46 46   17733 47 47   17733 48 48   18176 42 42   18176 43 43
  18597 40 40   18597 41 41   18996 39 39   19395 37 37   19395 38 38
  19788 36 36   20181 35 35   20536 34 34   20891 30 30   20891 31 31
  20891 32 32   20891 33 33   21226 28 28   21226 29 29   21535 27 27
  21830 26 26   22087 22 22   22087 23 23   22087 24 24   22087 25 25
  22334 21 21   22573 17 17   22573 18 18   22573 19 19   22573 20 20
  22796 11 11   22796 12 12   22796 13 13   22796 14 14   22796 15 15
  22796 16 16   22929 10 10   23042 9 9   23155 1 1   23155 2 2   23155 3 3
  23155 4 4   23155 5 5   23155 6 6   23155 7 7   23155 8 8}

do_execsql_test 5.4.8.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
  618 618 1   618 618 1   627 627 1   629 629 0   629 629 1   633 633 1
  634 634 1   652 652 1   660 660 1   667 667 0   667 667 1   670 670 1
  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
  730 730 1   759 759 1   762 762 1   768 768 1   768 768 1   777 777 1
  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
  839 839 1   839 839 1   840 840 1   844 844 1   845 845 1   870 870 0
  870 870 1   870 870 1   899 899 1   911 911 1   929 929 1   934 934 1
  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.4.8.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}

do_execsql_test 5.4.9.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {158 158 0   355 355 0   399 399 0   629 629 0   667 667 0   870 113 1
  870 158 1   870 158 1   870 158 1   870 158 1   870 158 1   870 158 1
  870 158 1   870 870 0   899 113 10   899 113 10   899 113 10   899 113 10
  899 113 10   899 113 10   899 113 10   899 113 17   899 113 17   899 113 17
  899 113 17   899 113 17   899 113 17   899 113 17   899 158 1   963 113 17
  979 102 34   979 102 45   979 102 45   979 102 45   979 102 45   979 102 45
  979 102 50   979 102 50   979 102 50   979 102 50   979 102 50   979 102 50
  979 102 50   979 102 57   979 102 57   979 102 57   979 102 57   979 102 57
  979 102 57   979 102 63   979 102 63   979 102 63   979 102 63   979 102 63
  979 102 63   979 102 63   979 102 63   979 102 63   979 102 63   979 102 63
  979 102 63   979 102 63   979 102 76   979 102 76   979 102 76   979 102 76
  979 102 76   979 102 76   979 102 76   979 102 76   979 113 17   979 113 26
  979 113 26   979 113 26   979 113 26   979 113 26   979 113 26   979 113 26
  979 113 26   979 113 34   979 113 34   979 113 34   979 113 34   979 113 34
  979 113 34   979 113 34   979 113 34   979 113 34   979 113 34}

do_execsql_test 5.4.9.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 84 11   {} 84 11   355 84 11   399 84 11   629 84 11   667 84 11
  2050 75 10   2050 75 10   2050 75 10   2050 75 10   2163 75 10   2307 75 10
  2889 75 10   2889 75 10   2949 75 10   4997 68 9   4997 68 9   4997 68 9
  5418 68 9   5440 68 9   5668 68 9   5802 68 9   7337 59 8   7337 59 8
  7337 59 8   7337 59 8   7470 59 8   7692 59 8   8020 59 8   8300 59 8
  8316 59 8   10450 51 7   10450 51 7   10450 51 7   10450 51 7   10450 51 7
  10450 51 7   10785 51 7   11379 51 7   11714 40 6   11714 40 6   11714 40 6
  11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6
  12009 40 6   12381 40 6   12676 35 5   12676 35 5   12789 35 5   13305 35 5
  13453 35 5   14195 28 4   14195 28 4   14195 28 4   14195 28 4   14195 28 4
  15040 28 4   15154 28 4   15999 22 3   15999 22 3   15999 22 3   15999 22 3
  16606 22 3   16758 22 3   17365 9 2   17365 9 2   17365 9 2   17365 9 2
  17365 9 2   17365 9 2   17612 9 2   17758 9 2   17758 9 2   17764 9 2
  17998 9 2   18070 9 2   18076 9 2   20846 1 1   20846 1 1   20846 1 1
  21069 1 1   21085 1 1   21155 1 1   21473 1 1   21757 1 1}

do_execsql_test 5.4.10.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
  618 618 1   618 618 1   627 627 1   629 629 0   629 629 1   633 633 1
  634 634 1   652 652 1   660 660 1   667 667 0   667 667 1   670 670 1
  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
  730 730 1   759 759 1   762 762 1   768 768 1   768 768 1   777 777 1
  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
  839 839 1   839 839 1   840 840 1   844 844 1   845 845 1   870 870 0
  870 870 1   870 870 1   899 899 1   911 911 1   929 929 1   934 934 1
  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.4.10.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  PARTITION BY coalesce(a, '') 
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}

do_execsql_test 5.4.11.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {223 223 1   239 239 1   309 309 1   572 572 1   627 627 1   870 870 1
  911 911 1   934 158 22   934 158 28   934 158 28   934 158 28   934 158 28
  934 158 28   934 158 28   934 223 9   934 223 9   934 223 9   934 223 9
  934 223 9   934 223 9   934 223 9   934 223 9   934 223 9   934 223 9
  934 223 9   934 223 9   934 223 9   934 223 22   934 223 22   934 223 22
  934 223 22   934 223 22   934 934 1   959 102 40   959 102 51   959 102 51
  959 102 51   959 102 51   959 102 51   959 102 51   959 102 51   959 102 51
  959 102 51   959 102 51   959 102 51   959 102 51   959 102 51   959 102 51
  959 102 51   959 113 35   959 113 40   959 113 40   959 113 40   959 113 40
  959 113 40   959 113 40   959 113 40   959 113 40   959 113 40   959 113 40
  959 158 28   959 158 35   959 158 35   959 158 35   959 158 35   963 102 51
  979 102 47   979 102 47   979 102 47   979 102 47   979 102 47   979 102 47
  979 102 47   979 102 48   979 102 48   979 102 48   979 102 48   979 102 48
  979 102 48   979 102 48   979 102 48   979 102 48   979 102 49   979 102 49
  979 102 49   979 102 49   979 102 49   979 102 49   979 102 51}

do_execsql_test 5.4.11.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 1 1   {} 1 1   223 1 1   239 1 1   309 1 1   627 1 1   911 1 1
  2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2556 9 2
  2702 9 2   2702 9 2   2708 9 2   2942 9 2   3014 9 2   3020 9 2   5790 22 3
  5790 22 3   5790 22 3   5790 22 3   6397 22 3   6549 22 3   7156 28 4
  7156 28 4   7156 28 4   7156 28 4   7156 28 4   8001 28 4   8115 28 4
  8960 35 5   8960 35 5   9073 35 5   9589 35 5   9737 35 5   10028 68 9
  10028 68 9   10028 68 9   10396 59 8   10396 59 8   10396 59 8   10396 59 8
  10449 68 9   10471 68 9   10479 40 6   10479 40 6   10479 40 6   10479 40 6
  10479 40 6   10479 40 6   10479 40 6   10479 40 6   10479 40 6   10529 59 8
  10699 68 9   10751 59 8   10774 40 6   10833 68 9   11002 75 10
  11002 75 10   11002 75 10   11002 75 10   11079 59 8   11115 75 10
  11146 40 6   11259 75 10   11359 59 8   11375 59 8   11441 51 7
  11441 51 7   11441 51 7   11441 51 7   11441 51 7   11441 51 7   11776 51 7
  11841 75 10   11841 75 10   11901 75 10   12145 84 11   12145 84 11
  12370 51 7   12500 84 11   12544 84 11   12774 84 11   12812 84 11}

do_execsql_test 5.4.12.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   160 158 1
  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  346 346 1   355 354 1   355 354 2   355 354 2   399 393 3   399 393 3
  399 393 3   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   574 572 2   574 572 2   607 607 1
  618 618 1   618 618 1   634 627 3   634 627 4   634 627 4   634 627 4
  634 629 3   652 652 1   667 660 2   671 667 2   671 667 3   671 667 3
  671 667 3   683 683 1   711 705 2   716 705 3   716 711 2   730 726 2
  730 726 2   762 759 2   768 759 4   768 762 2   768 762 2   777 777 1
  792 786 3   794 786 4   794 786 4   794 790 3   805 805 1   822 822 1
  845 839 4   845 839 4   845 839 5   845 839 5   845 839 5   870 870 0
  870 870 1   870 870 1   899 899 1   911 911 1   934 929 2   938 929 4
  938 934 2   938 934 2   963 959 2   963 959 2   979 979 1}

do_execsql_test 5.4.12.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  {} 85 72   113 2 2   113 2 2   133 4 3   223 10 8   223 11 9   239 12 10
  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  309 21 19   335 22 20   335 23 21   335 24 22   355 27 25   355 27 25
  421 35 30   443 37 32   504 16 14   504 17 15   607 42 36   683 56 47
  710 26 24   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1185 32 28
  1185 32 28   1191 29 26   1191 29 26   1334 51 43   1338 52 44   1338 52 44
  1416 57 48   1416 58 49   1584 31 27   1684 73 63   1684 73 63   1889 46 39
  1889 46 39   1891 49 41   1922 87 73   1922 88 74   2005 54 45   2005 55 46
  2518 45 38   2518 48 40   2523 75 64   2523 76 65   2523 77 66}

do_execsql_test 5.4.13.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
  618 618 1   618 618 1   627 627 1   629 629 0   629 629 1   633 633 1
  634 634 1   652 652 1   660 660 1   667 667 0   667 667 1   670 670 1
  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
  730 730 1   759 759 1   762 762 1   768 768 1   768 768 1   777 777 1
  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
  839 839 1   839 839 1   840 840 1   844 844 1   845 845 1   870 870 0
  870 870 1   870 870 1   899 899 1   911 911 1   929 929 1   934 934 1
  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}

do_execsql_test 5.4.13.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   113 2 2   113 2 2
  133 4 3   223 10 8   239 14 12   247 15 13   257 19 17   295 20 18
  309 21 19   335 23 21   355 27 25   355 27 25   393 29 26   393 29 26
  399 32 28   399 32 28   421 35 30   443 37 32   607 42 36   627 45 38
  629 46 39   629 46 39   633 48 40   667 52 44   667 52 44   671 55 46
  683 56 47   705 57 48   711 58 49   759 62 53   777 66 56   805 71 61
  839 73 63   839 73 63   845 77 66   899 81 68   911 82 69   929 83 70
  959 87 73   963 88 74   979 89 75}

do_execsql_test 5.4.14.1 {
  SELECT max(c) OVER win,
             min(c) OVER win,
             count(a) OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  979 346 60   979 354 59   979 355 57   979 355 58   979 393 56   979 393 57
  979 398 55   979 399 53   979 399 54   979 412 53   979 421 52   979 430 51
  979 443 50   979 480 48   979 480 49   979 572 47   979 574 46   979 607 45
  979 618 43   979 618 44   979 627 42   979 629 40   979 629 41   979 633 40
  979 634 39   979 652 38   979 660 37   979 667 35   979 667 36   979 670 35
  979 671 34   979 683 33   979 705 32   979 711 31   979 716 30   979 726 29
  979 730 28   979 759 27   979 762 26   979 768 24   979 768 25   979 777 23
  979 786 22   979 790 21   979 792 20   979 794 19   979 805 18   979 822 17
  979 839 15   979 839 16   979 840 14   979 844 13   979 845 12   979 870 9
  979 870 10   979 870 11   979 899 9   979 911 8   979 929 7}

do_execsql_test 5.4.14.2 {
  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
             rank() OVER win,
             dense_rank() OVER win
      FROM t3
      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
  INSERT INTO t2 VALUES('A', NULL);
  INSERT INTO t2 VALUES('B', NULL);
  INSERT INTO t2 VALUES('C', 1);
} {}

do_execsql_test 6.1 {
  SELECT group_concat(a, '.') OVER (
    ORDER BY b  RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  )
  FROM t2
} {A.B   A.B   {}}

do_execsql_test 6.2 {
  SELECT group_concat(a, '.') OVER (
    ORDER BY b DESC  RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  )
  FROM t2
} {{}   A.B   A.B}

finish_test







|






|





6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
  INSERT INTO t2 VALUES('A', NULL);
  INSERT INTO t2 VALUES('B', NULL);
  INSERT INTO t2 VALUES('C', 1);
} {}

do_execsql_test 6.1 {
  SELECT group_concat(a, '.') OVER (
    ORDER BY b NULLS FIRST RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  )
  FROM t2
} {A.B   A.B   {}}

do_execsql_test 6.2 {
  SELECT group_concat(a, '.') OVER (
    ORDER BY b DESC NULLS LAST RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  )
  FROM t2
} {{}   A.B   A.B}

finish_test

Changes to tool/mkkeywordhash.c.

206
207
208
209
210
211
212

213
214
215
216
217
218
219
  { "EXCEPT",           "TK_EXCEPT",       COMPOUND               },
  { "EXCLUSIVE",        "TK_EXCLUSIVE",    ALWAYS                 },
  { "EXCLUDE",          "TK_EXCLUDE",      WINDOWFUNC             },
  { "EXISTS",           "TK_EXISTS",       ALWAYS                 },
  { "EXPLAIN",          "TK_EXPLAIN",      EXPLAIN                },
  { "FAIL",             "TK_FAIL",         CONFLICT|TRIGGER       },
  { "FILTER",           "TK_FILTER",       WINDOWFUNC             },

  { "FOLLOWING",        "TK_FOLLOWING",    WINDOWFUNC             },
  { "FOR",              "TK_FOR",          TRIGGER                },
  { "FOREIGN",          "TK_FOREIGN",      FKEY                   },
  { "FROM",             "TK_FROM",         ALWAYS                 },
  { "FULL",             "TK_JOIN_KW",      ALWAYS                 },
  { "GLOB",             "TK_LIKE_KW",      ALWAYS                 },
  { "GROUP",            "TK_GROUP",        ALWAYS                 },







>







206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
  { "EXCEPT",           "TK_EXCEPT",       COMPOUND               },
  { "EXCLUSIVE",        "TK_EXCLUSIVE",    ALWAYS                 },
  { "EXCLUDE",          "TK_EXCLUDE",      WINDOWFUNC             },
  { "EXISTS",           "TK_EXISTS",       ALWAYS                 },
  { "EXPLAIN",          "TK_EXPLAIN",      EXPLAIN                },
  { "FAIL",             "TK_FAIL",         CONFLICT|TRIGGER       },
  { "FILTER",           "TK_FILTER",       WINDOWFUNC             },
  { "FIRST",            "TK_FIRST",        ALWAYS                 },
  { "FOLLOWING",        "TK_FOLLOWING",    WINDOWFUNC             },
  { "FOR",              "TK_FOR",          TRIGGER                },
  { "FOREIGN",          "TK_FOREIGN",      FKEY                   },
  { "FROM",             "TK_FROM",         ALWAYS                 },
  { "FULL",             "TK_JOIN_KW",      ALWAYS                 },
  { "GLOB",             "TK_LIKE_KW",      ALWAYS                 },
  { "GROUP",            "TK_GROUP",        ALWAYS                 },
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
  { "INSTEAD",          "TK_INSTEAD",      TRIGGER                },
  { "INTERSECT",        "TK_INTERSECT",    COMPOUND               },
  { "INTO",             "TK_INTO",         ALWAYS                 },
  { "IS",               "TK_IS",           ALWAYS                 },
  { "ISNULL",           "TK_ISNULL",       ALWAYS                 },
  { "JOIN",             "TK_JOIN",         ALWAYS                 },
  { "KEY",              "TK_KEY",          ALWAYS                 },

  { "LEFT",             "TK_JOIN_KW",      ALWAYS                 },
  { "LIKE",             "TK_LIKE_KW",      ALWAYS                 },
  { "LIMIT",            "TK_LIMIT",        ALWAYS                 },
  { "MATCH",            "TK_MATCH",        ALWAYS                 },
  { "NATURAL",          "TK_JOIN_KW",      ALWAYS                 },
  { "NO",               "TK_NO",           FKEY|WINDOWFUNC        },
  { "NOT",              "TK_NOT",          ALWAYS                 },
  { "NOTHING",          "TK_NOTHING",      UPSERT                 },
  { "NOTNULL",          "TK_NOTNULL",      ALWAYS                 },
  { "NULL",             "TK_NULL",         ALWAYS                 },

  { "OF",               "TK_OF",           ALWAYS                 },
  { "OFFSET",           "TK_OFFSET",       ALWAYS                 },
  { "ON",               "TK_ON",           ALWAYS                 },
  { "OR",               "TK_OR",           ALWAYS                 },
  { "ORDER",            "TK_ORDER",        ALWAYS                 },
  { "OTHERS",           "TK_OTHERS",       WINDOWFUNC             },
  { "OUTER",            "TK_JOIN_KW",      ALWAYS                 },







>










>







232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
  { "INSTEAD",          "TK_INSTEAD",      TRIGGER                },
  { "INTERSECT",        "TK_INTERSECT",    COMPOUND               },
  { "INTO",             "TK_INTO",         ALWAYS                 },
  { "IS",               "TK_IS",           ALWAYS                 },
  { "ISNULL",           "TK_ISNULL",       ALWAYS                 },
  { "JOIN",             "TK_JOIN",         ALWAYS                 },
  { "KEY",              "TK_KEY",          ALWAYS                 },
  { "LAST",             "TK_LAST",         ALWAYS                 },
  { "LEFT",             "TK_JOIN_KW",      ALWAYS                 },
  { "LIKE",             "TK_LIKE_KW",      ALWAYS                 },
  { "LIMIT",            "TK_LIMIT",        ALWAYS                 },
  { "MATCH",            "TK_MATCH",        ALWAYS                 },
  { "NATURAL",          "TK_JOIN_KW",      ALWAYS                 },
  { "NO",               "TK_NO",           FKEY|WINDOWFUNC        },
  { "NOT",              "TK_NOT",          ALWAYS                 },
  { "NOTHING",          "TK_NOTHING",      UPSERT                 },
  { "NOTNULL",          "TK_NOTNULL",      ALWAYS                 },
  { "NULL",             "TK_NULL",         ALWAYS                 },
  { "NULLS",            "TK_NULLS",        ALWAYS                 },
  { "OF",               "TK_OF",           ALWAYS                 },
  { "OFFSET",           "TK_OFFSET",       ALWAYS                 },
  { "ON",               "TK_ON",           ALWAYS                 },
  { "OR",               "TK_OR",           ALWAYS                 },
  { "ORDER",            "TK_ORDER",        ALWAYS                 },
  { "OTHERS",           "TK_OTHERS",       WINDOWFUNC             },
  { "OUTER",            "TK_JOIN_KW",      ALWAYS                 },