/ Changes On Branch nulls-last
Login

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

Changes In Branch nulls-last Excluding Merge-Ins

This is equivalent to a diff from 279ac7fd to ad816d01

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)
10:05
If a TEMP TRIGGER references an auxiliary schema, and that auxiliary schema is detached, move the trigger to reference the TEMP schema before completing the detach, so that the trigger does not hold a dangling schema pointer. Ticket [ac8dd4a32ba4322f] (check-in: 069c2f4c 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)
14:57
Tweak the shell tool ".recover" command so that it can recover rows that consist of a rowid and no fields. (check-in: 279ac7fd user: dan tags: trunk)
14:18
Improved detection of number of column mismatch for vector assignment in UPDATE statements. Ticket [78acc9d40f0786e8] (check-in: bd4bda73 user: drh tags: trunk)
2019-08-23
20:33
Move some things in parse.y so that TK_COLUMN and TK_AGG_COLUMN are assigned the same values as they are on trunk for a very small speedup. (check-in: d26fdfa3 user: dan tags: nulls-last)

Changes to ext/expert/expert1.test.

   130    130   } {
   131    131     SELECT a FROM t1 WHERE a=? ORDER BY b;
   132    132   } {
   133    133     CREATE INDEX t1_idx_000123a7 ON t1(a, b);
   134    134     SEARCH TABLE t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
   135    135   }
   136    136   
          137  +if 0 {
   137    138   do_setup_rec_test $tn.6 {
   138    139     CREATE TABLE t1(a, b, c);
   139    140   } {
   140    141     SELECT min(a) FROM t1
   141    142   } {
   142    143     CREATE INDEX t1_idx_00000061 ON t1(a);
   143    144     SEARCH TABLE t1 USING COVERING INDEX t1_idx_00000061
          145  +}
   144    146   }
   145    147   
   146    148   do_setup_rec_test $tn.7 {
   147    149     CREATE TABLE t1(a, b, c);
   148    150   } {
   149    151     SELECT * FROM t1 ORDER BY a, b, c;
   150    152   } {

Changes to src/build.c.

  1439   1439         Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
  1440   1440         sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
  1441   1441       }
  1442   1442       pTab->iPKey = iCol;
  1443   1443       pTab->keyConf = (u8)onError;
  1444   1444       assert( autoInc==0 || autoInc==1 );
  1445   1445       pTab->tabFlags |= autoInc*TF_Autoincrement;
  1446         -    if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
         1446  +    if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
  1447   1447     }else if( autoInc ){
  1448   1448   #ifndef SQLITE_OMIT_AUTOINCREMENT
  1449   1449       sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
  1450   1450          "INTEGER PRIMARY KEY");
  1451   1451   #endif
  1452   1452     }else{
  1453   1453       sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
................................................................................
  1890   1890       sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
  1891   1891       pList = sqlite3ExprListAppend(pParse, 0, 
  1892   1892                     sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
  1893   1893       if( pList==0 ) return;
  1894   1894       if( IN_RENAME_OBJECT ){
  1895   1895         sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
  1896   1896       }
  1897         -    pList->a[0].sortOrder = pParse->iPkSortOrder;
         1897  +    pList->a[0].sortFlags = pParse->iPkSortOrder;
  1898   1898       assert( pParse->pNewTable==pTab );
  1899   1899       pTab->iPKey = -1;
  1900   1900       sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
  1901   1901                          SQLITE_IDXTYPE_PRIMARYKEY);
  1902   1902       if( db->mallocFailed || pParse->nErr ) return;
  1903   1903       pPk = sqlite3PrimaryKeyIndex(pTab);
  1904   1904       assert( pPk->nKeyCol==1 );
................................................................................
  3148   3148       p->aSortOrder = (u8*)pExtra;
  3149   3149       p->nColumn = nCol;
  3150   3150       p->nKeyCol = nCol - 1;
  3151   3151       *ppExtra = ((char*)p) + nByte;
  3152   3152     }
  3153   3153     return p;
  3154   3154   }
         3155  +
         3156  +/*
         3157  +** If expression list pList contains an expression that was parsed with
         3158  +** an explicit "NULLS FIRST" or "NULLS LAST" clause, leave an error in
         3159  +** pParse and return non-zero. Otherwise, return zero.
         3160  +*/
         3161  +int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
         3162  +  if( pList ){
         3163  +    int i;
         3164  +    for(i=0; i<pList->nExpr; i++){
         3165  +      if( pList->a[i].bNulls ){
         3166  +        u8 sf = pList->a[i].sortFlags;
         3167  +        sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s", 
         3168  +            (sf==0 || sf==3) ? "FIRST" : "LAST"
         3169  +        );
         3170  +        return 1;
         3171  +      }
         3172  +    }
         3173  +  }
         3174  +  return 0;
         3175  +}
  3155   3176   
  3156   3177   /*
  3157   3178   ** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
  3158   3179   ** and pTblList is the name of the table that is to be indexed.  Both will 
  3159   3180   ** be NULL for a primary key or an index that is created to satisfy a
  3160   3181   ** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
  3161   3182   ** as the table to be indexed.  pParse->pNewTable is a table that is
................................................................................
  3199   3220       goto exit_create_index;
  3200   3221     }
  3201   3222     if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
  3202   3223       goto exit_create_index;
  3203   3224     }
  3204   3225     if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
  3205   3226       goto exit_create_index;
         3227  +  }
         3228  +  if( sqlite3HasExplicitNulls(pParse, pList) ){
         3229  +    goto exit_create_index;
  3206   3230     }
  3207   3231   
  3208   3232     /*
  3209   3233     ** Find the table that is to be indexed.  Return early if not found.
  3210   3234     */
  3211   3235     if( pTblName!=0 ){
  3212   3236   
................................................................................
  3364   3388       Column *pCol = &pTab->aCol[pTab->nCol-1];
  3365   3389       pCol->colFlags |= COLFLAG_UNIQUE;
  3366   3390       sqlite3TokenInit(&prevCol, pCol->zName);
  3367   3391       pList = sqlite3ExprListAppend(pParse, 0,
  3368   3392                 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
  3369   3393       if( pList==0 ) goto exit_create_index;
  3370   3394       assert( pList->nExpr==1 );
  3371         -    sqlite3ExprListSetSortOrder(pList, sortOrder);
         3395  +    sqlite3ExprListSetSortOrder(pList, sortOrder, SQLITE_SO_UNDEFINED);
  3372   3396     }else{
  3373   3397       sqlite3ExprListCheckLength(pParse, pList, "index");
  3374   3398       if( pParse->nErr ) goto exit_create_index;
  3375   3399     }
  3376   3400   
  3377   3401     /* Figure out how many bytes of space are required to store explicitly
  3378   3402     ** specified collation sequence names.
................................................................................
  3482   3506         zColl = pTab->aCol[j].zColl;
  3483   3507       }
  3484   3508       if( !zColl ) zColl = sqlite3StrBINARY;
  3485   3509       if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
  3486   3510         goto exit_create_index;
  3487   3511       }
  3488   3512       pIndex->azColl[i] = zColl;
  3489         -    requestedSortOrder = pListItem->sortOrder & sortOrderMask;
         3513  +    requestedSortOrder = pListItem->sortFlags & sortOrderMask;
  3490   3514       pIndex->aSortOrder[i] = (u8)requestedSortOrder;
  3491   3515     }
  3492   3516   
  3493   3517     /* Append the table key to the end of the index.  For WITHOUT ROWID
  3494   3518     ** tables (when pPk!=0) this will be the declared PRIMARY KEY.  For
  3495   3519     ** normal tables (when pPk==0) this will be the rowid.
  3496   3520     */
................................................................................
  4700   4724     }
  4701   4725     if( pKey ){
  4702   4726       assert( sqlite3KeyInfoIsWriteable(pKey) );
  4703   4727       for(i=0; i<nCol; i++){
  4704   4728         const char *zColl = pIdx->azColl[i];
  4705   4729         pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
  4706   4730                           sqlite3LocateCollSeq(pParse, zColl);
  4707         -      pKey->aSortOrder[i] = pIdx->aSortOrder[i];
         4731  +      pKey->aSortFlags[i] = pIdx->aSortOrder[i];
         4732  +      assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) );
  4708   4733       }
  4709   4734       if( pParse->nErr ){
  4710   4735         assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ );
  4711   4736         if( pIdx->bNoQuery==0 ){
  4712   4737           /* Deactivate the index because it contains an unknown collating
  4713   4738           ** sequence.  The only way to reactive the index is to reload the
  4714   4739           ** schema.  Adding the missing collating sequence later does not

Changes to src/expr.c.

  1407   1407           assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 );
  1408   1408           assert( pPriorSelectCol==pItem[-1].pExpr->pLeft );
  1409   1409           pNewExpr->pLeft = pPriorSelectCol;
  1410   1410         }
  1411   1411       }
  1412   1412       pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
  1413   1413       pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
  1414         -    pItem->sortOrder = pOldItem->sortOrder;
         1414  +    pItem->sortFlags = pOldItem->sortFlags;
  1415   1415       pItem->done = 0;
         1416  +    pItem->bNulls = pOldItem->bNulls;
  1416   1417       pItem->bSpanIsTab = pOldItem->bSpanIsTab;
  1417   1418       pItem->bSorterRef = pOldItem->bSorterRef;
  1418   1419       pItem->u = pOldItem->u;
  1419   1420     }
  1420   1421     return pNew;
  1421   1422   }
  1422   1423   
................................................................................
  1664   1665     sqlite3IdListDelete(db, pColumns);
  1665   1666     return pList;
  1666   1667   }
  1667   1668   
  1668   1669   /*
  1669   1670   ** Set the sort order for the last element on the given ExprList.
  1670   1671   */
  1671         -void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder){
         1672  +void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder, int eNulls){
         1673  +  struct ExprList_item *pItem;
  1672   1674     if( p==0 ) return;
  1673         -  assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC>=0 && SQLITE_SO_DESC>0 );
  1674   1675     assert( p->nExpr>0 );
  1675         -  if( iSortOrder<0 ){
  1676         -    assert( p->a[p->nExpr-1].sortOrder==SQLITE_SO_ASC );
  1677         -    return;
         1676  +
         1677  +  assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC==0 && SQLITE_SO_DESC>0 );
         1678  +  assert( iSortOrder==SQLITE_SO_UNDEFINED 
         1679  +       || iSortOrder==SQLITE_SO_ASC 
         1680  +       || iSortOrder==SQLITE_SO_DESC 
         1681  +  );
         1682  +  assert( eNulls==SQLITE_SO_UNDEFINED 
         1683  +       || eNulls==SQLITE_SO_ASC 
         1684  +       || eNulls==SQLITE_SO_DESC 
         1685  +  );
         1686  +
         1687  +  pItem = &p->a[p->nExpr-1];
         1688  +  assert( pItem->bNulls==0 );
         1689  +  if( iSortOrder==SQLITE_SO_UNDEFINED ){
         1690  +    iSortOrder = SQLITE_SO_ASC;
  1678   1691     }
  1679         -  p->a[p->nExpr-1].sortOrder = (u8)iSortOrder;
         1692  +  pItem->sortFlags = (u8)iSortOrder;
         1693  +
         1694  +  if( eNulls!=SQLITE_SO_UNDEFINED ){
         1695  +    pItem->bNulls = 1;
         1696  +    if( iSortOrder!=eNulls ){
         1697  +      pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
         1698  +    }
         1699  +  }
  1680   1700   }
  1681   1701   
  1682   1702   /*
  1683   1703   ** Set the ExprList.a[].zName element of the most recently added item
  1684   1704   ** on the expression list.
  1685   1705   **
  1686   1706   ** pList might be NULL following an OOM error.  But pName should never be
................................................................................
  4933   4953     int i;
  4934   4954     if( pA==0 && pB==0 ) return 0;
  4935   4955     if( pA==0 || pB==0 ) return 1;
  4936   4956     if( pA->nExpr!=pB->nExpr ) return 1;
  4937   4957     for(i=0; i<pA->nExpr; i++){
  4938   4958       Expr *pExprA = pA->a[i].pExpr;
  4939   4959       Expr *pExprB = pB->a[i].pExpr;
  4940         -    if( pA->a[i].sortOrder!=pB->a[i].sortOrder ) return 1;
         4960  +    if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
  4941   4961       if( sqlite3ExprCompare(0, pExprA, pExprB, iTab) ) return 1;
  4942   4962     }
  4943   4963     return 0;
  4944   4964   }
  4945   4965   
  4946   4966   /*
  4947   4967   ** Like sqlite3ExprCompare() except COLLATE operators at the top-level

Changes to src/insert.c.

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

Changes to src/parse.y.

   207    207   %fallback ID
   208    208     ABORT ACTION AFTER ANALYZE ASC ATTACH BEFORE BEGIN BY CASCADE CAST COLUMNKW
   209    209     CONFLICT DATABASE DEFERRED DESC DETACH DO
   210    210     EACH END EXCLUSIVE EXPLAIN FAIL FOR
   211    211     IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH NO PLAN
   212    212     QUERY KEY OF OFFSET PRAGMA RAISE RECURSIVE RELEASE REPLACE RESTRICT ROW ROWS
   213    213     ROLLBACK SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL WITH WITHOUT
          214  +  NULLS FIRST LAST
   214    215   %ifdef SQLITE_OMIT_COMPOUND_SELECT
   215    216     EXCEPT INTERSECT UNION
   216    217   %endif SQLITE_OMIT_COMPOUND_SELECT
   217    218   %ifndef SQLITE_OMIT_WINDOWFUNC
   218    219     CURRENT FOLLOWING PARTITION PRECEDING RANGE UNBOUNDED
   219    220     EXCLUDE GROUPS OTHERS TIES
   220    221   %endif SQLITE_OMIT_WINDOWFUNC
................................................................................
   777    778   // sort order.
   778    779   //
   779    780   %type sortlist {ExprList*}
   780    781   %destructor sortlist {sqlite3ExprListDelete(pParse->db, $$);}
   781    782   
   782    783   orderby_opt(A) ::= .                          {A = 0;}
   783    784   orderby_opt(A) ::= ORDER BY sortlist(X).      {A = X;}
   784         -sortlist(A) ::= sortlist(A) COMMA expr(Y) sortorder(Z). {
          785  +sortlist(A) ::= sortlist(A) COMMA expr(Y) sortorder(Z) nulls(X). {
   785    786     A = sqlite3ExprListAppend(pParse,A,Y);
   786         -  sqlite3ExprListSetSortOrder(A,Z);
          787  +  sqlite3ExprListSetSortOrder(A,Z,X);
   787    788   }
   788         -sortlist(A) ::= expr(Y) sortorder(Z). {
          789  +sortlist(A) ::= expr(Y) sortorder(Z) nulls(X). {
   789    790     A = sqlite3ExprListAppend(pParse,0,Y); /*A-overwrites-Y*/
   790         -  sqlite3ExprListSetSortOrder(A,Z);
          791  +  sqlite3ExprListSetSortOrder(A,Z,X);
   791    792   }
   792    793   
   793    794   %type sortorder {int}
   794    795   
   795    796   sortorder(A) ::= ASC.           {A = SQLITE_SO_ASC;}
   796    797   sortorder(A) ::= DESC.          {A = SQLITE_SO_DESC;}
   797    798   sortorder(A) ::= .              {A = SQLITE_SO_UNDEFINED;}
   798    799   
          800  +%type nulls {int}
          801  +nulls(A) ::= NULLS FIRST.       {A = SQLITE_SO_ASC;}
          802  +nulls(A) ::= NULLS LAST.        {A = SQLITE_SO_DESC;}
          803  +nulls(A) ::= .                  {A = SQLITE_SO_UNDEFINED;}
          804  +
   799    805   %type groupby_opt {ExprList*}
   800    806   %destructor groupby_opt {sqlite3ExprListDelete(pParse->db, $$);}
   801    807   groupby_opt(A) ::= .                      {A = 0;}
   802    808   groupby_opt(A) ::= GROUP BY nexprlist(X). {A = X;}
   803    809   
   804    810   %type having_opt {Expr*}
   805    811   %destructor having_opt {sqlite3ExprDelete(pParse->db, $$);}
................................................................................
  1763   1769   %endif /* SQLITE_OMIT_WINDOWFUNC */
  1764   1770   
  1765   1771   /*
  1766   1772   ** The code generator needs some extra TK_ token values for tokens that
  1767   1773   ** are synthesized and do not actually appear in the grammar:
  1768   1774   */
  1769   1775   %token
  1770         -  TRUEFALSE       /* True or false keyword */
  1771         -  ISNOT           /* Combination of IS and NOT */
  1772         -  FUNCTION        /* A function invocation */
  1773   1776     COLUMN          /* Reference to a table column */
  1774   1777     AGG_FUNCTION    /* An aggregate function */
  1775   1778     AGG_COLUMN      /* An aggregated column */
         1779  +  TRUEFALSE       /* True or false keyword */
         1780  +  ISNOT           /* Combination of IS and NOT */
         1781  +  FUNCTION        /* A function invocation */
  1776   1782     UMINUS          /* Unary minus */
  1777   1783     UPLUS           /* Unary plus */
  1778   1784     TRUTH           /* IS TRUE or IS FALSE or IS NOT TRUE or IS NOT FALSE */
  1779   1785     REGISTER        /* Reference to a VDBE register */
  1780   1786     VECTOR          /* Vector */
  1781   1787     SELECT_COLUMN   /* Choose a single column from a multi-column SELECT */
  1782   1788     IF_NULL_ROW     /* the if-null-row operator */

Changes to src/select.c.

   660    660       }
   661    661       VdbeCoverage(v);
   662    662       sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
   663    663       pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
   664    664       if( pParse->db->mallocFailed ) return;
   665    665       pOp->p2 = nKey + nData;
   666    666       pKI = pOp->p4.pKeyInfo;
   667         -    memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */
          667  +    memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
   668    668       sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
   669    669       testcase( pKI->nAllField > pKI->nKeyField+2 );
   670    670       pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
   671    671                                              pKI->nAllField-pKI->nKeyField-1);
   672    672       addrJmp = sqlite3VdbeCurrentAddr(v);
   673    673       sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
   674    674       pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
................................................................................
  1271   1271   ** Allocate a KeyInfo object sufficient for an index of N key columns and
  1272   1272   ** X extra columns.
  1273   1273   */
  1274   1274   KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
  1275   1275     int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);
  1276   1276     KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);
  1277   1277     if( p ){
  1278         -    p->aSortOrder = (u8*)&p->aColl[N+X];
         1278  +    p->aSortFlags = (u8*)&p->aColl[N+X];
  1279   1279       p->nKeyField = (u16)N;
  1280   1280       p->nAllField = (u16)(N+X);
  1281   1281       p->enc = ENC(db);
  1282   1282       p->db = db;
  1283   1283       p->nRef = 1;
  1284   1284       memset(&p[1], 0, nExtra);
  1285   1285     }else{
................................................................................
  1348   1348   
  1349   1349     nExpr = pList->nExpr;
  1350   1350     pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
  1351   1351     if( pInfo ){
  1352   1352       assert( sqlite3KeyInfoIsWriteable(pInfo) );
  1353   1353       for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
  1354   1354         pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
  1355         -      pInfo->aSortOrder[i-iStart] = pItem->sortOrder;
         1355  +      pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
  1356   1356       }
  1357   1357     }
  1358   1358     return pInfo;
  1359   1359   }
  1360   1360   
  1361   1361   /*
  1362   1362   ** Name of the connection operator, used for error messages.
................................................................................
  2249   2249           pColl = multiSelectCollSeq(pParse, p, pItem->u.x.iOrderByCol-1);
  2250   2250           if( pColl==0 ) pColl = db->pDfltColl;
  2251   2251           pOrderBy->a[i].pExpr =
  2252   2252             sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
  2253   2253         }
  2254   2254         assert( sqlite3KeyInfoIsWriteable(pRet) );
  2255   2255         pRet->aColl[i] = pColl;
  2256         -      pRet->aSortOrder[i] = pOrderBy->a[i].sortOrder;
         2256  +      pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
  2257   2257       }
  2258   2258     }
  2259   2259   
  2260   2260     return pRet;
  2261   2261   }
  2262   2262   
  2263   2263   #ifndef SQLITE_OMIT_CTE
................................................................................
  3224   3224       pParse->nMem += nExpr+1;
  3225   3225       sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
  3226   3226       pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
  3227   3227       if( pKeyDup ){
  3228   3228         assert( sqlite3KeyInfoIsWriteable(pKeyDup) );
  3229   3229         for(i=0; i<nExpr; i++){
  3230   3230           pKeyDup->aColl[i] = multiSelectCollSeq(pParse, p, i);
  3231         -        pKeyDup->aSortOrder[i] = 0;
         3231  +        pKeyDup->aSortFlags[i] = 0;
  3232   3232         }
  3233   3233       }
  3234   3234     }
  3235   3235    
  3236   3236     /* Separate the left and the right query from one another
  3237   3237     */
  3238   3238     p->pPrior = 0;
................................................................................
  4401   4401   ** analysis.
  4402   4402   */
  4403   4403   static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
  4404   4404     int eRet = WHERE_ORDERBY_NORMAL;      /* Return value */
  4405   4405     ExprList *pEList = pFunc->x.pList;    /* Arguments to agg function */
  4406   4406     const char *zFunc;                    /* Name of aggregate function pFunc */
  4407   4407     ExprList *pOrderBy;
  4408         -  u8 sortOrder;
         4408  +  u8 sortFlags;
  4409   4409   
  4410   4410     assert( *ppMinMax==0 );
  4411   4411     assert( pFunc->op==TK_AGG_FUNCTION );
  4412   4412     assert( !IsWindowFunc(pFunc) );
  4413   4413     if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) ){
  4414   4414       return eRet;
  4415   4415     }
  4416   4416     zFunc = pFunc->u.zToken;
  4417   4417     if( sqlite3StrICmp(zFunc, "min")==0 ){
  4418   4418       eRet = WHERE_ORDERBY_MIN;
  4419         -    sortOrder = SQLITE_SO_ASC;
         4419  +    sortFlags = KEYINFO_ORDER_BIGNULL;
  4420   4420     }else if( sqlite3StrICmp(zFunc, "max")==0 ){
  4421   4421       eRet = WHERE_ORDERBY_MAX;
  4422         -    sortOrder = SQLITE_SO_DESC;
         4422  +    sortFlags = KEYINFO_ORDER_DESC;
  4423   4423     }else{
  4424   4424       return eRet;
  4425   4425     }
  4426   4426     *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
  4427   4427     assert( pOrderBy!=0 || db->mallocFailed );
  4428         -  if( pOrderBy ) pOrderBy->a[0].sortOrder = sortOrder;
         4428  +  if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
  4429   4429     return eRet;
  4430   4430   }
  4431   4431   
  4432   4432   /*
  4433   4433   ** The select statement passed as the first argument is an aggregate query.
  4434   4434   ** The second argument is the associated aggregate-info object. This 
  4435   4435   ** function tests if the SELECT is of the form:

Changes to src/sqliteInt.h.

  2134   2134   */
  2135   2135   struct KeyInfo {
  2136   2136     u32 nRef;           /* Number of references to this KeyInfo object */
  2137   2137     u8 enc;             /* Text encoding - one of the SQLITE_UTF* values */
  2138   2138     u16 nKeyField;      /* Number of key columns in the index */
  2139   2139     u16 nAllField;      /* Total columns, including key plus others */
  2140   2140     sqlite3 *db;        /* The database connection */
  2141         -  u8 *aSortOrder;     /* Sort order for each column. */
         2141  +  u8 *aSortFlags;     /* Sort order for each column. */
  2142   2142     CollSeq *aColl[1];  /* Collating sequence for each term of the key */
  2143   2143   };
         2144  +
         2145  +#define KEYINFO_ORDER_DESC    0x01
         2146  +#define KEYINFO_ORDER_BIGNULL 0x02
  2144   2147   
  2145   2148   /*
  2146   2149   ** This object holds a record which has been parsed out into individual
  2147   2150   ** fields, for the purposes of doing a comparison.
  2148   2151   **
  2149   2152   ** A record is an object that contains one or more fields of data.
  2150   2153   ** Records are used to store the content of a table row and to store
................................................................................
  2599   2602   */
  2600   2603   struct ExprList {
  2601   2604     int nExpr;             /* Number of expressions on the list */
  2602   2605     struct ExprList_item { /* For each expression in the list */
  2603   2606       Expr *pExpr;            /* The parse tree for this expression */
  2604   2607       char *zName;            /* Token associated with this expression */
  2605   2608       char *zSpan;            /* Original text of the expression */
  2606         -    u8 sortOrder;           /* 1 for DESC or 0 for ASC */
         2609  +    u8 sortFlags;           /* Mask of KEYINFO_ORDER_* flags */
  2607   2610       unsigned done :1;       /* A flag to indicate when processing is finished */
  2608   2611       unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
  2609   2612       unsigned reusable :1;   /* Constant expression is reusable */
  2610   2613       unsigned bSorterRef :1; /* Defer evaluation until after sorting */
         2614  +    unsigned bNulls: 1;     /* True if explicit "NULLS FIRST/LAST" */
  2611   2615       union {
  2612   2616         struct {
  2613   2617           u16 iOrderByCol;      /* For ORDER BY, column number in result set */
  2614   2618           u16 iAlias;           /* Index into Parse.aAlias[] for zName */
  2615   2619         } x;
  2616   2620         int iConstExprReg;      /* Register in which Expr value is cached */
  2617   2621       } u;
................................................................................
  3884   3888   Expr *sqlite3ExprSimplifiedAndOr(Expr*);
  3885   3889   Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
  3886   3890   void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
  3887   3891   void sqlite3ExprDelete(sqlite3*, Expr*);
  3888   3892   void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
  3889   3893   ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
  3890   3894   ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
  3891         -void sqlite3ExprListSetSortOrder(ExprList*,int);
         3895  +void sqlite3ExprListSetSortOrder(ExprList*,int,int);
  3892   3896   void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
  3893   3897   void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
  3894   3898   void sqlite3ExprListDelete(sqlite3*, ExprList*);
  3895   3899   u32 sqlite3ExprListFlags(const ExprList*);
  3896   3900   int sqlite3IndexHasDuplicateRootPage(Index*);
  3897   3901   int sqlite3Init(sqlite3*, char**);
  3898   3902   int sqlite3InitCallback(void*, int, char**, char**);
................................................................................
  4361   4365   Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
  4362   4366   int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
  4363   4367   KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int);
  4364   4368   void sqlite3KeyInfoUnref(KeyInfo*);
  4365   4369   KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
  4366   4370   KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
  4367   4371   KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);
         4372  +int sqlite3HasExplicitNulls(Parse*, ExprList*);
  4368   4373   
  4369   4374   #ifdef SQLITE_DEBUG
  4370   4375   int sqlite3KeyInfoIsWriteable(KeyInfo*);
  4371   4376   #endif
  4372   4377   int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
  4373   4378     void (*)(sqlite3_context*,int,sqlite3_value **),
  4374   4379     void (*)(sqlite3_context*,int,sqlite3_value **), 

Changes to src/trigger.c.

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

Changes to src/vdbe.c.

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

