/ Check-in [ac251f72]
Login

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

Overview
Comment:Add extra OOM test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | exp-window-functions
Files: files | file ages | folders
SHA3-256: ac251f72608c27c1512a0b3457524f5378a0b13d93d829cf0ed8bc178bc54a73
User & Date: dan 2018-06-15 20:46:12
Context
2018-06-18
16:55
Add new API function sqlite3_create_window_function(), for creating new aggregate window functions. check-in: da03fb43 user: dan tags: exp-window-functions
2018-06-15
20:46
Add extra OOM test. check-in: ac251f72 user: dan tags: exp-window-functions
19:01
Fix another problem in lead()/lag(). And some errors that could occur following OOM faults. check-in: fadd4dc1 user: dan tags: exp-window-functions
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/window.c.

   623    623   **     linked list passed as the second argument (pWin)
   624    624   **
   625    625   ** Append the node to output expression-list (*ppSub). And replace it
   626    626   ** with a TK_COLUMN that reads the (N-1)th element of table 
   627    627   ** pWin->iEphCsr, where N is the number of elements in (*ppSub) after
   628    628   ** appending the new one.
   629    629   */
   630         -static int selectWindowRewriteEList(
          630  +static void selectWindowRewriteEList(
   631    631     Parse *pParse, 
   632    632     Window *pWin,
   633    633     ExprList *pEList,               /* Rewrite expressions in this list */
   634    634     ExprList **ppSub                /* IN/OUT: Sub-select expression-list */
   635    635   ){
   636    636     Walker sWalker;
   637    637     WindowRewrite sRewrite;
   638         -  int rc;
   639    638   
   640    639     memset(&sWalker, 0, sizeof(Walker));
   641    640     memset(&sRewrite, 0, sizeof(WindowRewrite));
   642    641   
   643    642     sRewrite.pSub = *ppSub;
   644    643     sRewrite.pWin = pWin;
   645    644   
   646    645     sWalker.pParse = pParse;
   647    646     sWalker.xExprCallback = selectWindowRewriteExprCb;
   648    647     sWalker.xSelectCallback = selectWindowRewriteSelectCb;
   649    648     sWalker.u.pRewrite = &sRewrite;
   650    649   
   651         -  rc = sqlite3WalkExprList(&sWalker, pEList);
          650  +  (void)sqlite3WalkExprList(&sWalker, pEList);
   652    651   
   653    652     *ppSub = sRewrite.pSub;
   654         -  return rc;
   655    653   }
   656    654   
   657    655   /*
   658    656   ** Append a copy of each expression in expression-list pAppend to
   659    657   ** expression list pList. Return a pointer to the result list.
   660    658   */
   661    659   static ExprList *exprListAppendList(
................................................................................
   705    703       p->pHaving = 0;
   706    704   
   707    705       /* Assign a cursor number for the ephemeral table used to buffer rows.
   708    706       ** The OpenEphemeral instruction is coded later, after it is known how
   709    707       ** many columns the table will have.  */
   710    708       pMWin->iEphCsr = pParse->nTab++;
   711    709   
   712         -    rc = selectWindowRewriteEList(pParse, pMWin, p->pEList, &pSublist);
   713         -    if( rc ) return rc;
   714         -    rc = selectWindowRewriteEList(pParse, pMWin, p->pOrderBy, &pSublist);
   715         -    if( rc ) return rc;
          710  +    selectWindowRewriteEList(pParse, pMWin, p->pEList, &pSublist);
          711  +    selectWindowRewriteEList(pParse, pMWin, p->pOrderBy, &pSublist);
   716    712       pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
   717    713   
   718    714       /* Create the ORDER BY clause for the sub-select. This is the concatenation
   719    715       ** of the window PARTITION and ORDER BY clauses. Append the same 
   720    716       ** expressions to the sub-select expression list. They are required to
   721    717       ** figure out where boundaries for partitions and sets of peer rows.  */
   722    718       pSort = sqlite3ExprListDup(db, pMWin->pPartition, 0);

Changes to test/window1.test.

   260    260       lead(y, 2) OVER win, 
   261    261       lead(y, 3, 'default') OVER win
   262    262     FROM t1
   263    263     WINDOW win AS (ORDER BY x)
   264    264   } {
   265    265     4 6 8   6 8 10   8 10 default   10 {} default   {} {} default
   266    266   }
          267  +
          268  +do_execsql_test 7.3 {
          269  +  SELECT row_number() OVER (ORDER BY x) FROM t1
          270  +} {1 2 3 4 5}
   267    271   
   268    272   
   269    273   finish_test
   270    274   

Changes to test/windowfault.test.

    41     41              min(d) OVER win
    42     42       FROM t1
    43     43       WINDOW win AS (ORDER BY a)
    44     44     }
    45     45   } -test {
    46     46     faultsim_test_result {0 {1 1 1 1 4 4 {} 8 {} 4 4 2 2 2 1 4 8 8 12 4 8 4 3 3 3 2 4 12 8 {} 8 12 4}}
    47     47   }
           48  +
           49  +do_faultsim_test 2 -faults oom-* -prep {
           50  +  faultsim_restore_and_reopen
           51  +} -body {
           52  +  execsql {
           53  +    SELECT min(d) OVER win, max(d) OVER win
           54  +    FROM t1
           55  +    WINDOW win AS (ORDER BY a RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)
           56  +  }
           57  +} -test {
           58  +  faultsim_test_result {0 {4 12 8 12 12 12}}
           59  +}
    48     60   
    49     61   
    50     62   finish_test
    51     63