/ Check-in [489a1eb3aa]
Login

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

Overview
Comment:Simplifications to the window-function code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 489a1eb3aa2f1225b97b50a5f8688cf1a4ab0371973da1badc29616d70386c03
User & Date: drh 2019-09-25 02:07:50
Context
2019-09-25
10:36
In the unix VFS layer, do not attempt to chown() the journal to be the same as the database if running in 8+3 filename mode. Also, update the comments on the chown() attempt to be more precise. check-in: ab853724a7 user: drh tags: trunk
02:07
Simplifications to the window-function code. check-in: 489a1eb3aa user: drh tags: trunk
2019-09-24
20:20
Bug fixes for window frames of the form (... RANGE BETWEEN b PRECEDING AND a PRECEDING) or (... RANGE a FOLLOWING AND b FOLLOWING) where (a > b). check-in: 040e196a8b user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/window.c.

1545
1546
1547
1548
1549
1550
1551




1552
1553
1554
1555
1556
1557
1558
....
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
    FuncDef *pFunc = pWin->pFunc;
    int regArg;
    int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
    int i;

    assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );





    for(i=0; i<nArg; i++){
      if( i!=1 || pFunc->zName!=nth_valueName ){
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
      }else{
        sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
      }
    }
................................................................................
      **
      **    (peer IS NOT NULL AND peer < '')
      */
      if( pWin->eFrmType==TK_RANGE 
       && pWin->eStart==pWin->eEnd 
       && pWin->eStart==TK_PRECEDING
      ){
        int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
        int regPeer = sqlite3GetTempReg(pParse);
        int regString = sqlite3GetTempReg(pParse);
        int lbl = sqlite3VdbeMakeLabel(pParse);
        VdbeModuleComment((v, "windowAggStep \"peer is numeric?\" test"));
        sqlite3VdbeAddOp3(v, op, p->regStart, lbl, p->regEnd);
        VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because <expr> */
        VdbeCoverageNeverNullIf(v, op==OP_Le); /*   values previously checked */
        windowReadPeerValues(p, csr, regPeer);
        sqlite3VdbeAddOp2(v, OP_IsNull, regPeer, lbl);
        sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
        addrIf2 = sqlite3VdbeAddOp3(v, OP_Lt, regString, 0, regPeer);
        sqlite3ReleaseTempReg(pParse, regPeer);
        sqlite3ReleaseTempReg(pParse, regString);
        sqlite3VdbeResolveLabel(v, lbl);







>
>
>
>







 







<




|
|
|







1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
....
1608
1609
1610
1611
1612
1613
1614

1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
    FuncDef *pFunc = pWin->pFunc;
    int regArg;
    int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
    int i;

    assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );

    /* All OVER clauses in the same window function aggregate step must
    ** be the same. */
    assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)==0 );

    for(i=0; i<nArg; i++){
      if( i!=1 || pFunc->zName!=nth_valueName ){
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
      }else{
        sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
      }
    }
................................................................................
      **
      **    (peer IS NOT NULL AND peer < '')
      */
      if( pWin->eFrmType==TK_RANGE 
       && pWin->eStart==pWin->eEnd 
       && pWin->eStart==TK_PRECEDING
      ){

        int regPeer = sqlite3GetTempReg(pParse);
        int regString = sqlite3GetTempReg(pParse);
        int lbl = sqlite3VdbeMakeLabel(pParse);
        VdbeModuleComment((v, "windowAggStep \"peer is numeric?\" test"));
        assert( pMWin->eStart==TK_PRECEDING ); /* because pWin same as pMWin */
        sqlite3VdbeAddOp3(v, OP_Le, p->regStart, lbl, p->regEnd);
        VdbeCoverageNeverNull(v); /* because <expr> values previously checked */
        windowReadPeerValues(p, csr, regPeer);
        sqlite3VdbeAddOp2(v, OP_IsNull, regPeer, lbl);
        sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
        addrIf2 = sqlite3VdbeAddOp3(v, OP_Lt, regString, 0, regPeer);
        sqlite3ReleaseTempReg(pParse, regPeer);
        sqlite3ReleaseTempReg(pParse, regString);
        sqlite3VdbeResolveLabel(v, lbl);