Changes to src/vdbeaux.c.

  1489   1489     StrAccum x;
  1490   1490     assert( nTemp>=20 );
  1491   1491     sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0);
  1492   1492     switch( pOp->p4type ){
  1493   1493       case P4_KEYINFO: {
  1494   1494         int j;
  1495   1495         KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
  1496         -      assert( pKeyInfo->aSortOrder!=0 );
         1496  +      assert( pKeyInfo->aSortFlags!=0 );
  1497   1497         sqlite3_str_appendf(&x, "k(%d", pKeyInfo->nKeyField);
  1498   1498         for(j=0; j<pKeyInfo->nKeyField; j++){
  1499   1499           CollSeq *pColl = pKeyInfo->aColl[j];
  1500   1500           const char *zColl = pColl ? pColl->zName : "";
  1501   1501           if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
  1502         -        sqlite3_str_appendf(&x, ",%s%s", 
  1503         -               pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
         1502  +        sqlite3_str_appendf(&x, ",%s%s%s", 
         1503  +               (pKeyInfo->aSortFlags[j] & KEYINFO_ORDER_DESC) ? "-" : "", 
         1504  +               (pKeyInfo->aSortFlags[j] & KEYINFO_ORDER_BIGNULL)? "N." : "", 
         1505  +               zColl);
  1504   1506         }
  1505   1507         sqlite3_str_append(&x, ")", 1);
  1506   1508         break;
  1507   1509       }
  1508   1510   #ifdef SQLITE_ENABLE_CURSOR_HINTS
  1509   1511       case P4_EXPR: {
  1510   1512         displayP4Expr(&x, pOp->p4.pExpr);
................................................................................
  3809   3811   ){
  3810   3812     UnpackedRecord *p;              /* Unpacked record to return */
  3811   3813     int nByte;                      /* Number of bytes required for *p */
  3812   3814     nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
  3813   3815     p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
  3814   3816     if( !p ) return 0;
  3815   3817     p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
  3816         -  assert( pKeyInfo->aSortOrder!=0 );
         3818  +  assert( pKeyInfo->aSortFlags!=0 );
  3817   3819     p->pKeyInfo = pKeyInfo;
  3818   3820     p->nField = pKeyInfo->nKeyField + 1;
  3819   3821     return p;
  3820   3822   }
  3821   3823   
  3822   3824   /*
  3823   3825   ** Given the nKey-byte encoding of a record in pKey[], populate the 
................................................................................
  3908   3910     */
  3909   3911     /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
  3910   3912     
  3911   3913     idx1 = getVarint32(aKey1, szHdr1);
  3912   3914     if( szHdr1>98307 ) return SQLITE_CORRUPT;
  3913   3915     d1 = szHdr1;
  3914   3916     assert( pKeyInfo->nAllField>=pPKey2->nField || CORRUPT_DB );
  3915         -  assert( pKeyInfo->aSortOrder!=0 );
         3917  +  assert( pKeyInfo->aSortFlags!=0 );
  3916   3918     assert( pKeyInfo->nKeyField>0 );
  3917   3919     assert( idx1<=szHdr1 || CORRUPT_DB );
  3918   3920     do{
  3919   3921       u32 serial_type1;
  3920   3922   
  3921   3923       /* Read the serial types for the next element in each key. */
  3922   3924       idx1 += getVarint32( aKey1+idx1, serial_type1 );
................................................................................
  3939   3941   
  3940   3942       /* Do the comparison
  3941   3943       */
  3942   3944       rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
  3943   3945                              pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
  3944   3946       if( rc!=0 ){
  3945   3947         assert( mem1.szMalloc==0 );  /* See comment below */
  3946         -      if( pKeyInfo->aSortOrder[i] ){
         3948  +      if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL)
         3949  +       && ((mem1.flags & MEM_Null) || (pPKey2->aMem[i].flags & MEM_Null)) 
         3950  +      ){
         3951  +        rc = -rc;
         3952  +      }
         3953  +      if( pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC ){
  3947   3954           rc = -rc;  /* Invert the result for DESC sort order. */
  3948   3955         }
  3949   3956         goto debugCompareEnd;
  3950   3957       }
  3951   3958       i++;
  3952   3959     }while( idx1<szHdr1 && i<pPKey2->nField );
  3953   3960   
................................................................................
  4315   4322       pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
  4316   4323       return 0;  /* Corruption */
  4317   4324     }
  4318   4325   
  4319   4326     VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
  4320   4327     assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField 
  4321   4328          || CORRUPT_DB );
  4322         -  assert( pPKey2->pKeyInfo->aSortOrder!=0 );
         4329  +  assert( pPKey2->pKeyInfo->aSortFlags!=0 );
  4323   4330     assert( pPKey2->pKeyInfo->nKeyField>0 );
  4324   4331     assert( idx1<=szHdr1 || CORRUPT_DB );
  4325   4332     do{
  4326   4333       u32 serial_type;
  4327   4334   
  4328   4335       /* RHS is an integer */
  4329   4336       if( pRhs->flags & (MEM_Int|MEM_IntReal) ){
................................................................................
  4438   4445       /* RHS is null */
  4439   4446       else{
  4440   4447         serial_type = aKey1[idx1];
  4441   4448         rc = (serial_type!=0);
  4442   4449       }
  4443   4450   
  4444   4451       if( rc!=0 ){
  4445         -      if( pPKey2->pKeyInfo->aSortOrder[i] ){
  4446         -        rc = -rc;
         4452  +      int sortFlags = pPKey2->pKeyInfo->aSortFlags[i];
         4453  +      if( sortFlags ){
         4454  +        if( (sortFlags & KEYINFO_ORDER_BIGNULL)==0
         4455  +         || ((sortFlags & KEYINFO_ORDER_DESC)
         4456  +           !=(serial_type==0 || (pRhs->flags&MEM_Null)))
         4457  +        ){
         4458  +          rc = -rc;
         4459  +        }
  4447   4460         }
  4448   4461         assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, rc) );
  4449   4462         assert( mem1.szMalloc==0 );  /* See comment below */
  4450   4463         return rc;
  4451   4464       }
  4452   4465   
  4453   4466       i++;
................................................................................
  4656   4669     ** is an integer.
  4657   4670     **
  4658   4671     ** The easiest way to enforce this limit is to consider only records with
  4659   4672     ** 13 fields or less. If the first field is an integer, the maximum legal
  4660   4673     ** header size is (12*5 + 1 + 1) bytes.  */
  4661   4674     if( p->pKeyInfo->nAllField<=13 ){
  4662   4675       int flags = p->aMem[0].flags;
  4663         -    if( p->pKeyInfo->aSortOrder[0] ){
         4676  +    if( p->pKeyInfo->aSortFlags[0] ){
         4677  +      if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
         4678  +        return sqlite3VdbeRecordCompare;
         4679  +      }
  4664   4680         p->r1 = 1;
  4665   4681         p->r2 = -1;
  4666   4682       }else{
  4667   4683         p->r1 = -1;
  4668   4684         p->r2 = 1;
  4669   4685       }
  4670   4686       if( (flags & MEM_Int) ){
................................................................................
  5002   5018     preupdate.v = v;
  5003   5019     preupdate.pCsr = pCsr;
  5004   5020     preupdate.op = op;
  5005   5021     preupdate.iNewReg = iReg;
  5006   5022     preupdate.keyinfo.db = db;
  5007   5023     preupdate.keyinfo.enc = ENC(db);
  5008   5024     preupdate.keyinfo.nKeyField = pTab->nCol;
  5009         -  preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder;
         5025  +  preupdate.keyinfo.aSortFlags = (u8*)&fakeSortOrder;
  5010   5026     preupdate.iKey1 = iKey1;
  5011   5027     preupdate.iKey2 = iKey2;
  5012   5028     preupdate.pTab = pTab;
  5013   5029   
  5014   5030     db->pPreUpdate = &preupdate;
  5015   5031     db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
  5016   5032     db->pPreUpdate = 0;

Changes to src/vdbesort.c.

   825    825     if( res==0 ){
   826    826       if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
   827    827         res = vdbeSorterCompareTail(
   828    828             pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
   829    829         );
   830    830       }
   831    831     }else{
   832         -    if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
          832  +    assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
          833  +    if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
   833    834         res = res * -1;
   834    835       }
   835    836     }
   836    837   
   837    838     return res;
   838    839   }
   839    840   
................................................................................
   893    894   
   894    895     if( res==0 ){
   895    896       if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
   896    897         res = vdbeSorterCompareTail(
   897    898             pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
   898    899         );
   899    900       }
   900         -  }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
          901  +  }else if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
          902  +    assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
   901    903       res = res * -1;
   902    904     }
   903    905   
   904    906     return res;
   905    907   }
   906    908   
   907    909   /*
................................................................................
  1008   1010           pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
  1009   1011           if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
  1010   1012         }
  1011   1013       }
  1012   1014   
  1013   1015       if( pKeyInfo->nAllField<13 
  1014   1016        && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
         1017  +     && (pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL)==0
  1015   1018       ){
  1016   1019         pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
  1017   1020       }
  1018   1021     }
  1019   1022   
  1020   1023     return rc;
  1021   1024   }

Changes to src/where.c.

   930    930     */
   931    931     nOrderBy = 0;
   932    932     if( pOrderBy ){
   933    933       int n = pOrderBy->nExpr;
   934    934       for(i=0; i<n; i++){
   935    935         Expr *pExpr = pOrderBy->a[i].pExpr;
   936    936         if( pExpr->op!=TK_COLUMN || pExpr->iTable!=pSrc->iCursor ) break;
          937  +      if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
   937    938       }
   938    939       if( i==n){
   939    940         nOrderBy = n;
   940    941       }
   941    942     }
   942    943   
   943    944     /* Allocate the sqlite3_index_info structure
................................................................................
  1028   1029       }
  1029   1030   
  1030   1031       j++;
  1031   1032     }
  1032   1033     for(i=0; i<nOrderBy; i++){
  1033   1034       Expr *pExpr = pOrderBy->a[i].pExpr;
  1034   1035       pIdxOrderBy[i].iColumn = pExpr->iColumn;
  1035         -    pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder;
         1036  +    pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
  1036   1037     }
  1037   1038   
  1038   1039     *pmNoOmit = mNoOmit;
  1039   1040     return pIdxInfo;
  1040   1041   }
  1041   1042   
  1042   1043   /*
................................................................................
  3802   3803           }
  3803   3804   
  3804   3805           /* Get the column number in the table (iColumn) and sort order
  3805   3806           ** (revIdx) for the j-th column of the index.
  3806   3807           */
  3807   3808           if( pIndex ){
  3808   3809             iColumn = pIndex->aiColumn[j];
  3809         -          revIdx = pIndex->aSortOrder[j];
         3810  +          revIdx = pIndex->aSortOrder[j] & KEYINFO_ORDER_DESC;
  3810   3811             if( iColumn==pIndex->pTable->iPKey ) iColumn = XN_ROWID;
  3811   3812           }else{
  3812   3813             iColumn = XN_ROWID;
  3813   3814             revIdx = 0;
  3814   3815           }
  3815   3816   
  3816   3817           /* An unconstrained column that might be NULL means that this
................................................................................
  3854   3855             isMatch = 1;
  3855   3856             break;
  3856   3857           }
  3857   3858           if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
  3858   3859             /* Make sure the sort order is compatible in an ORDER BY clause.
  3859   3860             ** Sort order is irrelevant for a GROUP BY clause. */
  3860   3861             if( revSet ){
  3861         -            if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;
         3862  +            if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
         3863  +              isMatch = 0;
         3864  +            }
  3862   3865             }else{
  3863         -            rev = revIdx ^ pOrderBy->a[i].sortOrder;
         3866  +            rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
  3864   3867               if( rev ) *pRevMask |= MASKBIT(iLoop);
  3865   3868               revSet = 1;
  3866   3869             }
         3870  +        }
         3871  +        if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
         3872  +          if( j==pLoop->u.btree.nEq ){
         3873  +            pLoop->wsFlags |= WHERE_BIGNULL_SORT;
         3874  +          }else{
         3875  +            isMatch = 0;
         3876  +          }
  3867   3877           }
  3868   3878           if( isMatch ){
  3869   3879             if( iColumn==XN_ROWID ){
  3870   3880               testcase( distinctColumns==0 );
  3871   3881               distinctColumns = 1;
  3872   3882             }
  3873   3883             obSat |= MASKBIT(i);
  3874         -          if( (wctrlFlags & WHERE_ORDERBY_MIN) && j==pLoop->u.btree.nEq ){
  3875         -            pLoop->wsFlags |= WHERE_MIN_ORDERED;
  3876         -          }
  3877   3884           }else{
  3878   3885             /* No match found */
  3879   3886             if( j==0 || j<nKeyCol ){
  3880   3887               testcase( isOrderDistinct!=0 );
  3881   3888               isOrderDistinct = 0;
  3882   3889             }
  3883   3890             break;
................................................................................
  5063   5070         assert( pIx->pSchema==pTab->pSchema );
  5064   5071         assert( iIndexCur>=0 );
  5065   5072         if( op ){
  5066   5073           sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
  5067   5074           sqlite3VdbeSetP4KeyInfo(pParse, pIx);
  5068   5075           if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
  5069   5076            && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
         5077  +         && (pLoop->wsFlags & WHERE_BIGNULL_SORT)==0
  5070   5078            && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
  5071   5079            && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
  5072   5080           ){
  5073   5081             sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
  5074   5082           }
  5075   5083           VdbeComment((v, "%s", pIx->zName));
  5076   5084   #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
................................................................................
  5204   5212         sqlite3VdbeResolveLabel(v, pLevel->addrCont);
  5205   5213         sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
  5206   5214         sqlite3VdbeChangeP5(v, pLevel->p5);
  5207   5215         VdbeCoverage(v);
  5208   5216         VdbeCoverageIf(v, pLevel->op==OP_Next);
  5209   5217         VdbeCoverageIf(v, pLevel->op==OP_Prev);
  5210   5218         VdbeCoverageIf(v, pLevel->op==OP_VNext);
         5219  +      if( pLevel->regBignull ){
         5220  +        sqlite3VdbeResolveLabel(v, pLevel->addrBignull);
         5221  +        sqlite3VdbeAddOp2(v, OP_IfNotZero, pLevel->regBignull, pLevel->p2-1);
         5222  +      }
  5211   5223   #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
  5212   5224         if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
  5213   5225   #endif
  5214   5226       }else{
  5215   5227         sqlite3VdbeResolveLabel(v, pLevel->addrCont);
  5216   5228       }
  5217   5229       if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){

Changes to src/whereInt.h.

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

Changes to src/wherecode.c.

  1546   1546       int nExtraReg = 0;           /* Number of extra registers needed */
  1547   1547       int op;                      /* Instruction opcode */
  1548   1548       char *zStartAff;             /* Affinity for start of range constraint */
  1549   1549       char *zEndAff = 0;           /* Affinity for end of range constraint */
  1550   1550       u8 bSeekPastNull = 0;        /* True to seek past initial nulls */
  1551   1551       u8 bStopAtNull = 0;          /* Add condition to terminate at NULLs */
  1552   1552       int omitTable;               /* True if we use the index only */
  1553         -
         1553  +    int regBignull = 0;          /* big-null flag register */
  1554   1554   
  1555   1555       pIdx = pLoop->u.btree.pIndex;
  1556   1556       iIdxCur = pLevel->iIdxCur;
  1557   1557       assert( nEq>=pLoop->nSkip );
  1558   1558   
  1559         -    /* If this loop satisfies a sort order (pOrderBy) request that 
  1560         -    ** was passed to this function to implement a "SELECT min(x) ..." 
  1561         -    ** query, then the caller will only allow the loop to run for
  1562         -    ** a single iteration. This means that the first row returned
  1563         -    ** should not have a NULL value stored in 'x'. If column 'x' is
  1564         -    ** the first one after the nEq equality constraints in the index,
  1565         -    ** this requires some special handling.
  1566         -    */
  1567         -    assert( (pWInfo->pOrderBy!=0 && pWInfo->pOrderBy->nExpr==1)
  1568         -         || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
  1569         -    if( pLoop->wsFlags & WHERE_MIN_ORDERED ){
  1570         -      assert( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN) );
  1571         -      assert( pWInfo->nOBSat );
  1572         -      assert( pIdx->nColumn>nEq );
  1573         -      assert( pLoop->nSkip==0 );
  1574         -      bSeekPastNull = 1;
  1575         -      nExtraReg = 1;
  1576         -    }
  1577         -
  1578   1559       /* Find any inequality constraint terms for the start and end 
  1579   1560       ** of the range. 
  1580   1561       */
  1581   1562       j = nEq;
  1582   1563       if( pLoop->wsFlags & WHERE_BTM_LIMIT ){
  1583   1564         pRangeStart = pLoop->aLTerm[j++];
  1584   1565         nExtraReg = MAX(nExtraReg, pLoop->u.btree.nBtm);
................................................................................
  1610   1591           j = pIdx->aiColumn[nEq];
  1611   1592           if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
  1612   1593             bSeekPastNull = 1;
  1613   1594           }
  1614   1595         }
  1615   1596       }
  1616   1597       assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 );
         1598  +
         1599  +    /* If the WHERE_BIGNULL_SORT flag is set, then index column nEq uses
         1600  +    ** a non-default "big-null" sort (either ASC NULLS LAST or DESC NULLS 
         1601  +    ** FIRST). In both cases separate ordered scans are made of those
         1602  +    ** index entries for which the column is null and for those for which
         1603  +    ** it is not. For an ASC sort, the non-NULL entries are scanned first.
         1604  +    ** For DESC, NULL entries are scanned first.
         1605  +    */
         1606  +    if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0
         1607  +     && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0
         1608  +    ){
         1609  +      assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 );
         1610  +      assert( pRangeEnd==0 && pRangeStart==0 );
         1611  +      assert( pLoop->nSkip==0 );
         1612  +      nExtraReg = 1;
         1613  +      bSeekPastNull = 1;
         1614  +      pLevel->regBignull = regBignull = ++pParse->nMem;
         1615  +      pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse);
         1616  +    }
  1617   1617   
  1618   1618       /* If we are doing a reverse order scan on an ascending index, or
  1619   1619       ** a forward order scan on a descending index, interchange the 
  1620   1620       ** start and end terms (pRangeStart and pRangeEnd).
  1621   1621       */
  1622   1622       if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
  1623   1623        || (bRev && pIdx->nKeyCol==nEq)
................................................................................
  1633   1633       */
  1634   1634       codeCursorHint(pTabItem, pWInfo, pLevel, pRangeEnd);
  1635   1635       regBase = codeAllEqualityTerms(pParse,pLevel,bRev,nExtraReg,&zStartAff);
  1636   1636       assert( zStartAff==0 || sqlite3Strlen30(zStartAff)>=nEq );
  1637   1637       if( zStartAff && nTop ){
  1638   1638         zEndAff = sqlite3DbStrDup(db, &zStartAff[nEq]);
  1639   1639       }
  1640         -    addrNxt = pLevel->addrNxt;
         1640  +    addrNxt = (regBignull ? pLevel->addrBignull : pLevel->addrNxt);
  1641   1641   
  1642   1642       testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
  1643   1643       testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
  1644   1644       testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
  1645   1645       testcase( pRangeEnd && (pRangeEnd->eOperator & WO_GE)!=0 );
  1646   1646       startEq = !pRangeStart || pRangeStart->eOperator & (WO_LE|WO_GE);
  1647   1647       endEq =   !pRangeEnd || pRangeEnd->eOperator & (WO_LE|WO_GE);
................................................................................
  1667   1667         if( sqlite3ExprIsVector(pRight)==0 ){
  1668   1668           disableTerm(pLevel, pRangeStart);
  1669   1669         }else{
  1670   1670           startEq = 1;
  1671   1671         }
  1672   1672         bSeekPastNull = 0;
  1673   1673       }else if( bSeekPastNull ){
  1674         -      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
  1675         -      nConstraint++;
  1676   1674         startEq = 0;
         1675  +      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
         1676  +      start_constraints = 1;
         1677  +      nConstraint++;
         1678  +    }else if( regBignull ){
         1679  +      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
  1677   1680         start_constraints = 1;
         1681  +      nConstraint++;
  1678   1682       }
  1679   1683       codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
  1680   1684       if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){
  1681   1685         /* The skip-scan logic inside the call to codeAllEqualityConstraints()
  1682   1686         ** above has already left the cursor sitting on the correct row,
  1683   1687         ** so no further seeking is needed */
  1684   1688       }else{
  1685   1689         if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){
  1686   1690           sqlite3VdbeAddOp1(v, OP_SeekHit, iIdxCur);
  1687   1691         }
         1692  +      if( regBignull ){
         1693  +        sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull);
         1694  +        VdbeComment((v, "NULL-scan pass ctr"));
         1695  +      }
         1696  +
  1688   1697         op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
  1689   1698         assert( op!=0 );
  1690   1699         sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
  1691   1700         VdbeCoverage(v);
  1692   1701         VdbeCoverageIf(v, op==OP_Rewind);  testcase( op==OP_Rewind );
  1693   1702         VdbeCoverageIf(v, op==OP_Last);    testcase( op==OP_Last );
  1694   1703         VdbeCoverageIf(v, op==OP_SeekGT);  testcase( op==OP_SeekGT );
  1695   1704         VdbeCoverageIf(v, op==OP_SeekGE);  testcase( op==OP_SeekGE );
  1696   1705         VdbeCoverageIf(v, op==OP_SeekLE);  testcase( op==OP_SeekLE );
  1697   1706         VdbeCoverageIf(v, op==OP_SeekLT);  testcase( op==OP_SeekLT );
  1698   1707   
  1699         -      if( bSeekPastNull && (pLoop->wsFlags & WHERE_TOP_LIMIT)==0 ){
  1700         -        /* If bSeekPastNull is set only to skip past the NULL values for
  1701         -        ** a query like "SELECT min(a), b FROM t1", then add code so that
  1702         -        ** if there are no rows with (a IS NOT NULL), then do the seek 
  1703         -        ** without jumping past NULLs instead. This allows the code in 
  1704         -        ** select.c to pick a value for "b" in the above query.  */
  1705         -        assert( startEq==0 && (op==OP_SeekGT || op==OP_SeekLT) );
  1706         -        assert( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 && pWInfo->nOBSat>0 );
  1707         -        sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
         1708  +      assert( bSeekPastNull==0 || bStopAtNull==0 );
         1709  +      if( regBignull ){
         1710  +        assert( bSeekPastNull==1 || bStopAtNull==1 );
         1711  +        assert( bSeekPastNull==!bStopAtNull );
         1712  +        assert( bStopAtNull==startEq );
  1708   1713           sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
  1709         -
  1710         -        op = aStartOp[(start_constraints<<2) + (1<<1) + bRev];
  1711         -        assert( op==OP_SeekGE || op==OP_SeekLE );
  1712         -        sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
         1714  +        op = aStartOp[(nConstraint>1)*4 + 2 + bRev];
         1715  +        sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, 
         1716  +                             nConstraint-startEq);
  1713   1717           VdbeCoverage(v);
         1718  +        VdbeCoverageIf(v, op==OP_Rewind);  testcase( op==OP_Rewind );
         1719  +        VdbeCoverageIf(v, op==OP_Last);    testcase( op==OP_Last );
  1714   1720           VdbeCoverageIf(v, op==OP_SeekGE);  testcase( op==OP_SeekGE );
  1715   1721           VdbeCoverageIf(v, op==OP_SeekLE);  testcase( op==OP_SeekLE );
         1722  +        assert( op==OP_Rewind || op==OP_Last || op==OP_SeekGE || op==OP_SeekLE);
  1716   1723         }
  1717   1724       }
  1718   1725   
  1719   1726       /* Load the value for the inequality constraint at the end of the
  1720   1727       ** range (if any).
  1721   1728       */
  1722   1729       nConstraint = nEq;
................................................................................
  1741   1748   
  1742   1749         if( sqlite3ExprIsVector(pRight)==0 ){
  1743   1750           disableTerm(pLevel, pRangeEnd);
  1744   1751         }else{
  1745   1752           endEq = 1;
  1746   1753         }
  1747   1754       }else if( bStopAtNull ){
  1748         -      sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
  1749         -      endEq = 0;
         1755  +      if( regBignull==0 ){
         1756  +        sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
         1757  +        endEq = 0;
         1758  +      }
  1750   1759         nConstraint++;
  1751   1760       }
  1752   1761       sqlite3DbFree(db, zStartAff);
  1753   1762       sqlite3DbFree(db, zEndAff);
  1754   1763   
  1755   1764       /* Top of the loop body */
  1756   1765       pLevel->p2 = sqlite3VdbeCurrentAddr(v);
  1757   1766   
  1758   1767       /* Check if the index cursor is past the end of the range. */
  1759   1768       if( nConstraint ){
         1769  +      if( regBignull ){
         1770  +        /* Except, skip the end-of-range check while doing the NULL-scan */
         1771  +        sqlite3VdbeAddOp2(v, OP_IfNot, regBignull, sqlite3VdbeCurrentAddr(v)+3);
         1772  +        VdbeComment((v, "If NULL-scan 2nd pass"));
         1773  +        VdbeCoverage(v);
         1774  +      }
  1760   1775         op = aEndOp[bRev*2 + endEq];
  1761   1776         sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
         1777  +      testcase( op==OP_IdxGT );  VdbeCoverageIf(v, op==OP_IdxGT );
         1778  +      testcase( op==OP_IdxGE );  VdbeCoverageIf(v, op==OP_IdxGE );
         1779  +      testcase( op==OP_IdxLT );  VdbeCoverageIf(v, op==OP_IdxLT );
         1780  +      testcase( op==OP_IdxLE );  VdbeCoverageIf(v, op==OP_IdxLE );
         1781  +    }
         1782  +    if( regBignull ){
         1783  +      /* During a NULL-scan, check to see if we have reached the end of
         1784  +      ** the NULLs */
         1785  +      assert( bSeekPastNull==!bStopAtNull );
         1786  +      assert( bSeekPastNull+bStopAtNull==1 );
         1787  +      assert( nConstraint+bSeekPastNull>0 );
         1788  +      sqlite3VdbeAddOp2(v, OP_If, regBignull, sqlite3VdbeCurrentAddr(v)+2);
         1789  +      VdbeComment((v, "If NULL-scan 1st pass"));
         1790  +      VdbeCoverage(v);
         1791  +      op = aEndOp[bRev*2 + bSeekPastNull];
         1792  +      sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase,
         1793  +                           nConstraint+bSeekPastNull);
  1762   1794         testcase( op==OP_IdxGT );  VdbeCoverageIf(v, op==OP_IdxGT );
  1763   1795         testcase( op==OP_IdxGE );  VdbeCoverageIf(v, op==OP_IdxGE );
  1764   1796         testcase( op==OP_IdxLT );  VdbeCoverageIf(v, op==OP_IdxLT );
  1765   1797         testcase( op==OP_IdxLE );  VdbeCoverageIf(v, op==OP_IdxLE );
  1766   1798       }
  1767   1799   
  1768   1800       if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){

Changes to src/window.c.

   884    884       for(i=0; i<pAppend->nExpr; i++){
   885    885         Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
   886    886         if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
   887    887           pDup->op = TK_NULL;
   888    888           pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
   889    889         }
   890    890         pList = sqlite3ExprListAppend(pParse, pList, pDup);
   891         -      if( pList ) pList->a[nInit+i].sortOrder = pAppend->a[i].sortOrder;
          891  +      if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
   892    892       }
   893    893     }
   894    894     return pList;
   895    895   }
   896    896   
   897    897   /*
   898    898   ** If the SELECT statement passed as the second argument does not invoke
................................................................................
  1311   1311         */
  1312   1312         ExprList *pList = pWin->pOwner->x.pList;
  1313   1313         KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
  1314   1314         pWin->csrApp = pParse->nTab++;
  1315   1315         pWin->regApp = pParse->nMem+1;
  1316   1316         pParse->nMem += 3;
  1317   1317         if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
  1318         -        assert( pKeyInfo->aSortOrder[0]==0 );
  1319         -        pKeyInfo->aSortOrder[0] = 1;
         1318  +        assert( pKeyInfo->aSortFlags[0]==0 );
         1319  +        pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
  1320   1320         }
  1321   1321         sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2);
  1322   1322         sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
  1323   1323         sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
  1324   1324       }
  1325   1325       else if( p->zName==nth_valueName || p->zName==first_valueName ){
  1326   1326         /* Allocate two registers at pWin->regApp. These will be used to
................................................................................
  1872   1872   ){
  1873   1873     Parse *pParse = p->pParse;
  1874   1874     Vdbe *v = sqlite3GetVdbe(pParse);
  1875   1875     int reg1 = sqlite3GetTempReg(pParse);
  1876   1876     int reg2 = sqlite3GetTempReg(pParse);
  1877   1877     int arith = OP_Add;
  1878   1878     int addrGe;
         1879  +  ExprList *pOrderBy = p->pMWin->pOrderBy;
  1879   1880   
  1880   1881     int regString = ++pParse->nMem;
  1881   1882   
  1882   1883     assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
  1883         -  assert( p->pMWin->pOrderBy && p->pMWin->pOrderBy->nExpr==1 );
  1884         -  if( p->pMWin->pOrderBy->a[0].sortOrder ){
         1884  +  assert( pOrderBy && pOrderBy->nExpr==1 );
         1885  +  if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
  1885   1886       switch( op ){
  1886   1887         case OP_Ge: op = OP_Le; break;
  1887   1888         case OP_Gt: op = OP_Lt; break;
  1888   1889         default: assert( op==OP_Le ); op = OP_Ge; break;
  1889   1890       }
  1890   1891       arith = OP_Subtract;
  1891   1892     }
................................................................................
  1897   1898     ** it to the smallest possible string - ''. If it is, jump over the
  1898   1899     ** OP_Add or OP_Subtract operation and proceed directly to the comparison. */
  1899   1900     sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
  1900   1901     addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
  1901   1902     VdbeCoverage(v);
  1902   1903     sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
  1903   1904     sqlite3VdbeJumpHere(v, addrGe);
         1905  +  if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
         1906  +    int addr;
         1907  +    addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
         1908  +    switch( op ){
         1909  +      case OP_Ge: sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl); break;
         1910  +      case OP_Gt: 
         1911  +        sqlite3VdbeAddOp2(v, OP_NotNull, reg2, lbl); 
         1912  +        VdbeCoverage(v); 
         1913  +        break;
         1914  +      case OP_Le: 
         1915  +        sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); 
         1916  +        VdbeCoverage(v); 
         1917  +        break;
         1918  +      default: assert( op==OP_Lt ); /* no-op */
         1919  +    }
         1920  +    sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
         1921  +    sqlite3VdbeJumpHere(v, addr);
         1922  +    sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
         1923  +    if( op==OP_Gt || op==OP_Ge ){
         1924  +      sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
         1925  +    }
         1926  +  }
  1904   1927     sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
  1905   1928     sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
  1906   1929     assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
  1907   1930     testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
  1908   1931     testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
  1909   1932     testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
  1910   1933     testcase(op==OP_Gt); VdbeCoverageIf(v, op==OP_Gt);

Changes to test/minmax4.test.

   195    195     CREATE TABLE t1 (a, b);
   196    196     INSERT INTO t1 VALUES(123, NULL);
   197    197     CREATE INDEX i1 ON t1(a, b DESC);
   198    198   }
   199    199   do_execsql_test 5.1 {
   200    200     SELECT MIN(a) FROM t1 WHERE a=123;
   201    201   } {123}
          202  +
          203  +#-------------------------------------------------------------------------
          204  +# Tests for ticket f8a7060ece.
          205  +#
          206  +reset_db
          207  +do_execsql_test 6.1.0 {
          208  +  CREATE TABLE t1(a, b, c);
          209  +  INSERT INTO t1 VALUES(NULL, 1, 'x');
          210  +  CREATE INDEX i1 ON t1(a);
          211  +}
          212  +do_execsql_test 6.1.1 {
          213  +  SELECT min(a), b, c FROM t1 WHERE c='x';
          214  +} {{} 1 x}
          215  +do_execsql_test 6.1.2 {
          216  +  INSERT INTO t1 VALUES(1,    2, 'y');
          217  +} {}
          218  +do_execsql_test 6.1.3 {
          219  +  SELECT min(a), b, c FROM t1 WHERE c='x';
          220  +} {{} 1 x}
          221  +
          222  +do_execsql_test 6.2.0 {
          223  +  CREATE TABLE t0(c0 UNIQUE, c1);
          224  +  INSERT INTO t0(c1) VALUES (0);
          225  +  INSERT INTO t0(c0) VALUES (0);
          226  +  CREATE VIEW v0(c0, c1) AS 
          227  +      SELECT t0.c1, t0.c0 FROM t0 WHERE CAST(t0.rowid AS INT) = 1;
          228  +}
          229  +do_execsql_test 6.2.1 {
          230  +  SELECT c0, c1 FROM v0;
          231  +} {0 {}}
          232  +do_execsql_test 6.2.2 {
          233  +  SELECT v0.c0, MIN(v0.c1) FROM v0;
          234  +} {0 {}}
   202    235   
   203    236   finish_test

Added test/nulls1.test.

            1  +# 2019 August 10
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +set testprefix nulls1
           17  +
           18  +do_execsql_test 1.0 {
           19  +  DROP TABLE IF EXISTS t3;
           20  +  CREATE TABLE t3(a INTEGER);
           21  +  INSERT INTO t3 VALUES(NULL), (10), (30), (20), (NULL);
           22  +} {}
           23  +
           24  +for {set a 0} {$a < 3} {incr a} {
           25  +  foreach {tn limit} {
           26  +    1 ""
           27  +    2 "LIMIT 10"
           28  +  } {
           29  +    do_execsql_test 1.$a.$tn.1 "
           30  +      SELECT a FROM t3 ORDER BY a nULLS FIRST $limit
           31  +    " {{}   {}   10   20   30}
           32  +    
           33  +    do_execsql_test 1.$a.$tn.2 "
           34  +      SELECT a FROM t3 ORDER BY a nULLS LAST $limit
           35  +    " {10   20   30   {}   {}}
           36  +    
           37  +    do_execsql_test 1.$a.$tn.3 "
           38  +      SELECT a FROM t3 ORDER BY a DESC nULLS FIRST $limit
           39  +    " {{}   {}   30   20   10}
           40  +    
           41  +    do_execsql_test 1.$a.$tn.4 "
           42  +      SELECT a FROM t3 ORDER BY a DESC nULLS LAST $limit
           43  +    " {30   20   10   {}   {}}
           44  +  }
           45  +
           46  +  switch $a {
           47  +    0 {
           48  +      execsql { CREATE INDEX i1 ON t3(a) }
           49  +    }
           50  +    1 {
           51  +      execsql { DROP INDEX i1 ; CREATE INDEX i1 ON t3(a DESC) }
           52  +    }
           53  +  }
           54  +}
           55  +
           56  +#-------------------------------------------------------------------------
           57  +reset_db
           58  +do_execsql_test 2.0 {
           59  +  CREATE TABLE t2(a, b, c);
           60  +  CREATE INDEX i2 ON t2(a, b);
           61  +  INSERT INTO t2 VALUES(1, 1, 1);
           62  +  INSERT INTO t2 VALUES(1, NULL, 2);
           63  +  INSERT INTO t2 VALUES(1, NULL, 3);
           64  +  INSERT INTO t2 VALUES(1, 4, 4);
           65  +}
           66  +
           67  +do_execsql_test 2.1 {
           68  +  SELECT * FROM t2 WHERE a=1 ORDER BY b NULLS LAST
           69  +} {
           70  +  1 1 1    1 4 4   1 {} 2   1 {} 3
           71  +}
           72  +
           73  +do_execsql_test 2.2 {
           74  +  SELECT * FROM t2 WHERE a=1 ORDER BY b DESC NULLS FIRST
           75  +} {
           76  +  1 {} 3
           77  +  1 {} 2     
           78  +  1 4 4     
           79  +  1 1 1
           80  +}
           81  +
           82  +#-------------------------------------------------------------------------
           83  +#
           84  +reset_db
           85  +do_execsql_test 3.0 {
           86  +  CREATE TABLE t1(a, b, c, d, UNIQUE (b));
           87  +}
           88  +foreach {tn sql err}  {
           89  +  1 { CREATE INDEX i1 ON t1(a ASC NULLS LAST) }           LAST
           90  +  2 { CREATE INDEX i1 ON t1(a ASC NULLS FIRST) }          FIRST
           91  +  3 { CREATE INDEX i1 ON t1(a, b ASC NULLS LAST) }        LAST
           92  +  4 { CREATE INDEX i1 ON t1(a, b ASC NULLS FIRST) }       FIRST
           93  +  5 { CREATE INDEX i1 ON t1(a DESC NULLS LAST) }          LAST
           94  +  6 { CREATE INDEX i1 ON t1(a DESC NULLS FIRST) }         FIRST
           95  +  7 { CREATE INDEX i1 ON t1(a, b DESC NULLS LAST) }       LAST
           96  +  8 { CREATE INDEX i1 ON t1(a, b DESC NULLS FIRST) }      FIRST
           97  +  9  { CREATE TABLE t2(a, b, PRIMARY KEY(a DESC, b NULLS FIRST)) } FIRST
           98  +  10 { CREATE TABLE t2(a, b, UNIQUE(a DESC NULLS FIRST, b)) }      FIRST
           99  +  11 { INSERT INTO t1 VALUES(1, 2, 3, 4)
          100  +          ON CONFLICT (b DESC NULLS LAST) DO UPDATE SET a = a+1 } LAST
          101  +  12 {
          102  +    CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
          103  +      INSERT INTO t1 VALUES(1, 2, 3, 4)
          104  +      ON CONFLICT (b DESC NULLS FIRST) DO UPDATE SET a = a+1;
          105  +    END
          106  +  } FIRST
          107  +} {
          108  +  do_catchsql_test 3.1.$tn $sql "1 {unsupported use of NULLS $err}"
          109  +}
          110  +
          111  +do_execsql_test 3.2 {
          112  +  CREATE TABLE first(nulls, last);
          113  +  INSERT INTO first(last, nulls) VALUES(100,200), (300,400), (200,300);
          114  +  SELECT * FROM first ORDER BY nulls;
          115  +} {
          116  +  200 100
          117  +  300 200
          118  +  400 300
          119  +}
          120  +
          121  +#-------------------------------------------------------------------------
          122  +#
          123  +ifcapable vtab {
          124  +  register_echo_module db
          125  +  do_execsql_test 4.0 {
          126  +    CREATE TABLE tx(a INTEGER PRIMARY KEY, b, c);
          127  +    CREATE INDEX i1 ON tx(b);
          128  +    INSERT INTO tx VALUES(1, 1, 1);
          129  +    INSERT INTO tx VALUES(2, NULL, 2);
          130  +    INSERT INTO tx VALUES(3, 3, 3);
          131  +    INSERT INTO tx VALUES(4, NULL, 4);
          132  +    INSERT INTO tx VALUES(5, 5, 5);
          133  +    CREATE VIRTUAL TABLE te USING echo(tx);
          134  +  }
          135  +
          136  +  do_execsql_test 4.1 {
          137  +    SELECT * FROM tx ORDER BY b NULLS FIRST;
          138  +  } {2 {} 2  4 {} 4  1 1 1  3 3 3  5 5 5}
          139  +  do_execsql_test 4.2 {
          140  +    SELECT * FROM te ORDER BY b NULLS FIRST;
          141  +  } {2 {} 2  4 {} 4  1 1 1  3 3 3  5 5 5}
          142  +
          143  +  do_execsql_test 4.3 {
          144  +    SELECT * FROM tx ORDER BY b NULLS LAST;
          145  +  } {1 1 1  3 3 3  5 5 5  2 {} 2  4 {} 4}
          146  +  do_execsql_test 4.4 {
          147  +    SELECT * FROM te ORDER BY b NULLS LAST;
          148  +  } {1 1 1  3 3 3  5 5 5  2 {} 2  4 {} 4}
          149  +}
          150  +
          151  +#-------------------------------------------------------------------------
          152  +#
          153  +do_execsql_test 5.0 {
          154  +  CREATE TABLE t4(a, b, c);
          155  +  INSERT INTO t4 VALUES(1, 1, 11);
          156  +  INSERT INTO t4 VALUES(1, 2, 12);
          157  +  INSERT INTO t4 VALUES(1, NULL, 1);
          158  +
          159  +  INSERT INTO t4 VALUES(2, NULL, 1);
          160  +  INSERT INTO t4 VALUES(2, 2, 12);
          161  +  INSERT INTO t4 VALUES(2, 1, 11);
          162  +
          163  +  INSERT INTO t4 VALUES(3, NULL, 1);
          164  +  INSERT INTO t4 VALUES(3, 2, 12);
          165  +  INSERT INTO t4 VALUES(3, NULL, 3);
          166  +}
          167  +
          168  +do_execsql_test 5.1 {
          169  +  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a, b NULLS LAST
          170  +} {
          171  +  1 1 11   1 2 12   1 {} 1   
          172  +  2 1 11   2 2 12   2 {} 1 
          173  +  3 2 12   3 {} 1   3 {} 3
          174  +}
          175  +do_execsql_test 5.2 {
          176  +  CREATE INDEX t4ab ON t4(a, b);
          177  +  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a, b NULLS LAST
          178  +} {
          179  +  1 1 11   1 2 12   1 {} 1   
          180  +  2 1 11   2 2 12   2 {} 1 
          181  +  3 2 12   3 {} 1   3 {} 3
          182  +}
          183  +do_eqp_test 5.3 {
          184  +  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a, b NULLS LAST
          185  +} {
          186  +  QUERY PLAN
          187  +  `--SEARCH TABLE t4 USING INDEX t4ab (a=?)
          188  +}
          189  +
          190  +do_execsql_test 5.4 {
          191  +  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a DESC, b DESC NULLS FIRST
          192  +} {
          193  +  3 {} 3   3 {} 1   3 2 12   
          194  +  2 {} 1   2 2 12   2 1 11   
          195  +  1 {} 1   1 2 12   1 1 11   
          196  +}
          197  +do_eqp_test 5.5 {
          198  +  SELECT * FROM t4 WHERE a IN (1, 2, 3) ORDER BY a DESC, b DESC NULLS FIRST
          199  +} {
          200  +  QUERY PLAN
          201  +  `--SEARCH TABLE t4 USING INDEX t4ab (a=?)
          202  +}
          203  +
          204  +#-------------------------------------------------------------------------
          205  +#
          206  +do_execsql_test 6.0 {
          207  +  CREATE TABLE t5(a, b, c);
          208  +  WITH s(i) AS (
          209  +    VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<200
          210  +  ) 
          211  +  INSERT INTO t5 SELECT i%2, CASE WHEN (i%10)==0 THEN NULL ELSE i END, i FROM s;
          212  +}
          213  +
          214  +set res1 [db eval { SELECT a,b FROM t5 WHERE a=1 ORDER BY b NULLS LAST, c }]
          215  +set res2 [db eval { 
          216  +  SELECT a,b FROM t5 WHERE a=1 ORDER BY b DESC NULLS FIRST, c DESC 
          217  +}]
          218  +
          219  +do_execsql_test 6.1.1 {
          220  +  CREATE INDEX t5ab ON t5(a, b, c);
          221  +  SELECT a,b FROM t5 WHERE a=1 ORDER BY b NULLS LAST, c;
          222  +} $res1
          223  +do_eqp_test 6.1.2 {
          224  +  SELECT a,b FROM t5 WHERE a=1 ORDER BY b NULLS LAST, c;
          225  +} {
          226  +  QUERY PLAN
          227  +  `--SEARCH TABLE t5 USING COVERING INDEX t5ab (a=?)
          228  +}
          229  +do_execsql_test 6.2.1 {
          230  +  SELECT a,b FROM t5 WHERE a=1 ORDER BY b DESC NULLS FIRST, c DESC 
          231  +} $res2
          232  +do_eqp_test 6.2.2 {
          233  +  SELECT a,b FROM t5 WHERE a=1 ORDER BY b DESC NULLS FIRST, c DESC 
          234  +} {
          235  +  QUERY PLAN
          236  +  `--SEARCH TABLE t5 USING COVERING INDEX t5ab (a=?)
          237  +}
          238  +
          239  +
          240  +finish_test
          241  +
          242  +

Changes to test/pg_common.tcl.

    66     66   
    67     67     set ret
    68     68   }
    69     69   
    70     70   proc execsql_test {tn sql} {
    71     71     set res [execsql $sql]
    72     72     set sql [string map {string_agg group_concat} $sql]
    73         -  set sql [string map [list {NULLS FIRST} {}] $sql]
    74         -  set sql [string map [list {NULLS LAST} {}] $sql]
           73  +  # set sql [string map [list {NULLS FIRST} {}] $sql]
           74  +  # set sql [string map [list {NULLS LAST} {}] $sql]
    75     75     puts $::fd "do_execsql_test $tn {"
    76     76     puts $::fd "  [string trim $sql]"
    77     77     puts $::fd "} {$res}"
    78     78     puts $::fd ""
    79     79   }
    80     80   
    81     81   proc errorsql_test {tn sql} {

Changes to test/window7.test.

    37     37       (1, 81), (2, 82), (3, 83), (4, 84), (5, 85), (6, 86), (7, 87), (8, 88), 
    38     38       (9, 89), (0, 90), (1, 91), (2, 92), (3, 93), (4, 94), (5, 95), (6, 96), 
    39     39       (7, 97), (8, 98), (9, 99), (0, 100);
    40     40   } {}
    41     41   
    42     42   do_execsql_test 1.1 {
    43     43     SELECT a, sum(b) FROM t3 GROUP BY a ORDER BY 1;
    44         -} {0 550   1 460   2 470   3 480   4 490   5 500   6 510   7 520   8 530   9 540}
           44  +} {0 550   1 460   2 470   3 480   4 490   5 500   6 510   7 520   8 530
           45  +  9 540}
    45     46   
    46     47   do_execsql_test 1.2 {
    47     48     SELECT a, sum(b) OVER (
    48     49       ORDER BY a GROUPS BETWEEN CURRENT ROW AND CURRENT ROW
    49     50     ) FROM t3 ORDER BY 1;
    50         -} {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}
           51  +} {0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550
           52  +  0 550   1 460   1 460   1 460   1 460   1 460   1 460   1 460   1 460
           53  +  1 460   1 460   2 470   2 470   2 470   2 470   2 470   2 470   2 470
           54  +  2 470   2 470   2 470   3 480   3 480   3 480   3 480   3 480   3 480
           55  +  3 480   3 480   3 480   3 480   4 490   4 490   4 490   4 490   4 490
           56  +  4 490   4 490   4 490   4 490   4 490   5 500   5 500   5 500   5 500
           57  +  5 500   5 500   5 500   5 500   5 500   5 500   6 510   6 510   6 510
           58  +  6 510   6 510   6 510   6 510   6 510   6 510   6 510   7 520   7 520
           59  +  7 520   7 520   7 520   7 520   7 520   7 520   7 520   7 520   8 530
           60  +  8 530   8 530   8 530   8 530   8 530   8 530   8 530   8 530   8 530
           61  +  9 540   9 540   9 540   9 540   9 540   9 540   9 540   9 540   9 540
           62  +  9 540}
    51     63   
    52     64   do_execsql_test 1.3 {
    53     65     SELECT a, sum(b) OVER (
    54     66       ORDER BY a GROUPS BETWEEN 0 PRECEDING AND 0 FOLLOWING
    55     67     ) FROM t3 ORDER BY 1;
    56         -} {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}
           68  +} {0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550
           69  +  0 550   1 460   1 460   1 460   1 460   1 460   1 460   1 460   1 460
           70  +  1 460   1 460   2 470   2 470   2 470   2 470   2 470   2 470   2 470
           71  +  2 470   2 470   2 470   3 480   3 480   3 480   3 480   3 480   3 480
           72  +  3 480   3 480   3 480   3 480   4 490   4 490   4 490   4 490   4 490
           73  +  4 490   4 490   4 490   4 490   4 490   5 500   5 500   5 500   5 500
           74  +  5 500   5 500   5 500   5 500   5 500   5 500   6 510   6 510   6 510
           75  +  6 510   6 510   6 510   6 510   6 510   6 510   6 510   7 520   7 520
           76  +  7 520   7 520   7 520   7 520   7 520   7 520   7 520   7 520   8 530
           77  +  8 530   8 530   8 530   8 530   8 530   8 530   8 530   8 530   8 530
           78  +  9 540   9 540   9 540   9 540   9 540   9 540   9 540   9 540   9 540
           79  +  9 540}
    57     80   
    58     81   do_execsql_test 1.4 {
    59     82     SELECT a, sum(b) OVER (
    60     83       ORDER BY a GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING
    61     84     ) FROM t3 ORDER BY 1;
    62         -} {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}
           85  +} {0 1480   0 1480   0 1480   0 1480   0 1480   0 1480   0 1480   0 1480
           86  +  0 1480   0 1480   1 1960   1 1960   1 1960   1 1960   1 1960   1 1960
           87  +  1 1960   1 1960   1 1960   1 1960   2 2450   2 2450   2 2450   2 2450
           88  +  2 2450   2 2450   2 2450   2 2450   2 2450   2 2450   3 2400   3 2400
           89  +  3 2400   3 2400   3 2400   3 2400   3 2400   3 2400   3 2400   3 2400
           90  +  4 2450   4 2450   4 2450   4 2450   4 2450   4 2450   4 2450   4 2450
           91  +  4 2450   4 2450   5 2500   5 2500   5 2500   5 2500   5 2500   5 2500
           92  +  5 2500   5 2500   5 2500   5 2500   6 2550   6 2550   6 2550   6 2550
           93  +  6 2550   6 2550   6 2550   6 2550   6 2550   6 2550   7 2600   7 2600
           94  +  7 2600   7 2600   7 2600   7 2600   7 2600   7 2600   7 2600   7 2600
           95  +  8 2100   8 2100   8 2100   8 2100   8 2100   8 2100   8 2100   8 2100
           96  +  8 2100   8 2100   9 1590   9 1590   9 1590   9 1590   9 1590   9 1590
           97  +  9 1590   9 1590   9 1590   9 1590}
    63     98   
    64     99   do_execsql_test 1.5 {
    65    100     SELECT a, sum(b) OVER (
    66    101       ORDER BY a RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING
    67    102     ) FROM t3 ORDER BY 1;
    68         -} {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}
          103  +} {0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550
          104  +  0 550   1 460   1 460   1 460   1 460   1 460   1 460   1 460   1 460
          105  +  1 460   1 460   2 470   2 470   2 470   2 470   2 470   2 470   2 470
          106  +  2 470   2 470   2 470   3 480   3 480   3 480   3 480   3 480   3 480
          107  +  3 480   3 480   3 480   3 480   4 490   4 490   4 490   4 490   4 490
          108  +  4 490   4 490   4 490   4 490   4 490   5 500   5 500   5 500   5 500
          109  +  5 500   5 500   5 500   5 500   5 500   5 500   6 510   6 510   6 510
          110  +  6 510   6 510   6 510   6 510   6 510   6 510   6 510   7 520   7 520
          111  +  7 520   7 520   7 520   7 520   7 520   7 520   7 520   7 520   8 530
          112  +  8 530   8 530   8 530   8 530   8 530   8 530   8 530   8 530   8 530
          113  +  9 540   9 540   9 540   9 540   9 540   9 540   9 540   9 540   9 540
          114  +  9 540}
    69    115   
    70    116   do_execsql_test 1.6 {
    71    117     SELECT a, sum(b) OVER (
    72    118       ORDER BY a RANGE BETWEEN 2 PRECEDING AND 2 FOLLOWING
    73    119     ) FROM t3 ORDER BY 1;
    74         -} {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}
          120  +} {0 1480   0 1480   0 1480   0 1480   0 1480   0 1480   0 1480   0 1480
          121  +  0 1480   0 1480   1 1960   1 1960   1 1960   1 1960   1 1960   1 1960
          122  +  1 1960   1 1960   1 1960   1 1960   2 2450   2 2450   2 2450   2 2450
          123  +  2 2450   2 2450   2 2450   2 2450   2 2450   2 2450   3 2400   3 2400
          124  +  3 2400   3 2400   3 2400   3 2400   3 2400   3 2400   3 2400   3 2400
          125  +  4 2450   4 2450   4 2450   4 2450   4 2450   4 2450   4 2450   4 2450
          126  +  4 2450   4 2450   5 2500   5 2500   5 2500   5 2500   5 2500   5 2500
          127  +  5 2500   5 2500   5 2500   5 2500   6 2550   6 2550   6 2550   6 2550
          128  +  6 2550   6 2550   6 2550   6 2550   6 2550   6 2550   7 2600   7 2600
          129  +  7 2600   7 2600   7 2600   7 2600   7 2600   7 2600   7 2600   7 2600
          130  +  8 2100   8 2100   8 2100   8 2100   8 2100   8 2100   8 2100   8 2100
          131  +  8 2100   8 2100   9 1590   9 1590   9 1590   9 1590   9 1590   9 1590
          132  +  9 1590   9 1590   9 1590   9 1590}
    75    133   
    76    134   do_execsql_test 1.7 {
    77    135     SELECT a, sum(b) OVER (
    78    136       ORDER BY a RANGE BETWEEN 2 PRECEDING AND 1 FOLLOWING
    79    137     ) FROM t3 ORDER BY 1;
    80         -} {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}
          138  +} {0 1010   0 1010   0 1010   0 1010   0 1010   0 1010   0 1010   0 1010
          139  +  0 1010   0 1010   1 1480   1 1480   1 1480   1 1480   1 1480   1 1480
          140  +  1 1480   1 1480   1 1480   1 1480   2 1960   2 1960   2 1960   2 1960
          141  +  2 1960   2 1960   2 1960   2 1960   2 1960   2 1960   3 1900   3 1900
          142  +  3 1900   3 1900   3 1900   3 1900   3 1900   3 1900   3 1900   3 1900
          143  +  4 1940   4 1940   4 1940   4 1940   4 1940   4 1940   4 1940   4 1940
          144  +  4 1940   4 1940   5 1980   5 1980   5 1980   5 1980   5 1980   5 1980
          145  +  5 1980   5 1980   5 1980   5 1980   6 2020   6 2020   6 2020   6 2020
          146  +  6 2020   6 2020   6 2020   6 2020   6 2020   6 2020   7 2060   7 2060
          147  +  7 2060   7 2060   7 2060   7 2060   7 2060   7 2060   7 2060   7 2060
          148  +  8 2100   8 2100   8 2100   8 2100   8 2100   8 2100   8 2100   8 2100
          149  +  8 2100   8 2100   9 1590   9 1590   9 1590   9 1590   9 1590   9 1590
          150  +  9 1590   9 1590   9 1590   9 1590}
    81    151   
    82    152   do_execsql_test 1.8.1 {
    83    153     SELECT a, sum(b) OVER (
    84    154       ORDER BY a RANGE BETWEEN 0 PRECEDING AND 1 FOLLOWING
    85    155     ) FROM t3 ORDER BY 1;
    86         -} {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}
          156  +} {0 1010   0 1010   0 1010   0 1010   0 1010   0 1010   0 1010   0 1010
          157  +  0 1010   0 1010   1 930   1 930   1 930   1 930   1 930   1 930   1 930
          158  +  1 930   1 930   1 930   2 950   2 950   2 950   2 950   2 950   2 950
          159  +  2 950   2 950   2 950   2 950   3 970   3 970   3 970   3 970   3 970
          160  +  3 970   3 970   3 970   3 970   3 970   4 990   4 990   4 990   4 990
          161  +  4 990   4 990   4 990   4 990   4 990   4 990   5 1010   5 1010   5 1010
          162  +  5 1010   5 1010   5 1010   5 1010   5 1010   5 1010   5 1010   6 1030
          163  +  6 1030   6 1030   6 1030   6 1030   6 1030   6 1030   6 1030   6 1030
          164  +  6 1030   7 1050   7 1050   7 1050   7 1050   7 1050   7 1050   7 1050
          165  +  7 1050   7 1050   7 1050   8 1070   8 1070   8 1070   8 1070   8 1070
          166  +  8 1070   8 1070   8 1070   8 1070   8 1070   9 540   9 540   9 540   9 540
          167  +  9 540   9 540   9 540   9 540   9 540   9 540}
    87    168   
    88    169   do_execsql_test 1.8.2 {
    89    170     SELECT a, sum(b) OVER (
    90    171       ORDER BY a DESC RANGE BETWEEN 0 PRECEDING AND 1 FOLLOWING
    91    172     ) FROM t3 ORDER BY 1;
    92         -} {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}
          173  +} {0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550   0 550
          174  +  0 550   1 1010   1 1010   1 1010   1 1010   1 1010   1 1010   1 1010
          175  +  1 1010   1 1010   1 1010   2 930   2 930   2 930   2 930   2 930   2 930
          176  +  2 930   2 930   2 930   2 930   3 950   3 950   3 950   3 950   3 950
          177  +  3 950   3 950   3 950   3 950   3 950   4 970   4 970   4 970   4 970
          178  +  4 970   4 970   4 970   4 970   4 970   4 970   5 990   5 990   5 990
          179  +  5 990   5 990   5 990   5 990   5 990   5 990   5 990   6 1010   6 1010
          180  +  6 1010   6 1010   6 1010   6 1010   6 1010   6 1010   6 1010   6 1010
          181  +  7 1030   7 1030   7 1030   7 1030   7 1030   7 1030   7 1030   7 1030
          182  +  7 1030   7 1030   8 1050   8 1050   8 1050   8 1050   8 1050   8 1050
          183  +  8 1050   8 1050   8 1050   8 1050   9 1070   9 1070   9 1070   9 1070
          184  +  9 1070   9 1070   9 1070   9 1070   9 1070   9 1070}
    93    185   
    94    186   finish_test

Changes to test/window8.tcl.

   193    193   }
   194    194   
   195    195   execsql_test 4.2.1 {
   196    196     SELECT sum(b) OVER (
   197    197       ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
   198    198     ) FROM t1 ORDER BY 1 NULLS FIRST;
   199    199   }
   200         -
   201    200   execsql_test 4.2.2 {
          201  +  SELECT sum(b) OVER (
          202  +    ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
          203  +  ) FROM t1 ORDER BY 1 NULLS LAST;
          204  +}
          205  +
          206  +execsql_test 4.2.3 {
   202    207     SELECT sum(b) OVER (
   203    208       ORDER BY a DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
   204    209     ) FROM t1 ORDER BY 1 NULLS FIRST;
   205    210   }
          211  +execsql_test 4.2.4 {
          212  +  SELECT sum(b) OVER (
          213  +    ORDER BY a DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
          214  +  ) FROM t1 ORDER BY 1 NULLS LAST;
          215  +}
   206    216   
   207    217   execsql_test 4.3.1 {
   208    218     SELECT sum(b) OVER (
   209    219       ORDER BY a NULLS FIRST RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
   210    220     ) FROM t1 ORDER BY 1 NULLS FIRST;
   211    221   }
          222  +execsql_test 4.3.2 {
          223  +  SELECT sum(b) OVER (
          224  +    ORDER BY a NULLS LAST RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
          225  +  ) FROM t1 ORDER BY 1 NULLS LAST;
          226  +}
   212    227   
   213    228   execsql_test 4.4.1 {
   214    229     SELECT sum(b) OVER (
   215    230       ORDER BY a NULLS FIRST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
   216    231     ) FROM t1 ORDER BY 1 NULLS FIRST;
   217    232   }
   218         -
   219    233   execsql_test 4.4.2 {
          234  +  SELECT sum(b) OVER (
          235  +    ORDER BY a NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
          236  +  ) FROM t1 ORDER BY 1 NULLS LAST;
          237  +}
          238  +
          239  +execsql_test 4.4.3 {
   220    240     SELECT sum(b) OVER (
   221    241       ORDER BY a DESC NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
   222    242     ) FROM t1 ORDER BY 1 NULLS FIRST;
   223    243   }
          244  +execsql_test 4.4.4 {
          245  +  SELECT sum(b) OVER (
          246  +    ORDER BY a DESC NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
          247  +  ) FROM t1 ORDER BY 1 NULLS LAST;
          248  +}
   224    249   
   225    250   ==========
   226    251   
   227    252   execsql_test 5.0 {
   228    253     INSERT INTO t3 VALUES
   229    254       (NULL, 'bb', 355), (NULL, 'cc', 158), (NULL, 'aa', 399), 
   230    255       ('JJ', NULL, 839), ('FF', NULL, 618), ('BB', NULL, 393), 
................................................................................
   244    269       3 { PARTITION BY coalesce(a, '') 
   245    270           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
   246    271       4 { ORDER BY a NULLS FIRST GROUPS 6 PRECEDING }
   247    272       5 { ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING }
   248    273       6 { ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING }
   249    274       7 { ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
   250    275           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING }
          276  +
          277  +    8 { RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
          278  +    9 { ORDER BY a NULLS LAST 
          279  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
          280  +   10 { PARTITION BY coalesce(a, '') 
          281  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING }
          282  +   11 { ORDER BY a NULLS LAST GROUPS 6 PRECEDING }
          283  +   12 { ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING }
          284  +   13 { ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING }
          285  +   14 { ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
          286  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING }
   251    287     } {
   252    288       execsql_test 5.$tn.$tn2.1 "
   253    289         SELECT max(c) OVER win,
   254    290                min(c) OVER win,
   255    291                count(a) OVER win
   256    292         FROM t3
   257    293         WINDOW win AS ( $frame $ex )
................................................................................
   288    324   
   289    325   execsql_test 6.2 {
   290    326     SELECT string_agg(a, '.') OVER (
   291    327       ORDER BY b DESC NULLS LAST RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
   292    328     )
   293    329     FROM t2
   294    330   }
          331  +
   295    332   
   296    333   
   297    334   finish_test
   298    335   
   299    336   

Changes to test/window8.test.

  3518   3518       ORDER BY a DESC RANGE BETWEEN 5 PRECEDING AND 10 FOLLOWING
  3519   3519     ) FROM t1 ORDER BY 1;
  3520   3520   } {6   6   6   9   9}
  3521   3521   
  3522   3522   do_execsql_test 4.2.1 {
  3523   3523     SELECT sum(b) OVER (
  3524   3524       ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
  3525         -  ) FROM t1 ORDER BY 1 ;
         3525  +  ) FROM t1 ORDER BY 1 NULLS FIRST;
  3526   3526   } {{}   {}   6   6   6}
  3527   3527   
  3528   3528   do_execsql_test 4.2.2 {
         3529  +  SELECT sum(b) OVER (
         3530  +    ORDER BY a RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
         3531  +  ) FROM t1 ORDER BY 1 NULLS LAST;
         3532  +} {6   6   6   {}   {}}
         3533  +
         3534  +do_execsql_test 4.2.3 {
  3529   3535     SELECT sum(b) OVER (
  3530   3536       ORDER BY a DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
  3531         -  ) FROM t1 ORDER BY 1 ;
         3537  +  ) FROM t1 ORDER BY 1 NULLS FIRST;
  3532   3538   } {{}   {}   6   6   6}
         3539  +
         3540  +do_execsql_test 4.2.4 {
         3541  +  SELECT sum(b) OVER (
         3542  +    ORDER BY a DESC RANGE BETWEEN 5 FOLLOWING AND 10 FOLLOWING
         3543  +  ) FROM t1 ORDER BY 1 NULLS LAST;
         3544  +} {6   6   6   {}   {}}
  3533   3545   
  3534   3546   do_execsql_test 4.3.1 {
  3535   3547     SELECT sum(b) OVER (
  3536         -    ORDER BY a  RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
  3537         -  ) FROM t1 ORDER BY 1 ;
         3548  +    ORDER BY a NULLS FIRST RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
         3549  +  ) FROM t1 ORDER BY 1 NULLS FIRST;
  3538   3550   } {6   6   6   15   15}
  3539   3551   
         3552  +do_execsql_test 4.3.2 {
         3553  +  SELECT sum(b) OVER (
         3554  +    ORDER BY a NULLS LAST RANGE BETWEEN UNBOUNDED PRECEDING AND 10 FOLLOWING
         3555  +  ) FROM t1 ORDER BY 1 NULLS LAST;
         3556  +} {9   9   15   15   15}
         3557  +
  3540   3558   do_execsql_test 4.4.1 {
  3541   3559     SELECT sum(b) OVER (
  3542         -    ORDER BY a  ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
  3543         -  ) FROM t1 ORDER BY 1 ;
         3560  +    ORDER BY a NULLS FIRST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
         3561  +  ) FROM t1 ORDER BY 1 NULLS FIRST;
  3544   3562   } {3   6   9   9   12}
  3545   3563   
  3546   3564   do_execsql_test 4.4.2 {
  3547   3565     SELECT sum(b) OVER (
  3548         -    ORDER BY a DESC  ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
  3549         -  ) FROM t1 ORDER BY 1 ;
         3566  +    ORDER BY a NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
         3567  +  ) FROM t1 ORDER BY 1 NULLS LAST;
         3568  +} {5   6   8   9   10}
         3569  +
         3570  +do_execsql_test 4.4.3 {
         3571  +  SELECT sum(b) OVER (
         3572  +    ORDER BY a DESC NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
         3573  +  ) FROM t1 ORDER BY 1 NULLS FIRST;
         3574  +} {5   6   8   9   10}
         3575  +
         3576  +do_execsql_test 4.4.4 {
         3577  +  SELECT sum(b) OVER (
         3578  +    ORDER BY a DESC NULLS LAST ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
         3579  +  ) FROM t1 ORDER BY 1 NULLS LAST;
  3550   3580   } {5   6   8   9   10}
  3551   3581   
  3552   3582   #==========================================================================
  3553   3583   
  3554   3584   do_execsql_test 5.0 {
  3555   3585     INSERT INTO t3 VALUES
  3556   3586       (NULL, 'bb', 355), (NULL, 'cc', 158), (NULL, 'aa', 399), 
................................................................................
  3560   3590   
  3561   3591   do_execsql_test 5.1.1.1 {
  3562   3592     SELECT max(c) OVER win,
  3563   3593                min(c) OVER win,
  3564   3594                count(a) OVER win
  3565   3595         FROM t3
  3566   3596         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3567         -      ORDER BY 1 , 2 , 3
         3597  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3568   3598   } {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  3569   3599     979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  3570   3600     979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  3571   3601     979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  3572   3602     979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  3573   3603     979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  3574   3604     979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
................................................................................
  3583   3613   
  3584   3614   do_execsql_test 5.1.1.2 {
  3585   3615     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3586   3616                rank() OVER win,
  3587   3617                dense_rank() OVER win
  3588   3618         FROM t3
  3589   3619         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3590         -      ORDER BY 1 , 2 , 3
         3620  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3591   3621   } {23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  3592   3622     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  3593   3623     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  3594   3624     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  3595   3625     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  3596   3626     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
  3597   3627     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
................................................................................
  3605   3635     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}
  3606   3636   
  3607   3637   do_execsql_test 5.1.2.1 {
  3608   3638     SELECT max(c) OVER win,
  3609   3639                min(c) OVER win,
  3610   3640                count(a) OVER win
  3611   3641         FROM t3
  3612         -      WINDOW win AS (  ORDER BY a  
         3642  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  3613   3643           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3614         -      ORDER BY 1 , 2 , 3
         3644  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3615   3645   } {899 113 9   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
  3616   3646     899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  3617   3647     899 113 16   899 113 16   899 113 16   899 113 16   979 102 44   979 102 44
  3618   3648     979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 44
  3619   3649     979 102 44   979 102 44   979 102 44   979 102 49   979 102 49   979 102 49
  3620   3650     979 102 49   979 102 49   979 102 56   979 102 56   979 102 56   979 102 56
  3621   3651     979 102 56   979 102 56   979 102 56   979 102 62   979 102 62   979 102 62
................................................................................
  3629   3659     979 113 33   979 113 33   979 113 33   979 113 33   979 113 33}
  3630   3660   
  3631   3661   do_execsql_test 5.1.2.2 {
  3632   3662     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3633   3663                rank() OVER win,
  3634   3664                dense_rank() OVER win
  3635   3665         FROM t3
  3636         -      WINDOW win AS (  ORDER BY a  
         3666  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  3637   3667           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3638         -      ORDER BY 1 , 2 , 3
         3668  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3639   3669   } {2947 81 11   2947 81 11   2947 81 11   2947 81 11   2947 81 11   2947 81 11
  3640   3670     2947 81 11   2947 81 11   2947 81 11   5287 74 10   5287 74 10   5287 74 10
  3641   3671     5287 74 10   5287 74 10   5287 74 10   5287 74 10   8400 65 9   8400 65 9
  3642   3672     8400 65 9   8400 65 9   8400 65 9   8400 65 9   8400 65 9   8400 65 9
  3643   3673     8400 65 9   9664 57 8   9664 57 8   9664 57 8   9664 57 8   9664 57 8
  3644   3674     9664 57 8   9664 57 8   9664 57 8   10626 46 7   10626 46 7   10626 46 7
  3645   3675     10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7
................................................................................
  3655   3685   do_execsql_test 5.1.3.1 {
  3656   3686     SELECT max(c) OVER win,
  3657   3687                min(c) OVER win,
  3658   3688                count(a) OVER win
  3659   3689         FROM t3
  3660   3690         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  3661   3691           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3662         -      ORDER BY 1 , 2 , 3
         3692  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3663   3693   } {777 113 5   777 113 5   777 113 5   777 113 5   777 113 5   805 250 7
  3664   3694     805 250 7   805 250 7   805 250 7   805 250 7   805 250 7   805 250 7
  3665   3695     822 158 6   822 158 6   822 158 6   822 158 6   822 158 6   822 158 6
  3666   3696     840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  3667   3697     840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
  3668   3698     840 247 13   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  3669   3699     870 158 0   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
................................................................................
  3679   3709   do_execsql_test 5.1.3.2 {
  3680   3710     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3681   3711                rank() OVER win,
  3682   3712                dense_rank() OVER win
  3683   3713         FROM t3
  3684   3714         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  3685   3715           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3686         -      ORDER BY 1 , 2 , 3
         3716  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3687   3717   } {962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  3688   3718     962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1   1264 1 1
  3689   3719     1264 1 1   1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1
  3690   3720     1366 1 1   1366 1 1   1366 1 1   1366 1 1   1519 1 1   1519 1 1   1519 1 1
  3691   3721     1519 1 1   1519 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1
  3692   3722     1804 1 1   1804 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1
  3693   3723     2050 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1
................................................................................
  3699   3729     3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}
  3700   3730   
  3701   3731   do_execsql_test 5.1.4.1 {
  3702   3732     SELECT max(c) OVER win,
  3703   3733                min(c) OVER win,
  3704   3734                count(a) OVER win
  3705   3735         FROM t3
  3706         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
  3707         -      ORDER BY 1 , 2 , 3
         3736  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
         3737  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3708   3738   } {870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  3709   3739     934 158 8   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  3710   3740     934 158 8   934 158 8   934 158 21   934 158 21   934 158 21   934 158 21
  3711   3741     934 158 21   934 158 21   934 158 21   934 158 21   934 158 21   934 158 21
  3712   3742     934 158 21   934 158 21   934 158 21   934 158 27   934 158 27   934 158 27
  3713   3743     934 158 27   934 158 27   934 158 27   959 102 50   959 102 50   959 102 50
  3714   3744     959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
................................................................................
  3722   3752     979 102 59   979 102 59   979 102 59   979 102 59   979 102 59}
  3723   3753   
  3724   3754   do_execsql_test 5.1.4.2 {
  3725   3755     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3726   3756                rank() OVER win,
  3727   3757                dense_rank() OVER win
  3728   3758         FROM t3
  3729         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
  3730         -      ORDER BY 1 , 2 , 3
         3759  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
         3760  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3731   3761   } {2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   4359 7 2
  3732   3762     4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2   4359 7 2
  3733   3763     7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  3734   3764     7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  3735   3765     7840 15 3   9206 28 4   9206 28 4   9206 28 4   9206 28 4   9206 28 4
  3736   3766     9206 28 4   11010 34 5   11010 34 5   11010 34 5   11010 34 5   11010 34 5
  3737   3767     11010 34 5   11010 34 5   12368 74 10   12368 74 10   12368 74 10
................................................................................
  3746   3776     13949 81 11}
  3747   3777   
  3748   3778   do_execsql_test 5.1.5.1 {
  3749   3779     SELECT max(c) OVER win,
  3750   3780                min(c) OVER win,
  3751   3781                count(a) OVER win
  3752   3782         FROM t3
  3753         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
  3754         -      ORDER BY 1 , 2 , 3
         3783  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
         3784  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3755   3785   } {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   160 158 2
  3756   3786     160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  3757   3787     239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  3758   3788     257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  3759   3789     346 346 1   355 354 2   355 354 2   355 354 2   399 393 4   399 393 4
  3760   3790     399 393 4   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  3761   3791     443 443 1   480 480 2   480 480 2   574 572 2   574 572 2   607 607 1
................................................................................
  3769   3799     938 934 3   938 934 3   963 959 2   963 959 2   979 979 1}
  3770   3800   
  3771   3801   do_execsql_test 5.1.5.2 {
  3772   3802     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3773   3803                rank() OVER win,
  3774   3804                dense_rank() OVER win
  3775   3805         FROM t3
  3776         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
  3777         -      ORDER BY 1 , 2 , 3
         3806  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
         3807  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3778   3808   } {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  3779   3809     {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  3780   3810     {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  3781   3811     {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  3782   3812     {} 85 72   133 4 3   223 10 8   223 11 9   226 2 2   226 2 2   239 12 10
  3783   3813     239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  3784   3814     309 21 19   335 22 20   335 23 21   335 24 22   421 35 30   443 37 32
................................................................................
  3791   3821     2523 73 63   2523 73 63   2523 75 64   2523 76 65   2523 77 66}
  3792   3822   
  3793   3823   do_execsql_test 5.1.6.1 {
  3794   3824     SELECT max(c) OVER win,
  3795   3825                min(c) OVER win,
  3796   3826                count(a) OVER win
  3797   3827         FROM t3
  3798         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
  3799         -      ORDER BY 1 , 2 , 3
         3828  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
         3829  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3800   3830   } {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   158 158 1
  3801   3831     158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  3802   3832     238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  3803   3833     257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  3804   3834     346 346 1   354 354 1   355 355 1   355 355 1   393 393 2   393 393 2
  3805   3835     398 398 1   399 399 1   399 399 1   412 412 1   421 421 1   430 430 1
  3806   3836     443 443 1   480 480 2   480 480 2   572 572 1   574 574 1   607 607 1
................................................................................
  3814   3844     938 938 2   938 938 2   959 959 1   963 963 1   979 979 1}
  3815   3845   
  3816   3846   do_execsql_test 5.1.6.2 {
  3817   3847     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3818   3848                rank() OVER win,
  3819   3849                dense_rank() OVER win
  3820   3850         FROM t3
  3821         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
  3822         -      ORDER BY 1 , 2 , 3
         3851  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
         3852  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3823   3853   } {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  3824   3854     {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  3825   3855     {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  3826   3856     {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  3827   3857     {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  3828   3858     {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  3829   3859     {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   133 4 3   223 10 8
................................................................................
  3836   3866     1334 52 44   1678 73 63   1678 73 63}
  3837   3867   
  3838   3868   do_execsql_test 5.1.7.1 {
  3839   3869     SELECT max(c) OVER win,
  3840   3870                min(c) OVER win,
  3841   3871                count(a) OVER win
  3842   3872         FROM t3
  3843         -      WINDOW win AS (  ORDER BY c , b , a 
         3873  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
  3844   3874           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3845         -      ORDER BY 1 , 2 , 3
         3875  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3846   3876   } {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  3847   3877     979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  3848   3878     979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  3849   3879     979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  3850   3880     979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  3851   3881     979 346 60   979 354 59   979 355 58   979 355 58   979 393 56   979 393 57
  3852   3882     979 398 55   979 399 54   979 399 54   979 412 53   979 421 52   979 430 51
................................................................................
  3860   3890     979 870 11   979 870 11   979 899 9   979 911 8   979 929 7}
  3861   3891   
  3862   3892   do_execsql_test 5.1.7.2 {
  3863   3893     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3864   3894                rank() OVER win,
  3865   3895                dense_rank() OVER win
  3866   3896         FROM t3
  3867         -      WINDOW win AS (  ORDER BY c , b , a 
         3897  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
         3898  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         3899  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         3900  +} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
         3901  +  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
         3902  +  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
         3903  +  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
         3904  +  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
         3905  +  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
         3906  +  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
         3907  +  17126 49 49   17126 50 50   17126 51 51   17733 44 44   17733 45 45
         3908  +  17733 46 46   17733 47 47   17733 48 48   18176 42 42   18176 43 43
         3909  +  18597 40 40   18597 41 41   18996 39 39   19395 37 37   19395 38 38
         3910  +  19788 36 36   20181 35 35   20536 34 34   20891 30 30   20891 31 31
         3911  +  20891 32 32   20891 33 33   21226 28 28   21226 29 29   21535 27 27
         3912  +  21830 26 26   22087 22 22   22087 23 23   22087 24 24   22087 25 25
         3913  +  22334 21 21   22573 17 17   22573 18 18   22573 19 19   22573 20 20
         3914  +  22796 11 11   22796 12 12   22796 13 13   22796 14 14   22796 15 15
         3915  +  22796 16 16   22929 10 10   23042 9 9   23155 1 1   23155 2 2   23155 3 3
         3916  +  23155 4 4   23155 5 5   23155 6 6   23155 7 7   23155 8 8}
         3917  +
         3918  +do_execsql_test 5.1.8.1 {
         3919  +  SELECT max(c) OVER win,
         3920  +             min(c) OVER win,
         3921  +             count(a) OVER win
         3922  +      FROM t3
         3923  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         3924  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         3925  +} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3926  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3927  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3928  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3929  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3930  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3931  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3932  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3933  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3934  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3935  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3936  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3937  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3938  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3939  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83}
         3940  +
         3941  +do_execsql_test 5.1.8.2 {
         3942  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         3943  +             rank() OVER win,
         3944  +             dense_rank() OVER win
         3945  +      FROM t3
         3946  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         3947  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         3948  +} {23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3949  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3950  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3951  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3952  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3953  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3954  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3955  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3956  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3957  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3958  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3959  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3960  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3961  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         3962  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}
         3963  +
         3964  +do_execsql_test 5.1.9.1 {
         3965  +  SELECT max(c) OVER win,
         3966  +             min(c) OVER win,
         3967  +             count(a) OVER win
         3968  +      FROM t3
         3969  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         3970  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         3971  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         3972  +} {870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
         3973  +  899 113 9   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
         3974  +  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
         3975  +  899 113 16   899 113 16   899 113 16   899 113 16   979 102 44   979 102 44
         3976  +  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 44
         3977  +  979 102 44   979 102 44   979 102 44   979 102 49   979 102 49   979 102 49
         3978  +  979 102 49   979 102 49   979 102 56   979 102 56   979 102 56   979 102 56
         3979  +  979 102 56   979 102 56   979 102 56   979 102 62   979 102 62   979 102 62
         3980  +  979 102 62   979 102 62   979 102 62   979 102 75   979 102 75   979 102 75
         3981  +  979 102 75   979 102 75   979 102 75   979 102 75   979 102 75   979 102 75
         3982  +  979 102 75   979 102 75   979 102 75   979 102 75   979 102 83   979 102 83
         3983  +  979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         3984  +  979 113 25   979 113 25   979 113 25   979 113 25   979 113 25   979 113 25
         3985  +  979 113 25   979 113 25   979 113 25   979 113 33   979 113 33   979 113 33
         3986  +  979 113 33   979 113 33   979 113 33   979 113 33   979 113 33}
         3987  +
         3988  +do_execsql_test 5.1.9.2 {
         3989  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         3990  +             rank() OVER win,
         3991  +             dense_rank() OVER win
         3992  +      FROM t3
         3993  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         3994  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         3995  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         3996  +} {2050 84 11   2050 84 11   2050 84 11   2050 84 11   2050 84 11   2050 84 11
         3997  +  4997 75 10   4997 75 10   4997 75 10   4997 75 10   4997 75 10   4997 75 10
         3998  +  4997 75 10   4997 75 10   4997 75 10   7337 68 9   7337 68 9   7337 68 9
         3999  +  7337 68 9   7337 68 9   7337 68 9   7337 68 9   10450 59 8   10450 59 8
         4000  +  10450 59 8   10450 59 8   10450 59 8   10450 59 8   10450 59 8   10450 59 8
         4001  +  10450 59 8   11714 51 7   11714 51 7   11714 51 7   11714 51 7   11714 51 7
         4002  +  11714 51 7   11714 51 7   11714 51 7   12676 40 6   12676 40 6   12676 40 6
         4003  +  12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6
         4004  +  12676 40 6   12676 40 6   14195 35 5   14195 35 5   14195 35 5   14195 35 5
         4005  +  14195 35 5   15999 28 4   15999 28 4   15999 28 4   15999 28 4   15999 28 4
         4006  +  15999 28 4   15999 28 4   17365 22 3   17365 22 3   17365 22 3   17365 22 3
         4007  +  17365 22 3   17365 22 3   20846 9 2   20846 9 2   20846 9 2   20846 9 2
         4008  +  20846 9 2   20846 9 2   20846 9 2   20846 9 2   20846 9 2   20846 9 2
         4009  +  20846 9 2   20846 9 2   20846 9 2   23155 1 1   23155 1 1   23155 1 1
         4010  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}
         4011  +
         4012  +do_execsql_test 5.1.10.1 {
         4013  +  SELECT max(c) OVER win,
         4014  +             min(c) OVER win,
         4015  +             count(a) OVER win
         4016  +      FROM t3
         4017  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         4018  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         4019  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4020  +} {777 113 5   777 113 5   777 113 5   777 113 5   777 113 5   805 250 7
         4021  +  805 250 7   805 250 7   805 250 7   805 250 7   805 250 7   805 250 7
         4022  +  822 158 6   822 158 6   822 158 6   822 158 6   822 158 6   822 158 6
         4023  +  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
         4024  +  840 247 13   840 247 13   840 247 13   840 247 13   840 247 13   840 247 13
         4025  +  840 247 13   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
         4026  +  870 158 0   899 113 9   899 113 9   899 113 9   899 113 9   899 113 9
         4027  +  899 113 9   899 113 9   899 113 9   899 113 9   934 223 8   934 223 8
         4028  +  934 223 8   934 223 8   934 223 8   934 223 8   934 223 8   934 223 8
         4029  +  938 102 11   938 102 11   938 102 11   938 102 11   938 102 11   938 102 11
         4030  +  938 102 11   938 102 11   938 102 11   938 102 11   938 102 11   938 148 8
         4031  +  938 148 8   938 148 8   938 148 8   938 148 8   938 148 8   938 148 8
         4032  +  938 148 8   959 224 7   959 224 7   959 224 7   959 224 7   959 224 7
         4033  +  959 224 7   959 224 7   979 133 9   979 133 9   979 133 9   979 133 9
         4034  +  979 133 9   979 133 9   979 133 9   979 133 9   979 133 9}
         4035  +
         4036  +do_execsql_test 5.1.10.2 {
         4037  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4038  +             rank() OVER win,
         4039  +             dense_rank() OVER win
         4040  +      FROM t3
         4041  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         4042  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         4043  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4044  +} {962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   962 1 1
         4045  +  962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1   1264 1 1
         4046  +  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1
         4047  +  1366 1 1   1366 1 1   1366 1 1   1366 1 1   1519 1 1   1519 1 1   1519 1 1
         4048  +  1519 1 1   1519 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1   1804 1 1
         4049  +  1804 1 1   1804 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1   2050 1 1
         4050  +  2050 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1
         4051  +  2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1   2340 1 1
         4052  +  2340 1 1   2340 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1   2947 1 1
         4053  +  2947 1 1   2947 1 1   2947 1 1   2947 1 1   3113 1 1   3113 1 1   3113 1 1
         4054  +  3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3481 1 1
         4055  +  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1
         4056  +  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}
         4057  +
         4058  +do_execsql_test 5.1.11.1 {
         4059  +  SELECT max(c) OVER win,
         4060  +             min(c) OVER win,
         4061  +             count(a) OVER win
         4062  +      FROM t3
         4063  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
         4064  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4065  +} {934 158 27   934 158 27   934 158 27   934 158 27   934 158 27   934 158 27
         4066  +  934 223 8   934 223 8   934 223 8   934 223 8   934 223 8   934 223 8
         4067  +  934 223 8   934 223 8   934 223 21   934 223 21   934 223 21   934 223 21
         4068  +  934 223 21   934 223 21   934 223 21   934 223 21   934 223 21   934 223 21
         4069  +  934 223 21   934 223 21   934 223 21   959 102 50   959 102 50   959 102 50
         4070  +  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
         4071  +  959 102 50   959 102 50   959 102 58   959 102 58   959 102 58   959 102 58
         4072  +  959 102 58   959 102 58   959 102 58   959 102 58   959 113 39   959 113 39
         4073  +  959 113 39   959 113 39   959 113 39   959 158 34   959 158 34   959 158 34
         4074  +  959 158 34   959 158 34   959 158 34   959 158 34   979 102 49   979 102 49
         4075  +  979 102 49   979 102 49   979 102 49   979 102 49   979 102 53   979 102 53
         4076  +  979 102 53   979 102 53   979 102 53   979 102 53   979 102 53   979 102 56
         4077  +  979 102 56   979 102 56   979 102 56   979 102 56   979 102 56   979 102 56
         4078  +  979 102 56   979 102 56   979 102 59   979 102 59   979 102 59   979 102 59
         4079  +  979 102 59   979 102 59   979 102 59   979 102 59   979 102 59}
         4080  +
         4081  +do_execsql_test 5.1.11.2 {
         4082  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4083  +             rank() OVER win,
         4084  +             dense_rank() OVER win
         4085  +      FROM t3
         4086  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE NO OTHERS  )
         4087  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4088  +} {2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1   2309 1 1
         4089  +  2309 1 1   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2
         4090  +  5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2
         4091  +  7156 22 3   7156 22 3   7156 22 3   7156 22 3   7156 22 3   7156 22 3
         4092  +  8960 28 4   8960 28 4   8960 28 4   8960 28 4   8960 28 4   8960 28 4
         4093  +  8960 28 4   10479 35 5   10479 35 5   10479 35 5   10479 35 5   10479 35 5
         4094  +  11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6
         4095  +  11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6   12368 68 9
         4096  +  12368 68 9   12368 68 9   12368 68 9   12368 68 9   12368 68 9   12368 68 9
         4097  +  12705 51 7   12705 51 7   12705 51 7   12705 51 7   12705 51 7   12705 51 7
         4098  +  12705 51 7   12705 51 7   13509 59 8   13509 59 8   13509 59 8   13509 59 8
         4099  +  13509 59 8   13509 59 8   13509 59 8   13509 59 8   13509 59 8
         4100  +  13949 75 10   13949 75 10   13949 75 10   13949 75 10   13949 75 10
         4101  +  13949 75 10   13949 75 10   13949 75 10   13949 75 10   14195 84 11
         4102  +  14195 84 11   14195 84 11   14195 84 11   14195 84 11   14195 84 11}
         4103  +
         4104  +do_execsql_test 5.1.12.1 {
         4105  +  SELECT max(c) OVER win,
         4106  +             min(c) OVER win,
         4107  +             count(a) OVER win
         4108  +      FROM t3
         4109  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
         4110  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4111  +} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   160 158 2
         4112  +  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
         4113  +  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
         4114  +  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
         4115  +  346 346 1   355 354 2   355 354 2   355 354 2   399 393 4   399 393 4
         4116  +  399 393 4   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
         4117  +  443 443 1   480 480 2   480 480 2   574 572 2   574 572 2   607 607 1
         4118  +  618 618 2   618 618 2   634 627 4   634 627 4   634 627 4   634 627 4
         4119  +  634 629 3   652 652 1   667 660 2   671 667 3   671 667 3   671 667 3
         4120  +  671 667 3   683 683 1   711 705 2   716 705 3   716 711 2   730 726 2
         4121  +  730 726 2   762 759 2   768 759 4   768 762 3   768 762 3   777 777 1
         4122  +  792 786 3   794 786 4   794 786 4   794 790 3   805 805 1   822 822 1
         4123  +  845 839 5   845 839 5   845 839 5   845 839 5   845 839 5   870 870 2
         4124  +  870 870 2   870 870 2   899 899 1   911 911 1   934 929 2   938 929 4
         4125  +  938 934 3   938 934 3   963 959 2   963 959 2   979 979 1}
         4126  +
         4127  +do_execsql_test 5.1.12.2 {
         4128  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4129  +             rank() OVER win,
         4130  +             dense_rank() OVER win
         4131  +      FROM t3
         4132  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE NO OTHERS  )
         4133  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4134  +} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
         4135  +  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
         4136  +  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
         4137  +  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
         4138  +  {} 85 72   133 4 3   223 10 8   223 11 9   226 2 2   226 2 2   239 12 10
         4139  +  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
         4140  +  309 21 19   335 22 20   335 23 21   335 24 22   421 35 30   443 37 32
         4141  +  504 16 14   504 17 15   607 42 36   683 56 47   710 26 24   710 27 25
         4142  +  710 27 25   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
         4143  +  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1334 51 43
         4144  +  1416 57 48   1416 58 49   1584 29 26   1584 29 26   1584 31 27   1584 32 28
         4145  +  1584 32 28   1891 49 41   1922 87 73   1922 88 74   2005 52 44   2005 52 44
         4146  +  2005 54 45   2005 55 46   2518 45 38   2518 46 39   2518 46 39   2518 48 40
         4147  +  2523 73 63   2523 73 63   2523 75 64   2523 76 65   2523 77 66}
         4148  +
         4149  +do_execsql_test 5.1.13.1 {
         4150  +  SELECT max(c) OVER win,
         4151  +             min(c) OVER win,
         4152  +             count(a) OVER win
         4153  +      FROM t3
         4154  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
         4155  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4156  +} {102 102 1   113 113 2   113 113 2   133 133 1   148 148 1   158 158 1
         4157  +  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
         4158  +  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
         4159  +  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
         4160  +  346 346 1   354 354 1   355 355 1   355 355 1   393 393 2   393 393 2
         4161  +  398 398 1   399 399 1   399 399 1   412 412 1   421 421 1   430 430 1
         4162  +  443 443 1   480 480 2   480 480 2   572 572 1   574 574 1   607 607 1
         4163  +  618 618 2   618 618 2   627 627 1   629 629 1   629 629 1   633 633 1
         4164  +  634 634 1   652 652 1   660 660 1   667 667 1   667 667 1   670 670 1
         4165  +  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
         4166  +  730 730 1   759 759 1   762 762 1   768 768 2   768 768 2   777 777 1
         4167  +  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
         4168  +  839 839 2   839 839 2   840 840 1   844 844 1   845 845 1   870 870 2
         4169  +  870 870 2   870 870 2   899 899 1   911 911 1   929 929 1   934 934 1
         4170  +  938 938 2   938 938 2   959 959 1   963 963 1   979 979 1}
         4171  +
         4172  +do_execsql_test 5.1.13.2 {
         4173  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4174  +             rank() OVER win,
         4175  +             dense_rank() OVER win
         4176  +      FROM t3
         4177  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE NO OTHERS  )
         4178  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4179  +} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
         4180  +  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
         4181  +  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
         4182  +  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
         4183  +  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
         4184  +  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
         4185  +  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   133 4 3   223 10 8
         4186  +  226 2 2   226 2 2   239 14 12   247 15 13   257 19 17   295 20 18
         4187  +  309 21 19   335 23 21   421 35 30   443 37 32   607 42 36   627 45 38
         4188  +  633 48 40   671 55 46   683 56 47   705 57 48   710 27 25   710 27 25
         4189  +  711 58 49   759 62 53   777 66 56   786 29 26   786 29 26   798 32 28
         4190  +  798 32 28   805 71 61   845 77 66   899 81 68   911 82 69   929 83 70
         4191  +  959 87 73   963 88 74   979 89 75   1258 46 39   1258 46 39   1334 52 44
         4192  +  1334 52 44   1678 73 63   1678 73 63}
         4193  +
         4194  +do_execsql_test 5.1.14.1 {
         4195  +  SELECT max(c) OVER win,
         4196  +             min(c) OVER win,
         4197  +             count(a) OVER win
         4198  +      FROM t3
         4199  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
         4200  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
         4201  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4202  +} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         4203  +  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
         4204  +  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
         4205  +  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
         4206  +  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
         4207  +  979 346 60   979 354 59   979 355 57   979 355 58   979 393 56   979 393 57
         4208  +  979 398 55   979 399 53   979 399 54   979 412 53   979 421 52   979 430 51
         4209  +  979 443 50   979 480 48   979 480 49   979 572 47   979 574 46   979 607 45
         4210  +  979 618 43   979 618 44   979 627 42   979 629 40   979 629 41   979 633 40
         4211  +  979 634 39   979 652 38   979 660 37   979 667 35   979 667 36   979 670 35
         4212  +  979 671 34   979 683 33   979 705 32   979 711 31   979 716 30   979 726 29
         4213  +  979 730 28   979 759 27   979 762 26   979 768 24   979 768 25   979 777 23
         4214  +  979 786 22   979 790 21   979 792 20   979 794 19   979 805 18   979 822 17
         4215  +  979 839 15   979 839 16   979 840 14   979 844 13   979 845 12   979 870 9
         4216  +  979 870 10   979 870 11   979 899 9   979 911 8   979 929 7}
         4217  +
         4218  +do_execsql_test 5.1.14.2 {
         4219  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4220  +             rank() OVER win,
         4221  +             dense_rank() OVER win
         4222  +      FROM t3
         4223  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
  3868   4224           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE NO OTHERS  )
  3869         -      ORDER BY 1 , 2 , 3
         4225  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3870   4226   } {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  3871   4227     6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  3872   4228     8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  3873   4229     9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  3874   4230     10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  3875   4231     13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  3876   4232     14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
................................................................................
  3887   4243   
  3888   4244   do_execsql_test 5.2.1.1 {
  3889   4245     SELECT max(c) OVER win,
  3890   4246                min(c) OVER win,
  3891   4247                count(a) OVER win
  3892   4248         FROM t3
  3893   4249         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  3894         -      ORDER BY 1 , 2 , 3
         4250  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3895   4251   } {963 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  3896   4252     979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  3897   4253     979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  3898   4254     979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  3899   4255     979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  3900   4256     979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  3901   4257     979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
................................................................................
  3910   4266   
  3911   4267   do_execsql_test 5.2.1.2 {
  3912   4268     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3913   4269                rank() OVER win,
  3914   4270                dense_rank() OVER win
  3915   4271         FROM t3
  3916   4272         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  3917         -      ORDER BY 1 , 2 , 3
         4273  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3918   4274   } {22176 1 1   22192 1 1   22196 1 1   22226 1 1   22244 1 1   22256 1 1
  3919   4275     22310 1 1   22316 1 1   22316 1 1   22350 1 1   22378 1 1   22396 1 1
  3920   4276     22444 1 1   22450 1 1   22472 1 1   22484 1 1   22488 1 1   22488 1 1
  3921   4277     22522 1 1   22526 1 1   22526 1 1   22528 1 1   22548 1 1   22712 1 1
  3922   4278     22734 1 1   22756 1 1   22756 1 1   22762 1 1   22762 1 1   22800 1 1
  3923   4279     22800 1 1   22820 1 1   22846 1 1   22860 1 1   22898 1 1   22908 1 1
  3924   4280     22916 1 1   22932 1 1   23022 1 1   23042 1 1   23042 1 1   23155 1 1
................................................................................
  3932   4288     23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}
  3933   4289   
  3934   4290   do_execsql_test 5.2.2.1 {
  3935   4291     SELECT max(c) OVER win,
  3936   4292                min(c) OVER win,
  3937   4293                count(a) OVER win
  3938   4294         FROM t3
  3939         -      WINDOW win AS (  ORDER BY a  
         4295  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  3940   4296           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  3941         -      ORDER BY 1 , 2 , 3
         4297  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3942   4298   } {839 113 8   899 113 8   899 113 8   899 113 8   899 113 8   899 113 8
  3943   4299     899 113 8   899 113 8   899 113 15   899 113 15   899 113 15   899 113 15
  3944   4300     899 113 15   899 113 15   899 113 15   899 234 8   963 113 24   979 102 43
  3945   4301     979 102 43   979 102 43   979 102 43   979 102 43   979 102 43   979 102 43
  3946   4302     979 102 43   979 102 43   979 102 43   979 102 48   979 102 48   979 102 48
  3947   4303     979 102 48   979 102 48   979 102 55   979 102 55   979 102 55   979 102 55
  3948   4304     979 102 55   979 102 55   979 102 55   979 102 61   979 102 61   979 102 61
................................................................................
  3956   4312     979 113 32   979 113 32   979 113 32   979 113 32   979 113 43}
  3957   4313   
  3958   4314   do_execsql_test 5.2.2.2 {
  3959   4315     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  3960   4316                rank() OVER win,
  3961   4317                dense_rank() OVER win
  3962   4318         FROM t3
  3963         -      WINDOW win AS (  ORDER BY a  
         4319  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  3964   4320           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  3965         -      ORDER BY 1 , 2 , 3
         4321  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3966   4322   } {2048 81 11   2108 81 11   2108 81 11   2690 81 11   2834 81 11   2947 81 11
  3967   4323     2947 81 11   2947 81 11   2947 81 11   4482 74 10   4616 74 10   4844 74 10
  3968   4324     4866 74 10   5287 74 10   5287 74 10   5287 74 10   7421 65 9   7437 65 9
  3969   4325     7717 65 9   8045 65 9   8267 65 9   8400 65 9   8400 65 9   8400 65 9
  3970   4326     8400 65 9   8735 57 8   9329 57 8   9664 57 8   9664 57 8   9664 57 8
  3971   4327     9664 57 8   9664 57 8   9664 57 8   9959 46 7   10331 46 7   10626 46 7
  3972   4328     10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7   10626 46 7
................................................................................
  3982   4338   do_execsql_test 5.2.3.1 {
  3983   4339     SELECT max(c) OVER win,
  3984   4340                min(c) OVER win,
  3985   4341                count(a) OVER win
  3986   4342         FROM t3
  3987   4343         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  3988   4344           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  3989         -      ORDER BY 1 , 2 , 3
         4345  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  3990   4346   } {667 158 0   671 250 6   759 158 5   768 113 4   777 113 4   777 113 4
  3991   4347     777 113 4   777 252 4   792 247 12   805 250 6   805 250 6   805 250 6
  3992   4348     805 250 6   805 250 6   805 398 6   822 158 5   822 158 5   822 158 5
  3993   4349     822 158 5   822 346 5   839 113 8   840 247 12   840 247 12   840 247 12
  3994   4350     840 247 12   840 247 12   840 247 12   840 247 12   840 247 12   840 247 12
  3995   4351     840 247 12   840 247 12   840 393 12   845 224 6   870 102 10   870 158 0
  3996   4352     870 158 0   870 158 0   870 158 0   870 355 0   899 113 8   899 113 8
................................................................................
  4006   4362   do_execsql_test 5.2.3.2 {
  4007   4363     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4008   4364                rank() OVER win,
  4009   4365                dense_rank() OVER win
  4010   4366         FROM t3
  4011   4367         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  4012   4368           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  4013         -      ORDER BY 1 , 2 , 3
         4369  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4014   4370   } {295 1 1   335 1 1   607 1 1   667 1 1   742 1 1   759 1 1   845 1 1
  4015   4371     890 1 1   929 1 1   959 1 1   962 1 1   962 1 1   962 1 1   962 1 1
  4016   4372     962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1
  4017   4373     1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1   1366 1 1
  4018   4374     1366 1 1   1383 1 1   1398 1 1   1406 1 1   1421 1 1   1519 1 1   1519 1 1
  4019   4375     1535 1 1   1651 1 1   1669 1 1   1682 1 1   1695 1 1   1804 1 1   1804 1 1
  4020   4376     1804 1 1   1804 1 1   1804 1 1   1897 1 1   1919 1 1   2000 1 1   2048 1 1
................................................................................
  4026   4382     3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}
  4027   4383   
  4028   4384   do_execsql_test 5.2.4.1 {
  4029   4385     SELECT max(c) OVER win,
  4030   4386                min(c) OVER win,
  4031   4387                count(a) OVER win
  4032   4388         FROM t3
  4033         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
  4034         -      ORDER BY 1 , 2 , 3
         4389  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
         4390  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4035   4391   } {667 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 355 0
  4036   4392     911 158 7   934 158 7   934 158 7   934 158 7   934 158 7   934 158 7
  4037   4393     934 158 7   934 158 7   934 158 20   934 158 20   934 158 20   934 158 20
  4038   4394     934 158 20   934 158 20   934 158 20   934 158 20   934 158 20   934 158 20
  4039   4395     934 158 20   934 158 20   934 158 20   934 158 26   934 158 26   934 158 26
  4040   4396     934 158 26   934 158 26   934 158 26   934 158 33   959 102 49   959 102 49
  4041   4397     959 102 49   959 102 49   959 102 49   959 102 49   959 102 49   959 102 49
................................................................................
  4049   4405     979 102 58   979 102 58   979 102 58   979 102 58   979 102 58}
  4050   4406   
  4051   4407   do_execsql_test 5.2.4.2 {
  4052   4408     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4053   4409                rank() OVER win,
  4054   4410                dense_rank() OVER win
  4055   4411         FROM t3
  4056         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
  4057         -      ORDER BY 1 , 2 , 3
         4412  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
         4413  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4058   4414   } {1383 1 1   1421 1 1   1651 1 1   1695 1 1   2050 1 1   2050 1 1   3448 7 2
  4059   4415     3732 7 2   4050 7 2   4120 7 2   4136 7 2   4359 7 2   4359 7 2   4359 7 2
  4060   4416     7129 15 3   7135 15 3   7207 15 3   7441 15 3   7447 15 3   7447 15 3
  4061   4417     7593 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3   7840 15 3
  4062   4418     7840 15 3   8447 28 4   8599 28 4   9206 28 4   9206 28 4   9206 28 4
  4063   4419     9206 28 4   10051 34 5   10165 34 5   11010 34 5   11010 34 5   11010 34 5
  4064   4420     11010 34 5   11010 34 5   11563 74 10   11697 74 10   11752 41 6
................................................................................
  4073   4429     13949 81 11   13949 81 11   13949 81 11}
  4074   4430   
  4075   4431   do_execsql_test 5.2.5.1 {
  4076   4432     SELECT max(c) OVER win,
  4077   4433                min(c) OVER win,
  4078   4434                count(a) OVER win
  4079   4435         FROM t3
  4080         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
  4081         -      ORDER BY 1 , 2 , 3
         4436  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
         4437  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4082   4438   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4083   4439     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4084   4440     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
  4085   4441     113 113 1   158 158 1   160 158 1   160 158 2   223 223 1   224 224 1
  4086   4442     238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  4087   4443     257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   355 354 1
  4088   4444     355 354 2   355 355 1   399 393 3   399 393 3   399 393 3   399 393 3
................................................................................
  4096   4452     959 959 1   963 963 1}
  4097   4453   
  4098   4454   do_execsql_test 5.2.5.2 {
  4099   4455     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4100   4456                rank() OVER win,
  4101   4457                dense_rank() OVER win
  4102   4458         FROM t3
  4103         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
  4104         -      ORDER BY 1 , 2 , 3
         4459  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
         4460  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4105   4461   } {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  4106   4462     {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19   {} 23 21   {} 25 23
  4107   4463     {} 34 29   {} 35 30   {} 36 31   {} 37 32   {} 38 33   {} 38 33   {} 40 34
  4108   4464     {} 41 35   {} 42 36   {} 43 37   {} 43 37   {} 50 42   {} 56 47   {} 60 51
  4109   4465     {} 61 52   {} 62 53   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58
  4110   4466     {} 69 59   {} 70 60   {} 71 61   {} 72 62   {} 78 67   {} 78 67   {} 78 67
  4111   4467     {} 81 68   {} 82 69   {} 83 70   {} 85 72   {} 85 72   {} 89 75   113 2 2
................................................................................
  4118   4474     2005 54 45   2523 75 64   2523 76 65}
  4119   4475   
  4120   4476   do_execsql_test 5.2.6.1 {
  4121   4477     SELECT max(c) OVER win,
  4122   4478                min(c) OVER win,
  4123   4479                count(a) OVER win
  4124   4480         FROM t3
  4125         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
  4126         -      ORDER BY 1 , 2 , 3
         4481  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
         4482  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4127   4483   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4128   4484     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4129   4485     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4130   4486     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4131   4487     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4132   4488     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4133   4489     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
................................................................................
  4140   4496     938 938 1   938 938 1}
  4141   4497   
  4142   4498   do_execsql_test 5.2.6.2 {
  4143   4499     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4144   4500                rank() OVER win,
  4145   4501                dense_rank() OVER win
  4146   4502         FROM t3
  4147         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
  4148         -      ORDER BY 1 , 2 , 3
         4503  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
         4504  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4149   4505   } {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
  4150   4506     {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13   {} 16 14   {} 17 15
  4151   4507     {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20   {} 23 21   {} 24 22
  4152   4508     {} 25 23   {} 26 24   {} 31 27   {} 34 29   {} 35 30   {} 36 31   {} 37 32
  4153   4509     {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37   {} 43 37
  4154   4510     {} 45 38   {} 48 40   {} 49 41   {} 50 42   {} 51 43   {} 54 45   {} 55 46
  4155   4511     {} 56 47   {} 57 48   {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53
................................................................................
  4161   4517     629 46 39   667 52 44   667 52 44   839 73 63   839 73 63}
  4162   4518   
  4163   4519   do_execsql_test 5.2.7.1 {
  4164   4520     SELECT max(c) OVER win,
  4165   4521                min(c) OVER win,
  4166   4522                count(a) OVER win
  4167   4523         FROM t3
  4168         -      WINDOW win AS (  ORDER BY c , b , a 
         4524  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
  4169   4525           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  4170         -      ORDER BY 1 , 2 , 3
         4526  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4171   4527   } {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  4172   4528     979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  4173   4529     979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  4174   4530     979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  4175   4531     979 256 66   979 257 65   979 295 64   979 309 64   979 330 62   979 335 61
  4176   4532     979 336 60   979 346 59   979 354 59   979 355 57   979 355 57   979 393 55
  4177   4533     979 393 56   979 398 54   979 399 53   979 399 53   979 412 52   979 421 51
................................................................................
  4185   4541     979 870 9   979 870 10   979 870 10   979 899 8   979 911 7}
  4186   4542   
  4187   4543   do_execsql_test 5.2.7.2 {
  4188   4544     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4189   4545                rank() OVER win,
  4190   4546                dense_rank() OVER win
  4191   4547         FROM t3
  4192         -      WINDOW win AS (  ORDER BY c , b , a 
         4548  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
         4549  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4550  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4551  +} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
         4552  +  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
         4553  +  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
         4554  +  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
         4555  +  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
         4556  +  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
         4557  +  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
         4558  +  17100 48 48   17104 46 46   17104 47 47   17106 45 45   17126 49 49
         4559  +  17126 50 50   17126 51 51   17569 42 42   17733 44 44   18176 43 43
         4560  +  18597 40 40   18597 41 41   18952 37 37   18996 39 39   19395 38 38
         4561  +  19760 35 35   19788 36 36   20492 32 32   20492 33 33   20498 30 30
         4562  +  20536 34 34   20833 29 29   20871 28 28   20891 31 31   21180 27 27
         4563  +  21752 23 23   21830 26 26   22025 21 21   22087 22 22   22087 24 24
         4564  +  22087 25 25   22278 20 20   22316 19 19   22549 15 15   22557 14 14
         4565  +  22573 17 17   22573 18 18   22706 10 10   22796 11 11   22796 12 12
         4566  +  22796 13 13   22796 16 16   23022 4 4   23042 2 2   23042 3 3   23042 9 9
         4567  +  23155 1 1   23155 5 5   23155 6 6   23155 7 7   23155 8 8}
         4568  +
         4569  +do_execsql_test 5.2.8.1 {
         4570  +  SELECT max(c) OVER win,
         4571  +             min(c) OVER win,
         4572  +             count(a) OVER win
         4573  +      FROM t3
         4574  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4575  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4576  +} {963 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4577  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4578  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4579  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4580  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4581  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4582  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4583  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4584  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4585  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4586  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4587  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4588  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4589  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 83   979 102 83
         4590  +  979 102 83   979 102 83   979 102 83   979 102 83   979 113 82}
         4591  +
         4592  +do_execsql_test 5.2.8.2 {
         4593  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4594  +             rank() OVER win,
         4595  +             dense_rank() OVER win
         4596  +      FROM t3
         4597  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4598  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4599  +} {22176 1 1   22192 1 1   22196 1 1   22226 1 1   22244 1 1   22256 1 1
         4600  +  22310 1 1   22316 1 1   22316 1 1   22350 1 1   22378 1 1   22396 1 1
         4601  +  22444 1 1   22450 1 1   22472 1 1   22484 1 1   22488 1 1   22488 1 1
         4602  +  22522 1 1   22526 1 1   22526 1 1   22528 1 1   22548 1 1   22712 1 1
         4603  +  22734 1 1   22756 1 1   22756 1 1   22762 1 1   22762 1 1   22800 1 1
         4604  +  22800 1 1   22820 1 1   22846 1 1   22860 1 1   22898 1 1   22908 1 1
         4605  +  22916 1 1   22932 1 1   23022 1 1   23042 1 1   23042 1 1   23155 1 1
         4606  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         4607  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         4608  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         4609  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         4610  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         4611  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         4612  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1
         4613  +  23155 1 1   23155 1 1   23155 1 1   23155 1 1   23155 1 1}
         4614  +
         4615  +do_execsql_test 5.2.9.1 {
         4616  +  SELECT max(c) OVER win,
         4617  +             min(c) OVER win,
         4618  +             count(a) OVER win
         4619  +      FROM t3
         4620  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         4621  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4622  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4623  +} {667 158 0   870 113 8   870 158 0   870 158 0   870 158 0   870 158 0
         4624  +  870 355 0   899 113 8   899 113 8   899 113 8   899 113 8   899 113 8
         4625  +  899 113 8   899 113 8   899 113 15   899 113 15   899 113 15   899 113 15
         4626  +  899 113 15   899 113 15   899 113 15   899 158 8   963 113 24   979 102 43
         4627  +  979 102 43   979 102 43   979 102 43   979 102 43   979 102 43   979 102 43
         4628  +  979 102 43   979 102 43   979 102 43   979 102 48   979 102 48   979 102 48
         4629  +  979 102 48   979 102 48   979 102 55   979 102 55   979 102 55   979 102 55
         4630  +  979 102 55   979 102 55   979 102 55   979 102 61   979 102 61   979 102 61
         4631  +  979 102 61   979 102 61   979 102 61   979 102 74   979 102 74   979 102 74
         4632  +  979 102 74   979 102 74   979 102 74   979 102 74   979 102 74   979 102 74
         4633  +  979 102 74   979 102 74   979 102 74   979 102 74   979 102 82   979 102 82
         4634  +  979 102 82   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4635  +  979 113 24   979 113 24   979 113 24   979 113 24   979 113 24   979 113 24
         4636  +  979 113 24   979 113 24   979 113 32   979 113 32   979 113 32   979 113 32
         4637  +  979 113 32   979 113 32   979 113 32   979 113 32   979 113 43}
         4638  +
         4639  +do_execsql_test 5.2.9.2 {
         4640  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4641  +             rank() OVER win,
         4642  +             dense_rank() OVER win
         4643  +      FROM t3
         4644  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         4645  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4646  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4647  +} {1383 84 11   1421 84 11   1651 84 11   1695 84 11   2050 84 11   2050 84 11
         4648  +  4098 75 10   4158 75 10   4158 75 10   4740 75 10   4884 75 10   4997 75 10
         4649  +  4997 75 10   4997 75 10   4997 75 10   6532 68 9   6666 68 9   6894 68 9
         4650  +  6916 68 9   7337 68 9   7337 68 9   7337 68 9   9471 59 8   9487 59 8
         4651  +  9767 59 8   10095 59 8   10317 59 8   10450 59 8   10450 59 8   10450 59 8
         4652  +  10450 59 8   10785 51 7   11379 51 7   11714 51 7   11714 51 7   11714 51 7
         4653  +  11714 51 7   11714 51 7   11714 51 7   12009 40 6   12381 40 6   12676 40 6
         4654  +  12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6   12676 40 6
         4655  +  12676 40 6   12676 40 6   13418 35 5   13566 35 5   14082 35 5   14195 35 5
         4656  +  14195 35 5   15040 28 4   15154 28 4   15999 28 4   15999 28 4   15999 28 4
         4657  +  15999 28 4   15999 28 4   16606 22 3   16758 22 3   17365 22 3   17365 22 3
         4658  +  17365 22 3   17365 22 3   20135 9 2   20141 9 2   20213 9 2   20447 9 2
         4659  +  20453 9 2   20453 9 2   20599 9 2   20846 9 2   20846 9 2   20846 9 2
         4660  +  20846 9 2   20846 9 2   20846 9 2   22244 1 1   22528 1 1   22846 1 1
         4661  +  22916 1 1   22932 1 1   23155 1 1   23155 1 1   23155 1 1}
         4662  +
         4663  +do_execsql_test 5.2.10.1 {
         4664  +  SELECT max(c) OVER win,
         4665  +             min(c) OVER win,
         4666  +             count(a) OVER win
         4667  +      FROM t3
         4668  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         4669  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4670  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4671  +} {667 158 0   671 250 6   759 158 5   768 113 4   777 113 4   777 113 4
         4672  +  777 113 4   777 252 4   792 247 12   805 250 6   805 250 6   805 250 6
         4673  +  805 250 6   805 250 6   805 398 6   822 158 5   822 158 5   822 158 5
         4674  +  822 158 5   822 346 5   839 113 8   840 247 12   840 247 12   840 247 12
         4675  +  840 247 12   840 247 12   840 247 12   840 247 12   840 247 12   840 247 12
         4676  +  840 247 12   840 247 12   840 393 12   845 224 6   870 102 10   870 158 0
         4677  +  870 158 0   870 158 0   870 158 0   870 355 0   899 113 8   899 113 8
         4678  +  899 113 8   899 113 8   899 113 8   899 113 8   899 113 8   899 234 8
         4679  +  911 223 7   929 148 7   934 223 7   934 223 7   934 223 7   934 223 7
         4680  +  934 223 7   934 223 7   934 239 7   938 102 10   938 102 10   938 102 10
         4681  +  938 102 10   938 102 10   938 102 10   938 102 10   938 102 10   938 102 10
         4682  +  938 148 7   938 148 7   938 148 7   938 148 7   938 148 7   938 148 7
         4683  +  938 160 7   938 208 10   959 224 6   959 224 6   959 224 6   959 224 6
         4684  +  959 224 6   959 238 6   963 133 8   979 133 8   979 133 8   979 133 8
         4685  +  979 133 8   979 133 8   979 133 8   979 133 8   979 330 8}
         4686  +
         4687  +do_execsql_test 5.2.10.2 {
         4688  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4689  +             rank() OVER win,
         4690  +             dense_rank() OVER win
         4691  +      FROM t3
         4692  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         4693  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4694  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4695  +} {295 1 1   335 1 1   607 1 1   667 1 1   742 1 1   759 1 1   845 1 1
         4696  +  890 1 1   929 1 1   959 1 1   962 1 1   962 1 1   962 1 1   962 1 1
         4697  +  962 1 1   962 1 1   962 1 1   962 1 1   962 1 1   1264 1 1   1264 1 1
         4698  +  1264 1 1   1264 1 1   1264 1 1   1264 1 1   1366 1 1   1366 1 1   1366 1 1
         4699  +  1366 1 1   1383 1 1   1398 1 1   1406 1 1   1421 1 1   1519 1 1   1519 1 1
         4700  +  1535 1 1   1651 1 1   1669 1 1   1682 1 1   1695 1 1   1804 1 1   1804 1 1
         4701  +  1804 1 1   1804 1 1   1804 1 1   1897 1 1   1919 1 1   2000 1 1   2048 1 1
         4702  +  2050 1 1   2050 1 1   2070 1 1   2086 1 1   2108 1 1   2108 1 1   2134 1 1
         4703  +  2150 1 1   2309 1 1   2309 1 1   2309 1 1   2340 1 1   2340 1 1   2340 1 1
         4704  +  2430 1 1   2690 1 1   2758 1 1   2770 1 1   2776 1 1   2834 1 1   2848 1 1
         4705  +  2947 1 1   2947 1 1   2947 1 1   2947 1 1   2980 1 1   3082 1 1   3088 1 1
         4706  +  3088 1 1   3113 1 1   3113 1 1   3113 1 1   3113 1 1   3234 1 1   3481 1 1
         4707  +  3481 1 1   3481 1 1   3481 1 1   3481 1 1   3481 1 1}
         4708  +
         4709  +do_execsql_test 5.2.11.1 {
         4710  +  SELECT max(c) OVER win,
         4711  +             min(c) OVER win,
         4712  +             count(a) OVER win
         4713  +      FROM t3
         4714  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
         4715  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4716  +} {911 223 7   934 158 26   934 158 26   934 158 26   934 158 26   934 158 26
         4717  +  934 158 33   934 223 7   934 223 7   934 223 7   934 223 7   934 223 7
         4718  +  934 223 7   934 223 20   934 223 20   934 223 20   934 223 20   934 223 20
         4719  +  934 223 20   934 223 20   934 223 20   934 223 20   934 223 20   934 223 20
         4720  +  934 223 20   934 223 20   934 223 26   934 239 7   959 102 49   959 102 49
         4721  +  959 102 49   959 102 49   959 102 49   959 102 49   959 102 49   959 102 49
         4722  +  959 102 49   959 102 49   959 102 57   959 102 57   959 102 57   959 102 57
         4723  +  959 102 57   959 102 57   959 102 57   959 102 57   959 113 38   959 113 38
         4724  +  959 113 38   959 113 38   959 113 49   959 158 33   959 158 33   959 158 33
         4725  +  959 158 33   959 158 33   959 158 33   959 158 38   963 102 58   979 102 49
         4726  +  979 102 49   979 102 49   979 102 49   979 102 49   979 102 49   979 102 52
         4727  +  979 102 52   979 102 52   979 102 52   979 102 52   979 102 52   979 102 52
         4728  +  979 102 55   979 102 55   979 102 55   979 102 55   979 102 55   979 102 55
         4729  +  979 102 55   979 102 55   979 102 55   979 102 58   979 102 58   979 102 58
         4730  +  979 102 58   979 102 58   979 102 58   979 102 58   979 102 58}
         4731  +
         4732  +do_execsql_test 5.2.11.2 {
         4733  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4734  +             rank() OVER win,
         4735  +             dense_rank() OVER win
         4736  +      FROM t3
         4737  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE CURRENT ROW  )
         4738  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4739  +} {1398 1 1   1682 1 1   2000 1 1   2070 1 1   2086 1 1   2309 1 1   2309 1 1
         4740  +  2309 1 1   5079 9 2   5085 9 2   5157 9 2   5391 9 2   5397 9 2   5397 9 2
         4741  +  5543 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2   5790 9 2
         4742  +  6397 22 3   6549 22 3   7156 22 3   7156 22 3   7156 22 3   7156 22 3
         4743  +  8001 28 4   8115 28 4   8960 28 4   8960 28 4   8960 28 4   8960 28 4
         4744  +  8960 28 4   9702 35 5   9850 35 5   10366 35 5   10479 35 5   10479 35 5
         4745  +  10774 40 6   11146 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6
         4746  +  11441 40 6   11441 40 6   11441 40 6   11441 40 6   11441 40 6   11563 68 9
         4747  +  11697 68 9   11776 51 7   11925 68 9   11947 68 9   12368 68 9   12368 68 9
         4748  +  12368 68 9   12370 51 7   12530 59 8   12546 59 8   12705 51 7   12705 51 7
         4749  +  12705 51 7   12705 51 7   12705 51 7   12705 51 7   12826 59 8
         4750  +  13050 75 10   13110 75 10   13110 75 10   13154 59 8   13376 59 8
         4751  +  13509 59 8   13509 59 8   13509 59 8   13509 59 8   13528 84 11
         4752  +  13566 84 11   13692 75 10   13796 84 11   13836 75 10   13840 84 11
         4753  +  13949 75 10   13949 75 10   13949 75 10   13949 75 10   14195 84 11
         4754  +  14195 84 11}
         4755  +
         4756  +do_execsql_test 5.2.12.1 {
         4757  +  SELECT max(c) OVER win,
         4758  +             min(c) OVER win,
         4759  +             count(a) OVER win
         4760  +      FROM t3
         4761  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
         4762  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4763  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4764  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4765  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
         4766  +  113 113 1   158 158 1   160 158 1   160 158 2   223 223 1   224 224 1
         4767  +  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
         4768  +  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   355 354 1
         4769  +  355 354 2   355 355 1   399 393 3   399 393 3   399 393 3   399 393 3
         4770  +  399 393 4   480 480 1   480 480 1   572 572 1   574 574 1   618 618 1
         4771  +  618 618 1   633 629 2   634 627 3   634 627 3   634 627 4   634 629 3
         4772  +  667 667 1   670 667 2   671 667 2   671 667 2   671 667 3   711 711 1
         4773  +  711 711 1   716 705 2   726 726 1   730 730 1   762 762 1   768 759 3
         4774  +  768 762 2   768 762 2   792 790 2   792 790 2   794 786 3   794 786 3
         4775  +  844 839 4   845 839 4   845 839 4   845 839 4   845 839 4   870 870 1
         4776  +  870 870 1   870 870 2   934 934 1   938 929 3   938 934 2   938 934 2
         4777  +  959 959 1   963 963 1}
         4778  +
         4779  +do_execsql_test 5.2.12.2 {
         4780  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4781  +             rank() OVER win,
         4782  +             dense_rank() OVER win
         4783  +      FROM t3
         4784  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE CURRENT ROW  )
         4785  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4786  +} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
         4787  +  {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19   {} 23 21   {} 25 23
         4788  +  {} 34 29   {} 35 30   {} 36 31   {} 37 32   {} 38 33   {} 38 33   {} 40 34
         4789  +  {} 41 35   {} 42 36   {} 43 37   {} 43 37   {} 50 42   {} 56 47   {} 60 51
         4790  +  {} 61 52   {} 62 53   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58
         4791  +  {} 69 59   {} 70 60   {} 71 61   {} 72 62   {} 78 67   {} 78 67   {} 78 67
         4792  +  {} 81 68   {} 82 69   {} 83 70   {} 85 72   {} 85 72   {} 89 75   113 2 2
         4793  +  113 2 2   223 11 9   239 12 10   239 13 11   257 18 16   335 22 20
         4794  +  335 24 22   355 27 25   355 27 25   504 16 14   504 17 15   705 58 49
         4795  +  710 26 24   711 57 48   711 59 50   759 63 54   929 84 71   959 88 74
         4796  +  963 87 73   1185 32 28   1185 32 28   1191 29 26   1191 29 26   1334 51 43
         4797  +  1334 55 46   1338 52 44   1338 52 44   1584 31 27   1678 77 66   1684 73 63
         4798  +  1684 73 63   1885 48 40   1889 46 39   1889 46 39   1891 45 38   1891 49 41
         4799  +  2005 54 45   2523 75 64   2523 76 65}
         4800  +
         4801  +do_execsql_test 5.2.13.1 {
         4802  +  SELECT max(c) OVER win,
         4803  +             min(c) OVER win,
         4804  +             count(a) OVER win
         4805  +      FROM t3
         4806  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
         4807  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4808  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4809  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4810  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4811  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4812  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4813  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4814  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4815  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         4816  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   113 113 1
         4817  +  113 113 1   158 158 0   158 158 1   355 355 0   355 355 1   393 393 1
         4818  +  393 393 1   399 399 0   399 399 1   480 480 1   480 480 1   618 618 1
         4819  +  618 618 1   629 629 0   629 629 1   667 667 0   667 667 1   768 768 1
         4820  +  768 768 1   839 839 1   839 839 1   870 870 1   870 870 1   870 870 2
         4821  +  938 938 1   938 938 1}
         4822  +
         4823  +do_execsql_test 5.2.13.2 {
         4824  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4825  +             rank() OVER win,
         4826  +             dense_rank() OVER win
         4827  +      FROM t3
         4828  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE CURRENT ROW  )
         4829  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4830  +} {{} 1 1   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 10 8
         4831  +  {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13   {} 16 14   {} 17 15
         4832  +  {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20   {} 23 21   {} 24 22
         4833  +  {} 25 23   {} 26 24   {} 31 27   {} 34 29   {} 35 30   {} 36 31   {} 37 32
         4834  +  {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37   {} 43 37
         4835  +  {} 45 38   {} 48 40   {} 49 41   {} 50 42   {} 51 43   {} 54 45   {} 55 46
         4836  +  {} 56 47   {} 57 48   {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53
         4837  +  {} 63 54   {} 64 55   {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59
         4838  +  {} 70 60   {} 71 61   {} 72 62   {} 75 64   {} 76 65   {} 77 66   {} 78 67
         4839  +  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
         4840  +  {} 85 72   {} 87 73   {} 88 74   {} 89 75   113 2 2   113 2 2   355 27 25
         4841  +  355 27 25   393 29 26   393 29 26   399 32 28   399 32 28   629 46 39
         4842  +  629 46 39   667 52 44   667 52 44   839 73 63   839 73 63}
         4843  +
         4844  +do_execsql_test 5.2.14.1 {
         4845  +  SELECT max(c) OVER win,
         4846  +             min(c) OVER win,
         4847  +             count(a) OVER win
         4848  +      FROM t3
         4849  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
         4850  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
         4851  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         4852  +} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         4853  +  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
         4854  +  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
         4855  +  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
         4856  +  979 256 66   979 257 65   979 295 64   979 309 63   979 330 63   979 335 61
         4857  +  979 336 60   979 346 59   979 354 58   979 355 56   979 355 58   979 393 55
         4858  +  979 393 56   979 398 54   979 399 52   979 399 53   979 412 52   979 421 51
         4859  +  979 430 50   979 443 49   979 480 47   979 480 48   979 572 46   979 574 46
         4860  +  979 607 44   979 618 42   979 618 43   979 627 41   979 629 40   979 629 40
         4861  +  979 633 39   979 634 38   979 652 37   979 660 36   979 667 34   979 667 35
         4862  +  979 670 34   979 671 33   979 683 32   979 705 31   979 711 30   979 716 29
         4863  +  979 726 28   979 730 27   979 759 26   979 762 25   979 768 23   979 768 24
         4864  +  979 777 22   979 786 21   979 790 20   979 792 19   979 794 18   979 805 17
         4865  +  979 822 16   979 839 15   979 839 15   979 840 13   979 844 12   979 845 11
         4866  +  979 870 8   979 870 9   979 870 10   979 899 8   979 911 7}
         4867  +
         4868  +do_execsql_test 5.2.14.2 {
         4869  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         4870  +             rank() OVER win,
         4871  +             dense_rank() OVER win
         4872  +      FROM t3
         4873  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
  4193   4874           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE CURRENT ROW  )
  4194         -      ORDER BY 1 , 2 , 3
         4875  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4195   4876   } {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  4196   4877     5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  4197   4878     8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  4198   4879     9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  4199   4880     10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  4200   4881     13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  4201   4882     13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
................................................................................
  4212   4893   
  4213   4894   do_execsql_test 5.3.1.1 {
  4214   4895     SELECT max(c) OVER win,
  4215   4896                min(c) OVER win,
  4216   4897                count(a) OVER win
  4217   4898         FROM t3
  4218   4899         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4219         -      ORDER BY 1 , 2 , 3
         4900  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4220   4901   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4221   4902     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4222   4903     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4223   4904     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4224   4905     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4225   4906     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4226   4907     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
................................................................................
  4233   4914   
  4234   4915   do_execsql_test 5.3.1.2 {
  4235   4916     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4236   4917                rank() OVER win,
  4237   4918                dense_rank() OVER win
  4238   4919         FROM t3
  4239   4920         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4240         -      ORDER BY 1 , 2 , 3
         4921  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4241   4922   } {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4242   4923     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4243   4924     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4244   4925     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4245   4926     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4246   4927     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4247   4928     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
................................................................................
  4252   4933     {} 1 1}
  4253   4934   
  4254   4935   do_execsql_test 5.3.2.1 {
  4255   4936     SELECT max(c) OVER win,
  4256   4937                min(c) OVER win,
  4257   4938                count(a) OVER win
  4258   4939         FROM t3
  4259         -      WINDOW win AS (  ORDER BY a  
         4940  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  4260   4941           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4261         -      ORDER BY 1 , 2 , 3
         4942  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4262   4943   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4263   4944     {} {} 0   {} {} 0   899 113 9   899 113 9   899 113 9   899 113 9
  4264   4945     899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
  4265   4946     899 113 16   899 113 16   899 113 16   899 113 16   899 113 16   899 113 16
  4266   4947     979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 49
  4267   4948     979 102 49   979 102 49   979 102 49   979 102 49   979 102 49   979 102 49
  4268   4949     979 102 56   979 102 56   979 102 56   979 102 56   979 102 56   979 102 56
................................................................................
  4276   4957     979 113 33   979 113 33   979 113 33   979 113 33}
  4277   4958   
  4278   4959   do_execsql_test 5.3.2.2 {
  4279   4960     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4280   4961                rank() OVER win,
  4281   4962                dense_rank() OVER win
  4282   4963         FROM t3
  4283         -      WINDOW win AS (  ORDER BY a  
         4964  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  4284   4965           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4285         -      ORDER BY 1 , 2 , 3
         4966  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4286   4967   } {{} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11   {} 81 11
  4287   4968     {} 81 11   {} 81 11   2947 74 10   2947 74 10   2947 74 10   2947 74 10
  4288   4969     2947 74 10   2947 74 10   2947 74 10   5287 65 9   5287 65 9   5287 65 9
  4289   4970     5287 65 9   5287 65 9   5287 65 9   5287 65 9   5287 65 9   5287 65 9
  4290   4971     8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8
  4291   4972     8400 57 8   8400 57 8   9664 46 7   9664 46 7   9664 46 7   9664 46 7
  4292   4973     9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7
................................................................................
  4302   4983   do_execsql_test 5.3.3.1 {
  4303   4984     SELECT max(c) OVER win,
  4304   4985                min(c) OVER win,
  4305   4986                count(a) OVER win
  4306   4987         FROM t3
  4307   4988         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  4308   4989           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4309         -      ORDER BY 1 , 2 , 3
         4990  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4310   4991   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4311   4992     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4312   4993     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4313   4994     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4314   4995     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4315   4996     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4316   4997     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
................................................................................
  4324   5005   do_execsql_test 5.3.3.2 {
  4325   5006     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4326   5007                rank() OVER win,
  4327   5008                dense_rank() OVER win
  4328   5009         FROM t3
  4329   5010         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  4330   5011           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4331         -      ORDER BY 1 , 2 , 3
         5012  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4332   5013   } {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4333   5014     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4334   5015     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4335   5016     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4336   5017     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4337   5018     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4338   5019     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
................................................................................
  4343   5024     {} 1 1}
  4344   5025   
  4345   5026   do_execsql_test 5.3.4.1 {
  4346   5027     SELECT max(c) OVER win,
  4347   5028                min(c) OVER win,
  4348   5029                count(a) OVER win
  4349   5030         FROM t3
  4350         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE GROUP  )
  4351         -      ORDER BY 1 , 2 , 3
         5031  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
         5032  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4352   5033   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   870 158 0
  4353   5034     870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
  4354   5035     870 158 0   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  4355   5036     934 158 8   934 158 8   934 158 8   934 158 8   934 158 8   934 158 8
  4356   5037     934 158 8   934 158 8   934 158 21   934 158 21   934 158 21   934 158 21
  4357   5038     934 158 21   934 158 21   934 158 27   934 158 27   934 158 27   934 158 27
  4358   5039     934 158 27   934 158 27   934 158 27   959 102 50   959 102 50   959 102 50
................................................................................
  4366   5047     979 102 47   979 102 47   979 102 47   979 102 47}
  4367   5048   
  4368   5049   do_execsql_test 5.3.4.2 {
  4369   5050     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4370   5051                rank() OVER win,
  4371   5052                dense_rank() OVER win
  4372   5053         FROM t3
  4373         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE GROUP  )
  4374         -      ORDER BY 1 , 2 , 3
         5054  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
         5055  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4375   5056   } {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   2050 7 2   2050 7 2
  4376   5057     2050 7 2   2050 7 2   2050 7 2   2050 7 2   2050 7 2   2050 7 2   4359 15 3
  4377   5058     4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  4378   5059     4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  4379   5060     7840 28 4   7840 28 4   7840 28 4   7840 28 4   7840 28 4   7840 28 4
  4380   5061     9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5
  4381   5062     9206 34 5   10028 74 10   10028 74 10   10028 74 10   10028 74 10
................................................................................
  4389   5070     12529 46 7   12529 46 7   12529 46 7   12529 46 7   12529 46 7   12529 46 7}
  4390   5071   
  4391   5072   do_execsql_test 5.3.5.1 {
  4392   5073     SELECT max(c) OVER win,
  4393   5074                min(c) OVER win,
  4394   5075                count(a) OVER win
  4395   5076         FROM t3
  4396         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
  4397         -      ORDER BY 1 , 2 , 3
         5077  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
         5078  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4398   5079   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4399   5080     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4400   5081     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4401   5082     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4402   5083     {} {} 0   158 158 1   160 160 1   160 160 1   223 223 1   224 224 1
  4403   5084     238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
  4404   5085     257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   354 354 1
................................................................................
  4412   5093     963 963 1}
  4413   5094   
  4414   5095   do_execsql_test 5.3.5.2 {
  4415   5096     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4416   5097                rank() OVER win,
  4417   5098                dense_rank() OVER win
  4418   5099         FROM t3
  4419         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
  4420         -      ORDER BY 1 , 2 , 3
         5100  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
         5101  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4421   5102   } {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  4422   5103     {} 9 7   {} 10 8   {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19
  4423   5104     {} 23 21   {} 25 23   {} 27 25   {} 27 25   {} 34 29   {} 35 30   {} 36 31
  4424   5105     {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  4425   5106     {} 43 37   {} 50 42   {} 56 47   {} 60 51   {} 61 52   {} 62 53   {} 64 55
  4426   5107     {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
  4427   5108     {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70
................................................................................
  4434   5115     2005 54 45   2523 75 64   2523 76 65}
  4435   5116   
  4436   5117   do_execsql_test 5.3.6.1 {
  4437   5118     SELECT max(c) OVER win,
  4438   5119                min(c) OVER win,
  4439   5120                count(a) OVER win
  4440   5121         FROM t3
  4441         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
  4442         -      ORDER BY 1 , 2 , 3
         5122  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
         5123  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4443   5124   } {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4444   5125     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4445   5126     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4446   5127     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4447   5128     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4448   5129     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
  4449   5130     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
................................................................................
  4455   5136     {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}
  4456   5137   
  4457   5138   do_execsql_test 5.3.6.2 {
  4458   5139     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4459   5140                rank() OVER win,
  4460   5141                dense_rank() OVER win
  4461   5142         FROM t3
  4462         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
  4463         -      ORDER BY 1 , 2 , 3
         5143  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
         5144  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4464   5145   } {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
  4465   5146     {} 9 7   {} 10 8   {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13
  4466   5147     {} 16 14   {} 17 15   {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20
  4467   5148     {} 23 21   {} 24 22   {} 25 23   {} 26 24   {} 27 25   {} 27 25   {} 29 26
  4468   5149     {} 29 26   {} 31 27   {} 32 28   {} 32 28   {} 34 29   {} 35 30   {} 36 31
  4469   5150     {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
  4470   5151     {} 43 37   {} 45 38   {} 46 39   {} 46 39   {} 48 40   {} 49 41   {} 50 42
................................................................................
  4476   5157     {} 85 72   {} 87 73   {} 88 74   {} 89 75}
  4477   5158   
  4478   5159   do_execsql_test 5.3.7.1 {
  4479   5160     SELECT max(c) OVER win,
  4480   5161                min(c) OVER win,
  4481   5162                count(a) OVER win
  4482   5163         FROM t3
  4483         -      WINDOW win AS (  ORDER BY c , b , a 
         5164  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
  4484   5165           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4485         -      ORDER BY 1 , 2 , 3
         5166  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4486   5167   } {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
  4487   5168     979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
  4488   5169     979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
  4489   5170     979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
  4490   5171     979 256 66   979 257 65   979 295 64   979 309 64   979 330 62   979 335 61
  4491   5172     979 336 60   979 346 59   979 354 59   979 355 57   979 355 57   979 393 55
  4492   5173     979 393 56   979 398 54   979 399 53   979 399 53   979 412 52   979 421 51
................................................................................
  4500   5181     979 870 9   979 870 10   979 870 10   979 899 8   979 911 7}
  4501   5182   
  4502   5183   do_execsql_test 5.3.7.2 {
  4503   5184     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4504   5185                rank() OVER win,
  4505   5186                dense_rank() OVER win
  4506   5187         FROM t3
  4507         -      WINDOW win AS (  ORDER BY c , b , a 
         5188  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
         5189  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5190  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5191  +} {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
         5192  +  5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
         5193  +  8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
         5194  +  9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
         5195  +  10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
         5196  +  13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
         5197  +  13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
         5198  +  17100 48 48   17104 46 46   17104 47 47   17106 45 45   17126 49 49
         5199  +  17126 50 50   17126 51 51   17569 42 42   17733 44 44   18176 43 43
         5200  +  18597 40 40   18597 41 41   18952 37 37   18996 39 39   19395 38 38
         5201  +  19760 35 35   19788 36 36   20492 32 32   20492 33 33   20498 30 30
         5202  +  20536 34 34   20833 29 29   20871 28 28   20891 31 31   21180 27 27
         5203  +  21752 23 23   21830 26 26   22025 21 21   22087 22 22   22087 24 24
         5204  +  22087 25 25   22278 20 20   22316 19 19   22549 15 15   22557 14 14
         5205  +  22573 17 17   22573 18 18   22706 10 10   22796 11 11   22796 12 12
         5206  +  22796 13 13   22796 16 16   23022 4 4   23042 2 2   23042 3 3   23042 9 9
         5207  +  23155 1 1   23155 5 5   23155 6 6   23155 7 7   23155 8 8}
         5208  +
         5209  +do_execsql_test 5.3.8.1 {
         5210  +  SELECT max(c) OVER win,
         5211  +             min(c) OVER win,
         5212  +             count(a) OVER win
         5213  +      FROM t3
         5214  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5215  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5216  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5217  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5218  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5219  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5220  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5221  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5222  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5223  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5224  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5225  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5226  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5227  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5228  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}
         5229  +
         5230  +do_execsql_test 5.3.8.2 {
         5231  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5232  +             rank() OVER win,
         5233  +             dense_rank() OVER win
         5234  +      FROM t3
         5235  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5236  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5237  +} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5238  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5239  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5240  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5241  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5242  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5243  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5244  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5245  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5246  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5247  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5248  +  {} 1 1}
         5249  +
         5250  +do_execsql_test 5.3.9.1 {
         5251  +  SELECT max(c) OVER win,
         5252  +             min(c) OVER win,
         5253  +             count(a) OVER win
         5254  +      FROM t3
         5255  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         5256  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5257  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5258  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   870 158 0
         5259  +  870 158 0   870 158 0   870 158 0   870 158 0   870 158 0   870 158 0
         5260  +  870 158 0   870 158 0   899 113 9   899 113 9   899 113 9   899 113 9
         5261  +  899 113 9   899 113 9   899 113 9   899 113 16   899 113 16   899 113 16
         5262  +  899 113 16   899 113 16   899 113 16   899 113 16   899 113 16   899 113 16
         5263  +  979 102 44   979 102 44   979 102 44   979 102 44   979 102 44   979 102 49
         5264  +  979 102 49   979 102 49   979 102 49   979 102 49   979 102 49   979 102 49
         5265  +  979 102 56   979 102 56   979 102 56   979 102 56   979 102 56   979 102 56
         5266  +  979 102 62   979 102 62   979 102 62   979 102 62   979 102 62   979 102 62
         5267  +  979 102 62   979 102 62   979 102 62   979 102 62   979 102 62   979 102 62
         5268  +  979 102 62   979 102 75   979 102 75   979 102 75   979 102 75   979 102 75
         5269  +  979 102 75   979 102 75   979 102 75   979 113 25   979 113 25   979 113 25
         5270  +  979 113 25   979 113 25   979 113 25   979 113 25   979 113 25   979 113 33
         5271  +  979 113 33   979 113 33   979 113 33   979 113 33   979 113 33   979 113 33
         5272  +  979 113 33   979 113 33   979 113 33   979 113 33}
         5273  +
         5274  +do_execsql_test 5.3.9.2 {
         5275  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5276  +             rank() OVER win,
         5277  +             dense_rank() OVER win
         5278  +      FROM t3
         5279  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         5280  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5281  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5282  +} {{} 84 11   {} 84 11   {} 84 11   {} 84 11   {} 84 11   {} 84 11
         5283  +  2050 75 10   2050 75 10   2050 75 10   2050 75 10   2050 75 10   2050 75 10
         5284  +  2050 75 10   2050 75 10   2050 75 10   4997 68 9   4997 68 9   4997 68 9
         5285  +  4997 68 9   4997 68 9   4997 68 9   4997 68 9   7337 59 8   7337 59 8
         5286  +  7337 59 8   7337 59 8   7337 59 8   7337 59 8   7337 59 8   7337 59 8
         5287  +  7337 59 8   10450 51 7   10450 51 7   10450 51 7   10450 51 7   10450 51 7
         5288  +  10450 51 7   10450 51 7   10450 51 7   11714 40 6   11714 40 6   11714 40 6
         5289  +  11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6
         5290  +  11714 40 6   11714 40 6   12676 35 5   12676 35 5   12676 35 5   12676 35 5
         5291  +  12676 35 5   14195 28 4   14195 28 4   14195 28 4   14195 28 4   14195 28 4
         5292  +  14195 28 4   14195 28 4   15999 22 3   15999 22 3   15999 22 3   15999 22 3
         5293  +  15999 22 3   15999 22 3   17365 9 2   17365 9 2   17365 9 2   17365 9 2
         5294  +  17365 9 2   17365 9 2   17365 9 2   17365 9 2   17365 9 2   17365 9 2
         5295  +  17365 9 2   17365 9 2   17365 9 2   20846 1 1   20846 1 1   20846 1 1
         5296  +  20846 1 1   20846 1 1   20846 1 1   20846 1 1   20846 1 1}
         5297  +
         5298  +do_execsql_test 5.3.10.1 {
         5299  +  SELECT max(c) OVER win,
         5300  +             min(c) OVER win,
         5301  +             count(a) OVER win
         5302  +      FROM t3
         5303  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         5304  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5305  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5306  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5307  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5308  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5309  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5310  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5311  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5312  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5313  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5314  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5315  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5316  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5317  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5318  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}
         5319  +
         5320  +do_execsql_test 5.3.10.2 {
         5321  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5322  +             rank() OVER win,
         5323  +             dense_rank() OVER win
         5324  +      FROM t3
         5325  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         5326  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5327  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5328  +} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5329  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5330  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5331  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5332  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5333  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5334  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5335  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5336  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5337  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5338  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5339  +  {} 1 1}
         5340  +
         5341  +do_execsql_test 5.3.11.1 {
         5342  +  SELECT max(c) OVER win,
         5343  +             min(c) OVER win,
         5344  +             count(a) OVER win
         5345  +      FROM t3
         5346  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
         5347  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5348  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5349  +  {} {} 0   934 158 27   934 158 27   934 158 27   934 158 27   934 158 27
         5350  +  934 158 27   934 158 27   934 223 8   934 223 8   934 223 8   934 223 8
         5351  +  934 223 8   934 223 8   934 223 8   934 223 8   934 223 8   934 223 8
         5352  +  934 223 8   934 223 8   934 223 8   934 223 21   934 223 21   934 223 21
         5353  +  934 223 21   934 223 21   934 223 21   959 102 50   959 102 50   959 102 50
         5354  +  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
         5355  +  959 102 50   959 102 50   959 102 50   959 102 50   959 102 50   959 102 50
         5356  +  959 102 50   959 102 50   959 113 39   959 113 39   959 113 39   959 113 39
         5357  +  959 113 39   959 113 39   959 113 39   959 113 39   959 113 39   959 113 39
         5358  +  959 113 39   959 158 34   959 158 34   959 158 34   959 158 34   959 158 34
         5359  +  979 102 46   979 102 46   979 102 46   979 102 46   979 102 46   979 102 46
         5360  +  979 102 46   979 102 47   979 102 47   979 102 47   979 102 47   979 102 47
         5361  +  979 102 47   979 102 47   979 102 47   979 102 47   979 102 49   979 102 49
         5362  +  979 102 49   979 102 49   979 102 49   979 102 49}
         5363  +
         5364  +do_execsql_test 5.3.11.2 {
         5365  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5366  +             rank() OVER win,
         5367  +             dense_rank() OVER win
         5368  +      FROM t3
         5369  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE GROUP  )
         5370  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5371  +} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5372  +  2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2
         5373  +  2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   5790 22 3
         5374  +  5790 22 3   5790 22 3   5790 22 3   5790 22 3   5790 22 3   7156 28 4
         5375  +  7156 28 4   7156 28 4   7156 28 4   7156 28 4   7156 28 4   7156 28 4
         5376  +  8960 35 5   8960 35 5   8960 35 5   8960 35 5   8960 35 5   10028 68 9
         5377  +  10028 68 9   10028 68 9   10028 68 9   10028 68 9   10028 68 9   10028 68 9
         5378  +  10396 59 8   10396 59 8   10396 59 8   10396 59 8   10396 59 8   10396 59 8
         5379  +  10396 59 8   10396 59 8   10396 59 8   10479 40 6   10479 40 6   10479 40 6
         5380  +  10479 40 6   10479 40 6   10479 40 6   10479 40 6   10479 40 6   10479 40 6
         5381  +  10479 40 6   10479 40 6   11002 75 10   11002 75 10   11002 75 10
         5382  +  11002 75 10   11002 75 10   11002 75 10   11002 75 10   11002 75 10
         5383  +  11002 75 10   11441 51 7   11441 51 7   11441 51 7   11441 51 7
         5384  +  11441 51 7   11441 51 7   11441 51 7   11441 51 7   12145 84 11
         5385  +  12145 84 11   12145 84 11   12145 84 11   12145 84 11   12145 84 11}
         5386  +
         5387  +do_execsql_test 5.3.12.1 {
         5388  +  SELECT max(c) OVER win,
         5389  +             min(c) OVER win,
         5390  +             count(a) OVER win
         5391  +      FROM t3
         5392  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
         5393  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5394  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5395  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5396  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5397  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5398  +  {} {} 0   158 158 1   160 160 1   160 160 1   223 223 1   224 224 1
         5399  +  238 234 2   239 234 2   239 238 2   252 250 2   256 252 2   257 247 4
         5400  +  257 247 4   257 250 3   335 330 2   336 330 2   336 335 2   354 354 1
         5401  +  354 354 1   355 355 1   398 393 3   398 393 3   399 393 3   399 398 2
         5402  +  399 398 2   572 572 1   574 574 1   633 629 2   634 627 3   634 627 3
         5403  +  634 627 3   634 629 3   667 667 1   670 667 2   671 667 2   671 670 2
         5404  +  671 670 2   711 711 1   711 711 1   716 705 2   726 726 1   730 730 1
         5405  +  762 762 1   762 762 1   762 762 1   768 759 3   792 790 2   792 790 2
         5406  +  794 786 3   794 786 3   844 839 4   845 839 4   845 839 4   845 840 3
         5407  +  845 840 3   934 934 1   934 934 1   934 934 1   938 929 3   959 959 1
         5408  +  963 963 1}
         5409  +
         5410  +do_execsql_test 5.3.12.2 {
         5411  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5412  +             rank() OVER win,
         5413  +             dense_rank() OVER win
         5414  +      FROM t3
         5415  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE GROUP  )
         5416  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5417  +} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
         5418  +  {} 9 7   {} 10 8   {} 14 12   {} 15 13   {} 19 17   {} 20 18   {} 21 19
         5419  +  {} 23 21   {} 25 23   {} 27 25   {} 27 25   {} 34 29   {} 35 30   {} 36 31
         5420  +  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
         5421  +  {} 43 37   {} 50 42   {} 56 47   {} 60 51   {} 61 52   {} 62 53   {} 64 55
         5422  +  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
         5423  +  {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70
         5424  +  {} 85 72   {} 85 72   {} 89 75   223 11 9   239 12 10   239 13 11
         5425  +  257 18 16   335 22 20   335 24 22   504 16 14   504 17 15   671 52 44
         5426  +  671 52 44   705 58 49   710 26 24   711 57 48   711 59 50   759 63 54
         5427  +  786 32 28   786 32 28   798 29 26   798 29 26   845 73 63   845 73 63
         5428  +  929 84 71   959 88 74   963 87 73   1260 46 39   1260 46 39   1334 51 43
         5429  +  1334 55 46   1584 31 27   1678 77 66   1885 48 40   1891 45 38   1891 49 41
         5430  +  2005 54 45   2523 75 64   2523 76 65}
         5431  +
         5432  +do_execsql_test 5.3.13.1 {
         5433  +  SELECT max(c) OVER win,
         5434  +             min(c) OVER win,
         5435  +             count(a) OVER win
         5436  +      FROM t3
         5437  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
         5438  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5439  +} {{} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5440  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5441  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5442  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5443  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5444  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5445  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5446  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5447  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5448  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5449  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5450  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0
         5451  +  {} {} 0   {} {} 0   {} {} 0   {} {} 0   {} {} 0}
         5452  +
         5453  +do_execsql_test 5.3.13.2 {
         5454  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5455  +             rank() OVER win,
         5456  +             dense_rank() OVER win
         5457  +      FROM t3
         5458  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE GROUP  )
         5459  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5460  +} {{} 1 1   {} 2 2   {} 2 2   {} 4 3   {} 5 4   {} 6 5   {} 6 5   {} 8 6
         5461  +  {} 9 7   {} 10 8   {} 11 9   {} 12 10   {} 13 11   {} 14 12   {} 15 13
         5462  +  {} 16 14   {} 17 15   {} 18 16   {} 19 17   {} 20 18   {} 21 19   {} 22 20
         5463  +  {} 23 21   {} 24 22   {} 25 23   {} 26 24   {} 27 25   {} 27 25   {} 29 26
         5464  +  {} 29 26   {} 31 27   {} 32 28   {} 32 28   {} 34 29   {} 35 30   {} 36 31
         5465  +  {} 37 32   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 42 36   {} 43 37
         5466  +  {} 43 37   {} 45 38   {} 46 39   {} 46 39   {} 48 40   {} 49 41   {} 50 42
         5467  +  {} 51 43   {} 52 44   {} 52 44   {} 54 45   {} 55 46   {} 56 47   {} 57 48
         5468  +  {} 58 49   {} 59 50   {} 60 51   {} 61 52   {} 62 53   {} 63 54   {} 64 55
         5469  +  {} 64 55   {} 66 56   {} 67 57   {} 68 58   {} 69 59   {} 70 60   {} 71 61
         5470  +  {} 72 62   {} 73 63   {} 73 63   {} 75 64   {} 76 65   {} 77 66   {} 78 67
         5471  +  {} 78 67   {} 78 67   {} 81 68   {} 82 69   {} 83 70   {} 84 71   {} 85 72
         5472  +  {} 85 72   {} 87 73   {} 88 74   {} 89 75}
         5473  +
         5474  +do_execsql_test 5.3.14.1 {
         5475  +  SELECT max(c) OVER win,
         5476  +             min(c) OVER win,
         5477  +             count(a) OVER win
         5478  +      FROM t3
         5479  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
         5480  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
         5481  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5482  +} {963 929 6   979 102 82   979 102 82   979 102 82   979 102 82   979 102 82
         5483  +  979 102 83   979 113 80   979 113 81   979 113 82   979 133 79   979 148 78
         5484  +  979 158 76   979 158 77   979 160 76   979 208 75   979 223 74   979 224 73
         5485  +  979 234 72   979 238 71   979 239 70   979 247 69   979 250 68   979 252 67
         5486  +  979 256 66   979 257 65   979 295 64   979 309 63   979 330 63   979 335 61
         5487  +  979 336 60   979 346 59   979 354 58   979 355 56   979 355 58   979 393 55
         5488  +  979 393 56   979 398 54   979 399 52   979 399 53   979 412 52   979 421 51
         5489  +  979 430 50   979 443 49   979 480 47   979 480 48   979 572 46   979 574 46
         5490  +  979 607 44   979 618 42   979 618 43   979 627 41   979 629 40   979 629 40
         5491  +  979 633 39   979 634 38   979 652 37   979 660 36   979 667 34   979 667 35
         5492  +  979 670 34   979 671 33   979 683 32   979 705 31   979 711 30   979 716 29
         5493  +  979 726 28   979 730 27   979 759 26   979 762 25   979 768 23   979 768 24
         5494  +  979 777 22   979 786 21   979 790 20   979 792 19   979 794 18   979 805 17
         5495  +  979 822 16   979 839 15   979 839 15   979 840 13   979 844 12   979 845 11
         5496  +  979 870 8   979 870 9   979 870 10   979 899 8   979 911 7}
         5497  +
         5498  +do_execsql_test 5.3.14.2 {
         5499  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5500  +             rank() OVER win,
         5501  +             dense_rank() OVER win
         5502  +      FROM t3
         5503  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
  4508   5504           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE GROUP  )
  4509         -      ORDER BY 1 , 2 , 3
         5505  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4510   5506   } {2851 89 89   3778 88 88   4681 87 87   5556 83 83   5574 82 82   5586 81 81
  4511   5507     5640 84 84   5640 85 85   5640 86 86   7324 80 80   8123 77 77   8129 73 73
  4512   5508     8129 74 74   8163 78 78   8163 79 79   8940 71 71   8968 75 75   8968 76 76
  4513   5509     9727 66 66   9745 69 69   9745 70 70   9745 72 72   10504 65 65
  4514   5510     10504 67 67   10504 68 68   11215 64 64   11844 62 62   11920 63 63
  4515   5511     13274 60 60   13274 61 61   13897 58 58   13903 57 57   13925 56 56
  4516   5512     13937 55 55   13941 59 59   15203 53 53   15241 54 54   15832 52 52
................................................................................
  4527   5523   
  4528   5524   do_execsql_test 5.4.1.1 {
  4529   5525     SELECT max(c) OVER win,
  4530   5526                min(c) OVER win,
  4531   5527                count(a) OVER win
  4532   5528         FROM t3
  4533   5529         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4534         -      ORDER BY 1 , 2 , 3
         5530  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4535   5531   } {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  4536   5532     158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  4537   5533     238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  4538   5534     257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  4539   5535     346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  4540   5536     398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  4541   5537     443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
................................................................................
  4550   5546   
  4551   5547   do_execsql_test 5.4.1.2 {
  4552   5548     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4553   5549                rank() OVER win,
  4554   5550                dense_rank() OVER win
  4555   5551         FROM t3
  4556   5552         WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4557         -      ORDER BY 1 , 2 , 3
         5553  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4558   5554   } {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4559   5555     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4560   5556     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4561   5557     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4562   5558     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4563   5559     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4564   5560     113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
................................................................................
  4569   5565     899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}
  4570   5566   
  4571   5567   do_execsql_test 5.4.2.1 {
  4572   5568     SELECT max(c) OVER win,
  4573   5569                min(c) OVER win,
  4574   5570                count(a) OVER win
  4575   5571         FROM t3
  4576         -      WINDOW win AS (  ORDER BY a  
         5572  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  4577   5573           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4578         -      ORDER BY 1 , 2 , 3
         5574  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4579   5575   } {113 113 1   234 234 1   257 257 1   336 336 1   354 354 1   768 768 1
  4580   5576     839 839 1   839 839 1   899 113 10   899 113 10   899 113 10   899 113 10
  4581   5577     899 113 10   899 113 10   899 113 10   899 113 17   899 113 17   899 113 17
  4582   5578     899 113 17   899 113 17   899 113 17   899 113 17   899 899 1   963 113 17
  4583   5579     979 102 34   979 102 45   979 102 45   979 102 45   979 102 45   979 102 45
  4584   5580     979 102 50   979 102 50   979 102 50   979 102 50   979 102 50   979 102 50
  4585   5581     979 102 50   979 102 57   979 102 57   979 102 57   979 102 57   979 102 57
................................................................................
  4593   5589     979 113 34   979 113 34   979 113 34   979 113 34   979 113 34}
  4594   5590   
  4595   5591   do_execsql_test 5.4.2.2 {
  4596   5592     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4597   5593                rank() OVER win,
  4598   5594                dense_rank() OVER win
  4599   5595         FROM t3
  4600         -      WINDOW win AS (  ORDER BY a  
         5596  +      WINDOW win AS (  ORDER BY a NULLS FIRST 
  4601   5597           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4602         -      ORDER BY 1 , 2 , 3
         5598  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4603   5599   } {{} 81 11   {} 81 11   {} 81 11   {} 81 11   113 81 11   257 81 11
  4604   5600     839 81 11   839 81 11   899 81 11   2947 74 10   2947 74 10   2947 74 10
  4605   5601     3368 74 10   3390 74 10   3618 74 10   3752 74 10   5287 65 9   5287 65 9
  4606   5602     5287 65 9   5287 65 9   5420 65 9   5642 65 9   5970 65 9   6250 65 9
  4607   5603     6266 65 9   8400 57 8   8400 57 8   8400 57 8   8400 57 8   8400 57 8
  4608   5604     8400 57 8   8735 57 8   9329 57 8   9664 46 7   9664 46 7   9664 46 7
  4609   5605     9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7   9664 46 7
................................................................................
  4619   5615   do_execsql_test 5.4.3.1 {
  4620   5616     SELECT max(c) OVER win,
  4621   5617                min(c) OVER win,
  4622   5618                count(a) OVER win
  4623   5619         FROM t3
  4624   5620         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  4625   5621           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4626         -      ORDER BY 1 , 2 , 3
         5622  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4627   5623   } {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  4628   5624     158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  4629   5625     238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  4630   5626     257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  4631   5627     346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  4632   5628     398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  4633   5629     443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
................................................................................
  4643   5639   do_execsql_test 5.4.3.2 {
  4644   5640     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4645   5641                rank() OVER win,
  4646   5642                dense_rank() OVER win
  4647   5643         FROM t3
  4648   5644         WINDOW win AS (  PARTITION BY coalesce(a, '') 
  4649   5645           RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4650         -      ORDER BY 1 , 2 , 3
         5646  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4651   5647   } {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4652   5648     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4653   5649     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4654   5650     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4655   5651     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4656   5652     {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
  4657   5653     113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
................................................................................
  4662   5658     899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}
  4663   5659   
  4664   5660   do_execsql_test 5.4.4.1 {
  4665   5661     SELECT max(c) OVER win,
  4666   5662                min(c) OVER win,
  4667   5663                count(a) OVER win
  4668   5664         FROM t3
  4669         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE TIES  )
  4670         -      ORDER BY 1 , 2 , 3
         5665  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE TIES  )
         5666  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4671   5667   } {158 158 0   355 355 0   399 399 0   629 629 0   667 667 0   870 158 1
  4672   5668     870 158 1   870 158 1   870 158 1   870 158 1   870 158 1   870 870 0
  4673   5669     911 158 1   934 158 1   934 158 9   934 158 9   934 158 9   934 158 9
  4674   5670     934 158 9   934 158 9   934 158 9   934 158 9   934 158 9   934 158 9
  4675   5671     934 158 9   934 158 9   934 158 9   934 158 22   934 158 22   934 158 22
  4676   5672     934 158 22   934 158 22   934 158 22   934 158 28   934 158 28   934 158 28
  4677   5673     934 158 28   934 158 28   934 158 28   959 102 40   959 102 51   959 102 51
................................................................................
  4685   5681     979 102 48   979 102 48   979 102 48   979 102 48   979 102 51}
  4686   5682   
  4687   5683   do_execsql_test 5.4.4.2 {
  4688   5684     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4689   5685                rank() OVER win,
  4690   5686                dense_rank() OVER win
  4691   5687         FROM t3
  4692         -      WINDOW win AS (  ORDER BY a  GROUPS 6 PRECEDING   EXCLUDE TIES  )
  4693         -      ORDER BY 1 , 2 , 3
         5688  +      WINDOW win AS (  ORDER BY a NULLS FIRST GROUPS 6 PRECEDING   EXCLUDE TIES  )
         5689  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4694   5690   } {{} 1 1   {} 1 1   355 1 1   399 1 1   629 1 1   667 1 1   2050 7 2
  4695   5691     2050 7 2   2050 7 2   2273 7 2   2289 7 2   2359 7 2   2677 7 2   2961 7 2
  4696   5692     4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3   4359 15 3
  4697   5693     4606 15 3   4752 15 3   4752 15 3   4758 15 3   4992 15 3   5064 15 3
  4698   5694     5070 15 3   7840 28 4   7840 28 4   7840 28 4   7840 28 4   8447 28 4
  4699   5695     8599 28 4   9206 34 5   9206 34 5   9206 34 5   9206 34 5   9206 34 5
  4700   5696     10028 74 10   10028 74 10   10028 74 10   10051 34 5   10165 34 5
................................................................................
  4709   5705     12529 46 7   12529 46 7   12824 46 7   13196 46 7}
  4710   5706   
  4711   5707   do_execsql_test 5.4.5.1 {
  4712   5708     SELECT max(c) OVER win,
  4713   5709                min(c) OVER win,
  4714   5710                count(a) OVER win
  4715   5711         FROM t3
  4716         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
  4717         -      ORDER BY 1 , 2 , 3
         5712  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
         5713  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4718   5714   } {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   160 158 1
  4719   5715     160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
  4720   5716     239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
  4721   5717     257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
  4722   5718     346 346 1   355 354 1   355 354 2   355 354 2   399 393 3   399 393 3
  4723   5719     399 393 3   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
  4724   5720     443 443 1   480 480 1   480 480 1   574 572 2   574 572 2   607 607 1
................................................................................
  4732   5728     938 934 2   938 934 2   963 959 2   963 959 2   979 979 1}
  4733   5729   
  4734   5730   do_execsql_test 5.4.5.2 {
  4735   5731     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4736   5732                rank() OVER win,
  4737   5733                dense_rank() OVER win
  4738   5734         FROM t3
  4739         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
  4740         -      ORDER BY 1 , 2 , 3
         5735  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
         5736  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4741   5737   } {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
  4742   5738     {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
  4743   5739     {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
  4744   5740     {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
  4745   5741     {} 85 72   113 2 2   113 2 2   133 4 3   223 10 8   223 11 9   239 12 10
  4746   5742     239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
  4747   5743     309 21 19   335 22 20   335 23 21   335 24 22   355 27 25   355 27 25
................................................................................
  4754   5750     2518 45 38   2518 48 40   2523 75 64   2523 76 65   2523 77 66}
  4755   5751   
  4756   5752   do_execsql_test 5.4.6.1 {
  4757   5753     SELECT max(c) OVER win,
  4758   5754                min(c) OVER win,
  4759   5755                count(a) OVER win
  4760   5756         FROM t3
  4761         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
  4762         -      ORDER BY 1 , 2 , 3
         5757  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
         5758  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4763   5759   } {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
  4764   5760     158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
  4765   5761     238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
  4766   5762     257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
  4767   5763     346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
  4768   5764     398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
  4769   5765     443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
................................................................................
  4777   5773     938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}
  4778   5774   
  4779   5775   do_execsql_test 5.4.6.2 {
  4780   5776     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4781   5777                rank() OVER win,
  4782   5778                dense_rank() OVER win
  4783   5779         FROM t3
  4784         -      WINDOW win AS (  ORDER BY c  RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
  4785         -      ORDER BY 1 , 2 , 3
         5780  +      WINDOW win AS (  ORDER BY c NULLS FIRST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
         5781  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4786   5782   } {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
  4787   5783     {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
  4788   5784     {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
  4789   5785     {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
  4790   5786     {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
  4791   5787     {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
  4792   5788     {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   113 2 2   113 2 2
................................................................................
  4799   5795     959 87 73   963 88 74   979 89 75}
  4800   5796   
  4801   5797   do_execsql_test 5.4.7.1 {
  4802   5798     SELECT max(c) OVER win,
  4803   5799                min(c) OVER win,
  4804   5800                count(a) OVER win
  4805   5801         FROM t3
  4806         -      WINDOW win AS (  ORDER BY c , b , a 
         5802  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
  4807   5803           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4808         -      ORDER BY 1 , 2 , 3
         5804  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4809   5805   } {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
  4810   5806     979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
  4811   5807     979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
  4812   5808     979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
  4813   5809     979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
  4814   5810     979 346 60   979 354 59   979 355 58   979 355 58   979 393 56   979 393 57
  4815   5811     979 398 55   979 399 54   979 399 54   979 412 53   979 421 52   979 430 51
................................................................................
  4823   5819     979 870 11   979 870 11   979 899 9   979 911 8   979 929 7}
  4824   5820   
  4825   5821   do_execsql_test 5.4.7.2 {
  4826   5822     SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
  4827   5823                rank() OVER win,
  4828   5824                dense_rank() OVER win
  4829   5825         FROM t3
  4830         -      WINDOW win AS (  ORDER BY c , b , a 
         5826  +      WINDOW win AS (  ORDER BY c NULLS FIRST, b NULLS FIRST, a NULLS FIRST
         5827  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         5828  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5829  +} {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
         5830  +  6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
         5831  +  8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
         5832  +  9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
         5833  +  10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
         5834  +  13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
         5835  +  14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
         5836  +  17126 49 49   17126 50 50   17126 51 51   17733 44 44   17733 45 45
         5837  +  17733 46 46   17733 47 47   17733 48 48   18176 42 42   18176 43 43
         5838  +  18597 40 40   18597 41 41   18996 39 39   19395 37 37   19395 38 38
         5839  +  19788 36 36   20181 35 35   20536 34 34   20891 30 30   20891 31 31
         5840  +  20891 32 32   20891 33 33   21226 28 28   21226 29 29   21535 27 27
         5841  +  21830 26 26   22087 22 22   22087 23 23   22087 24 24   22087 25 25
         5842  +  22334 21 21   22573 17 17   22573 18 18   22573 19 19   22573 20 20
         5843  +  22796 11 11   22796 12 12   22796 13 13   22796 14 14   22796 15 15
         5844  +  22796 16 16   22929 10 10   23042 9 9   23155 1 1   23155 2 2   23155 3 3
         5845  +  23155 4 4   23155 5 5   23155 6 6   23155 7 7   23155 8 8}
         5846  +
         5847  +do_execsql_test 5.4.8.1 {
         5848  +  SELECT max(c) OVER win,
         5849  +             min(c) OVER win,
         5850  +             count(a) OVER win
         5851  +      FROM t3
         5852  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         5853  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5854  +} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
         5855  +  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
         5856  +  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
         5857  +  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
         5858  +  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
         5859  +  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
         5860  +  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
         5861  +  618 618 1   618 618 1   627 627 1   629 629 0   629 629 1   633 633 1
         5862  +  634 634 1   652 652 1   660 660 1   667 667 0   667 667 1   670 670 1
         5863  +  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
         5864  +  730 730 1   759 759 1   762 762 1   768 768 1   768 768 1   777 777 1
         5865  +  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
         5866  +  839 839 1   839 839 1   840 840 1   844 844 1   845 845 1   870 870 0
         5867  +  870 870 1   870 870 1   899 899 1   911 911 1   929 929 1   934 934 1
         5868  +  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}
         5869  +
         5870  +do_execsql_test 5.4.8.2 {
         5871  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5872  +             rank() OVER win,
         5873  +             dense_rank() OVER win
         5874  +      FROM t3
         5875  +      WINDOW win AS (  RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         5876  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5877  +} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5878  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5879  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5880  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5881  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5882  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5883  +  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
         5884  +  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
         5885  +  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
         5886  +  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
         5887  +  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
         5888  +  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}
         5889  +
         5890  +do_execsql_test 5.4.9.1 {
         5891  +  SELECT max(c) OVER win,
         5892  +             min(c) OVER win,
         5893  +             count(a) OVER win
         5894  +      FROM t3
         5895  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         5896  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         5897  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5898  +} {158 158 0   355 355 0   399 399 0   629 629 0   667 667 0   870 113 1
         5899  +  870 158 1   870 158 1   870 158 1   870 158 1   870 158 1   870 158 1
         5900  +  870 158 1   870 870 0   899 113 10   899 113 10   899 113 10   899 113 10
         5901  +  899 113 10   899 113 10   899 113 10   899 113 17   899 113 17   899 113 17
         5902  +  899 113 17   899 113 17   899 113 17   899 113 17   899 158 1   963 113 17
         5903  +  979 102 34   979 102 45   979 102 45   979 102 45   979 102 45   979 102 45
         5904  +  979 102 50   979 102 50   979 102 50   979 102 50   979 102 50   979 102 50
         5905  +  979 102 50   979 102 57   979 102 57   979 102 57   979 102 57   979 102 57
         5906  +  979 102 57   979 102 63   979 102 63   979 102 63   979 102 63   979 102 63
         5907  +  979 102 63   979 102 63   979 102 63   979 102 63   979 102 63   979 102 63
         5908  +  979 102 63   979 102 63   979 102 76   979 102 76   979 102 76   979 102 76
         5909  +  979 102 76   979 102 76   979 102 76   979 102 76   979 113 17   979 113 26
         5910  +  979 113 26   979 113 26   979 113 26   979 113 26   979 113 26   979 113 26
         5911  +  979 113 26   979 113 34   979 113 34   979 113 34   979 113 34   979 113 34
         5912  +  979 113 34   979 113 34   979 113 34   979 113 34   979 113 34}
         5913  +
         5914  +do_execsql_test 5.4.9.2 {
         5915  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5916  +             rank() OVER win,
         5917  +             dense_rank() OVER win
         5918  +      FROM t3
         5919  +      WINDOW win AS (  ORDER BY a NULLS LAST 
         5920  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         5921  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5922  +} {{} 84 11   {} 84 11   355 84 11   399 84 11   629 84 11   667 84 11
         5923  +  2050 75 10   2050 75 10   2050 75 10   2050 75 10   2163 75 10   2307 75 10
         5924  +  2889 75 10   2889 75 10   2949 75 10   4997 68 9   4997 68 9   4997 68 9
         5925  +  5418 68 9   5440 68 9   5668 68 9   5802 68 9   7337 59 8   7337 59 8
         5926  +  7337 59 8   7337 59 8   7470 59 8   7692 59 8   8020 59 8   8300 59 8
         5927  +  8316 59 8   10450 51 7   10450 51 7   10450 51 7   10450 51 7   10450 51 7
         5928  +  10450 51 7   10785 51 7   11379 51 7   11714 40 6   11714 40 6   11714 40 6
         5929  +  11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6   11714 40 6
         5930  +  12009 40 6   12381 40 6   12676 35 5   12676 35 5   12789 35 5   13305 35 5
         5931  +  13453 35 5   14195 28 4   14195 28 4   14195 28 4   14195 28 4   14195 28 4
         5932  +  15040 28 4   15154 28 4   15999 22 3   15999 22 3   15999 22 3   15999 22 3
         5933  +  16606 22 3   16758 22 3   17365 9 2   17365 9 2   17365 9 2   17365 9 2
         5934  +  17365 9 2   17365 9 2   17612 9 2   17758 9 2   17758 9 2   17764 9 2
         5935  +  17998 9 2   18070 9 2   18076 9 2   20846 1 1   20846 1 1   20846 1 1
         5936  +  21069 1 1   21085 1 1   21155 1 1   21473 1 1   21757 1 1}
         5937  +
         5938  +do_execsql_test 5.4.10.1 {
         5939  +  SELECT max(c) OVER win,
         5940  +             min(c) OVER win,
         5941  +             count(a) OVER win
         5942  +      FROM t3
         5943  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         5944  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         5945  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5946  +} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
         5947  +  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
         5948  +  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
         5949  +  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
         5950  +  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
         5951  +  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
         5952  +  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
         5953  +  618 618 1   618 618 1   627 627 1   629 629 0   629 629 1   633 633 1
         5954  +  634 634 1   652 652 1   660 660 1   667 667 0   667 667 1   670 670 1
         5955  +  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
         5956  +  730 730 1   759 759 1   762 762 1   768 768 1   768 768 1   777 777 1
         5957  +  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
         5958  +  839 839 1   839 839 1   840 840 1   844 844 1   845 845 1   870 870 0
         5959  +  870 870 1   870 870 1   899 899 1   911 911 1   929 929 1   934 934 1
         5960  +  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}
         5961  +
         5962  +do_execsql_test 5.4.10.2 {
         5963  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         5964  +             rank() OVER win,
         5965  +             dense_rank() OVER win
         5966  +      FROM t3
         5967  +      WINDOW win AS (  PARTITION BY coalesce(a, '') 
         5968  +        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         5969  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5970  +} {{} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5971  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5972  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5973  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5974  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5975  +  {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1   {} 1 1
         5976  +  113 1 1   113 1 1   133 1 1   223 1 1   239 1 1   247 1 1   257 1 1
         5977  +  295 1 1   309 1 1   335 1 1   355 1 1   355 1 1   393 1 1   393 1 1
         5978  +  399 1 1   399 1 1   421 1 1   443 1 1   607 1 1   627 1 1   629 1 1
         5979  +  629 1 1   633 1 1   667 1 1   667 1 1   671 1 1   683 1 1   705 1 1
         5980  +  711 1 1   759 1 1   777 1 1   805 1 1   839 1 1   839 1 1   845 1 1
         5981  +  899 1 1   911 1 1   929 1 1   959 1 1   963 1 1   979 1 1}
         5982  +
         5983  +do_execsql_test 5.4.11.1 {
         5984  +  SELECT max(c) OVER win,
         5985  +             min(c) OVER win,
         5986  +             count(a) OVER win
         5987  +      FROM t3
         5988  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE TIES  )
         5989  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         5990  +} {223 223 1   239 239 1   309 309 1   572 572 1   627 627 1   870 870 1
         5991  +  911 911 1   934 158 22   934 158 28   934 158 28   934 158 28   934 158 28
         5992  +  934 158 28   934 158 28   934 223 9   934 223 9   934 223 9   934 223 9
         5993  +  934 223 9   934 223 9   934 223 9   934 223 9   934 223 9   934 223 9
         5994  +  934 223 9   934 223 9   934 223 9   934 223 22   934 223 22   934 223 22
         5995  +  934 223 22   934 223 22   934 934 1   959 102 40   959 102 51   959 102 51
         5996  +  959 102 51   959 102 51   959 102 51   959 102 51   959 102 51   959 102 51
         5997  +  959 102 51   959 102 51   959 102 51   959 102 51   959 102 51   959 102 51
         5998  +  959 102 51   959 113 35   959 113 40   959 113 40   959 113 40   959 113 40
         5999  +  959 113 40   959 113 40   959 113 40   959 113 40   959 113 40   959 113 40
         6000  +  959 158 28   959 158 35   959 158 35   959 158 35   959 158 35   963 102 51
         6001  +  979 102 47   979 102 47   979 102 47   979 102 47   979 102 47   979 102 47
         6002  +  979 102 47   979 102 48   979 102 48   979 102 48   979 102 48   979 102 48
         6003  +  979 102 48   979 102 48   979 102 48   979 102 48   979 102 49   979 102 49
         6004  +  979 102 49   979 102 49   979 102 49   979 102 49   979 102 51}
         6005  +
         6006  +do_execsql_test 5.4.11.2 {
         6007  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         6008  +             rank() OVER win,
         6009  +             dense_rank() OVER win
         6010  +      FROM t3
         6011  +      WINDOW win AS (  ORDER BY a NULLS LAST GROUPS 6 PRECEDING   EXCLUDE TIES  )
         6012  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         6013  +} {{} 1 1   {} 1 1   {} 1 1   223 1 1   239 1 1   309 1 1   627 1 1   911 1 1
         6014  +  2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2309 9 2   2556 9 2
         6015  +  2702 9 2   2702 9 2   2708 9 2   2942 9 2   3014 9 2   3020 9 2   5790 22 3
         6016  +  5790 22 3   5790 22 3   5790 22 3   6397 22 3   6549 22 3   7156 28 4
         6017  +  7156 28 4   7156 28 4   7156 28 4   7156 28 4   8001 28 4   8115 28 4
         6018  +  8960 35 5   8960 35 5   9073 35 5   9589 35 5   9737 35 5   10028 68 9
         6019  +  10028 68 9   10028 68 9   10396 59 8   10396 59 8   10396 59 8   10396 59 8
         6020  +  10449 68 9   10471 68 9   10479 40 6   10479 40 6   10479 40 6   10479 40 6
         6021  +  10479 40 6   10479 40 6   10479 40 6   10479 40 6   10479 40 6   10529 59 8
         6022  +  10699 68 9   10751 59 8   10774 40 6   10833 68 9   11002 75 10
         6023  +  11002 75 10   11002 75 10   11002 75 10   11079 59 8   11115 75 10
         6024  +  11146 40 6   11259 75 10   11359 59 8   11375 59 8   11441 51 7
         6025  +  11441 51 7   11441 51 7   11441 51 7   11441 51 7   11441 51 7   11776 51 7
         6026  +  11841 75 10   11841 75 10   11901 75 10   12145 84 11   12145 84 11
         6027  +  12370 51 7   12500 84 11   12544 84 11   12774 84 11   12812 84 11}
         6028  +
         6029  +do_execsql_test 5.4.12.1 {
         6030  +  SELECT max(c) OVER win,
         6031  +             min(c) OVER win,
         6032  +             count(a) OVER win
         6033  +      FROM t3
         6034  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
         6035  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         6036  +} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   160 158 1
         6037  +  160 158 2   160 158 2   208 208 1   224 223 2   224 223 2   239 234 3
         6038  +  239 234 3   239 234 3   252 247 3   257 247 5   257 247 5   257 250 4
         6039  +  257 252 3   295 295 1   309 309 1   336 330 3   336 330 3   336 330 3
         6040  +  346 346 1   355 354 1   355 354 2   355 354 2   399 393 3   399 393 3
         6041  +  399 393 3   399 393 4   399 393 4   412 412 1   421 421 1   430 430 1
         6042  +  443 443 1   480 480 1   480 480 1   574 572 2   574 572 2   607 607 1
         6043  +  618 618 1   618 618 1   634 627 3   634 627 4   634 627 4   634 627 4
         6044  +  634 629 3   652 652 1   667 660 2   671 667 2   671 667 3   671 667 3
         6045  +  671 667 3   683 683 1   711 705 2   716 705 3   716 711 2   730 726 2
         6046  +  730 726 2   762 759 2   768 759 4   768 762 2   768 762 2   777 777 1
         6047  +  792 786 3   794 786 4   794 786 4   794 790 3   805 805 1   822 822 1
         6048  +  845 839 4   845 839 4   845 839 5   845 839 5   845 839 5   870 870 0
         6049  +  870 870 1   870 870 1   899 899 1   911 911 1   934 929 2   938 929 4
         6050  +  938 934 2   938 934 2   963 959 2   963 959 2   979 979 1}
         6051  +
         6052  +do_execsql_test 5.4.12.2 {
         6053  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         6054  +             rank() OVER win,
         6055  +             dense_rank() OVER win
         6056  +      FROM t3
         6057  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 6 PRECEDING AND 7 FOLLOWING   EXCLUDE TIES  )
         6058  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         6059  +} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 25 23   {} 34 29
         6060  +  {} 36 31   {} 38 33   {} 38 33   {} 40 34   {} 41 35   {} 43 37   {} 43 37
         6061  +  {} 50 42   {} 60 51   {} 61 52   {} 64 55   {} 64 55   {} 67 57   {} 68 58
         6062  +  {} 69 59   {} 70 60   {} 72 62   {} 78 67   {} 78 67   {} 78 67   {} 85 72
         6063  +  {} 85 72   113 2 2   113 2 2   133 4 3   223 10 8   223 11 9   239 12 10
         6064  +  239 13 11   239 14 12   247 15 13   257 18 16   257 19 17   295 20 18
         6065  +  309 21 19   335 22 20   335 23 21   335 24 22   355 27 25   355 27 25
         6066  +  421 35 30   443 37 32   504 16 14   504 17 15   607 42 36   683 56 47
         6067  +  710 26 24   711 59 50   759 62 53   759 63 54   777 66 56   805 71 61
         6068  +  899 81 68   911 82 69   929 83 70   929 84 71   979 89 75   1185 32 28
         6069  +  1185 32 28   1191 29 26   1191 29 26   1334 51 43   1338 52 44   1338 52 44
         6070  +  1416 57 48   1416 58 49   1584 31 27   1684 73 63   1684 73 63   1889 46 39
         6071  +  1889 46 39   1891 49 41   1922 87 73   1922 88 74   2005 54 45   2005 55 46
         6072  +  2518 45 38   2518 48 40   2523 75 64   2523 76 65   2523 77 66}
         6073  +
         6074  +do_execsql_test 5.4.13.1 {
         6075  +  SELECT max(c) OVER win,
         6076  +             min(c) OVER win,
         6077  +             count(a) OVER win
         6078  +      FROM t3
         6079  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
         6080  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         6081  +} {102 102 1   113 113 1   113 113 1   133 133 1   148 148 1   158 158 0
         6082  +  158 158 1   160 160 1   208 208 1   223 223 1   224 224 1   234 234 1
         6083  +  238 238 1   239 239 1   247 247 1   250 250 1   252 252 1   256 256 1
         6084  +  257 257 1   295 295 1   309 309 1   330 330 1   335 335 1   336 336 1
         6085  +  346 346 1   354 354 1   355 355 0   355 355 1   393 393 1   393 393 1
         6086  +  398 398 1   399 399 0   399 399 1   412 412 1   421 421 1   430 430 1
         6087  +  443 443 1   480 480 1   480 480 1   572 572 1   574 574 1   607 607 1
         6088  +  618 618 1   618 618 1   627 627 1   629 629 0   629 629 1   633 633 1
         6089  +  634 634 1   652 652 1   660 660 1   667 667 0   667 667 1   670 670 1
         6090  +  671 671 1   683 683 1   705 705 1   711 711 1   716 716 1   726 726 1
         6091  +  730 730 1   759 759 1   762 762 1   768 768 1   768 768 1   777 777 1
         6092  +  786 786 1   790 790 1   792 792 1   794 794 1   805 805 1   822 822 1
         6093  +  839 839 1   839 839 1   840 840 1   844 844 1   845 845 1   870 870 0
         6094  +  870 870 1   870 870 1   899 899 1   911 911 1   929 929 1   934 934 1
         6095  +  938 938 1   938 938 1   959 959 1   963 963 1   979 979 1}
         6096  +
         6097  +do_execsql_test 5.4.13.2 {
         6098  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         6099  +             rank() OVER win,
         6100  +             dense_rank() OVER win
         6101  +      FROM t3
         6102  +      WINDOW win AS (  ORDER BY c NULLS LAST RANGE BETWEEN 0 PRECEDING AND 0 FOLLOWING   EXCLUDE TIES  )
         6103  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         6104  +} {{} 1 1   {} 5 4   {} 6 5   {} 6 5   {} 8 6   {} 9 7   {} 11 9   {} 12 10
         6105  +  {} 13 11   {} 16 14   {} 17 15   {} 18 16   {} 22 20   {} 24 22   {} 25 23
         6106  +  {} 26 24   {} 31 27   {} 34 29   {} 36 31   {} 38 33   {} 38 33   {} 40 34
         6107  +  {} 41 35   {} 43 37   {} 43 37   {} 49 41   {} 50 42   {} 51 43   {} 54 45
         6108  +  {} 59 50   {} 60 51   {} 61 52   {} 63 54   {} 64 55   {} 64 55   {} 67 57
         6109  +  {} 68 58   {} 69 59   {} 70 60   {} 72 62   {} 75 64   {} 76 65   {} 78 67
         6110  +  {} 78 67   {} 78 67   {} 84 71   {} 85 72   {} 85 72   113 2 2   113 2 2
         6111  +  133 4 3   223 10 8   239 14 12   247 15 13   257 19 17   295 20 18
         6112  +  309 21 19   335 23 21   355 27 25   355 27 25   393 29 26   393 29 26
         6113  +  399 32 28   399 32 28   421 35 30   443 37 32   607 42 36   627 45 38
         6114  +  629 46 39   629 46 39   633 48 40   667 52 44   667 52 44   671 55 46
         6115  +  683 56 47   705 57 48   711 58 49   759 62 53   777 66 56   805 71 61
         6116  +  839 73 63   839 73 63   845 77 66   899 81 68   911 82 69   929 83 70
         6117  +  959 87 73   963 88 74   979 89 75}
         6118  +
         6119  +do_execsql_test 5.4.14.1 {
         6120  +  SELECT max(c) OVER win,
         6121  +             min(c) OVER win,
         6122  +             count(a) OVER win
         6123  +      FROM t3
         6124  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
         6125  +        ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
         6126  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
         6127  +} {979 102 83   979 102 83   979 102 83   979 102 83   979 102 83   979 102 83
         6128  +  979 102 83   979 113 81   979 113 82   979 133 80   979 148 79   979 158 77
         6129  +  979 158 78   979 160 77   979 208 76   979 223 75   979 224 74   979 234 73
         6130  +  979 238 72   979 239 71   979 247 70   979 250 69   979 252 68   979 256 67
         6131  +  979 257 66   979 295 65   979 309 64   979 330 63   979 335 62   979 336 61
         6132  +  979 346 60   979 354 59   979 355 57   979 355 58   979 393 56   979 393 57
         6133  +  979 398 55   979 399 53   979 399 54   979 412 53   979 421 52   979 430 51
         6134  +  979 443 50   979 480 48   979 480 49   979 572 47   979 574 46   979 607 45
         6135  +  979 618 43   979 618 44   979 627 42   979 629 40   979 629 41   979 633 40
         6136  +  979 634 39   979 652 38   979 660 37   979 667 35   979 667 36   979 670 35
         6137  +  979 671 34   979 683 33   979 705 32   979 711 31   979 716 30   979 726 29
         6138  +  979 730 28   979 759 27   979 762 26   979 768 24   979 768 25   979 777 23
         6139  +  979 786 22   979 790 21   979 792 20   979 794 19   979 805 18   979 822 17
         6140  +  979 839 15   979 839 16   979 840 14   979 844 13   979 845 12   979 870 9
         6141  +  979 870 10   979 870 11   979 899 9   979 911 8   979 929 7}
         6142  +
         6143  +do_execsql_test 5.4.14.2 {
         6144  +  SELECT sum(c) FILTER (WHERE (c%2)!=0) OVER win,
         6145  +             rank() OVER win,
         6146  +             dense_rank() OVER win
         6147  +      FROM t3
         6148  +      WINDOW win AS (  ORDER BY c NULLS LAST, b NULLS LAST, a NULLS LAST
  4831   6149           ROWS BETWEEN 6 PRECEDING AND UNBOUNDED FOLLOWING   EXCLUDE TIES  )
  4832         -      ORDER BY 1 , 2 , 3
         6150  +      ORDER BY 1 NULLS FIRST, 2 NULLS FIRST, 3 NULLS FIRST
  4833   6151   } {3830 89 89   4741 88 88   5640 84 84   5640 85 85   5640 86 86   5640 87 87
  4834   6152     6485 81 81   6485 82 82   6485 83 83   7324 80 80   8163 78 78   8163 79 79
  4835   6153     8968 73 73   8968 74 74   8968 75 75   8968 76 76   8968 77 77   9745 69 69
  4836   6154     9745 70 70   9745 71 71   9745 72 72   10504 65 65   10504 66 66
  4837   6155     10504 67 67   10504 68 68   11215 64 64   11920 63 63   12603 62 62
  4838   6156     13274 60 60   13274 61 61   13941 59 59   14608 55 55   14608 56 56
  4839   6157     14608 57 57   14608 58 58   15241 54 54   15870 53 53   16499 52 52
................................................................................
  4856   6174     INSERT INTO t2 VALUES('A', NULL);
  4857   6175     INSERT INTO t2 VALUES('B', NULL);
  4858   6176     INSERT INTO t2 VALUES('C', 1);
  4859   6177   } {}
  4860   6178   
  4861   6179   do_execsql_test 6.1 {
  4862   6180     SELECT group_concat(a, '.') OVER (
  4863         -    ORDER BY b  RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
         6181  +    ORDER BY b NULLS FIRST RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  4864   6182     )
  4865   6183     FROM t2
  4866   6184   } {A.B   A.B   {}}
  4867   6185   
  4868   6186   do_execsql_test 6.2 {
  4869   6187     SELECT group_concat(a, '.') OVER (
  4870         -    ORDER BY b DESC  RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
         6188  +    ORDER BY b DESC NULLS LAST RANGE BETWEEN 7 PRECEDING AND 2 PRECEDING
  4871   6189     )
  4872   6190     FROM t2
  4873   6191   } {{}   A.B   A.B}
  4874   6192   
  4875   6193   finish_test

Changes to tool/mkkeywordhash.c.

   206    206     { "EXCEPT",           "TK_EXCEPT",       COMPOUND               },
   207    207     { "EXCLUSIVE",        "TK_EXCLUSIVE",    ALWAYS                 },
   208    208     { "EXCLUDE",          "TK_EXCLUDE",      WINDOWFUNC             },
   209    209     { "EXISTS",           "TK_EXISTS",       ALWAYS                 },
   210    210     { "EXPLAIN",          "TK_EXPLAIN",      EXPLAIN                },
   211    211     { "FAIL",             "TK_FAIL",         CONFLICT|TRIGGER       },
   212    212     { "FILTER",           "TK_FILTER",       WINDOWFUNC             },
          213  +  { "FIRST",            "TK_FIRST",        ALWAYS                 },
   213    214     { "FOLLOWING",        "TK_FOLLOWING",    WINDOWFUNC             },
   214    215     { "FOR",              "TK_FOR",          TRIGGER                },
   215    216     { "FOREIGN",          "TK_FOREIGN",      FKEY                   },
   216    217     { "FROM",             "TK_FROM",         ALWAYS                 },
   217    218     { "FULL",             "TK_JOIN_KW",      ALWAYS                 },
   218    219     { "GLOB",             "TK_LIKE_KW",      ALWAYS                 },
   219    220     { "GROUP",            "TK_GROUP",        ALWAYS                 },
................................................................................
   231    232     { "INSTEAD",          "TK_INSTEAD",      TRIGGER                },
   232    233     { "INTERSECT",        "TK_INTERSECT",    COMPOUND               },
   233    234     { "INTO",             "TK_INTO",         ALWAYS                 },
   234    235     { "IS",               "TK_IS",           ALWAYS                 },
   235    236     { "ISNULL",           "TK_ISNULL",       ALWAYS                 },
   236    237     { "JOIN",             "TK_JOIN",         ALWAYS                 },
   237    238     { "KEY",              "TK_KEY",          ALWAYS                 },
          239  +  { "LAST",             "TK_LAST",         ALWAYS                 },
   238    240     { "LEFT",             "TK_JOIN_KW",      ALWAYS                 },
   239    241     { "LIKE",             "TK_LIKE_KW",      ALWAYS                 },
   240    242     { "LIMIT",            "TK_LIMIT",        ALWAYS                 },
   241    243     { "MATCH",            "TK_MATCH",        ALWAYS                 },
   242    244     { "NATURAL",          "TK_JOIN_KW",      ALWAYS                 },
   243    245     { "NO",               "TK_NO",           FKEY|WINDOWFUNC        },
   244    246     { "NOT",              "TK_NOT",          ALWAYS                 },
   245    247     { "NOTHING",          "TK_NOTHING",      UPSERT                 },
   246    248     { "NOTNULL",          "TK_NOTNULL",      ALWAYS                 },
   247    249     { "NULL",             "TK_NULL",         ALWAYS                 },
          250  +  { "NULLS",            "TK_NULLS",        ALWAYS                 },
   248    251     { "OF",               "TK_OF",           ALWAYS                 },
   249    252     { "OFFSET",           "TK_OFFSET",       ALWAYS                 },
   250    253     { "ON",               "TK_ON",           ALWAYS                 },
   251    254     { "OR",               "TK_OR",           ALWAYS                 },
   252    255     { "ORDER",            "TK_ORDER",        ALWAYS                 },
   253    256     { "OTHERS",           "TK_OTHERS",       WINDOWFUNC             },
   254    257     { "OUTER",            "TK_JOIN_KW",      ALWAYS                 },