diff options
author | dan <dan@noemail.net> | 2018-06-08 16:11:55 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2018-06-08 16:11:55 +0000 |
commit | dacf1de95c75ffdaf01537a21666a270e29a670c (patch) | |
tree | d306c967bbb97d13af0f864519866055d875e66b /src/select.c | |
parent | 03854d2eccd79a5538da1ead29ed52dca85d5332 (diff) | |
download | sqlite-dacf1de95c75ffdaf01537a21666a270e29a670c.tar.gz sqlite-dacf1de95c75ffdaf01537a21666a270e29a670c.zip |
Do not flatten sub-queries that contain window functions.
FossilOrigin-Name: 236cb75bd1f0d5eb86aa5f52d8d548e7263c34633833dcea9dfc934f142113b8
Diffstat (limited to 'src/select.c')
-rw-r--r-- | src/select.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/select.c b/src/select.c index 5e99c949a..fcafe742d 100644 --- a/src/select.c +++ b/src/select.c @@ -3712,7 +3712,7 @@ static int flattenSubquery( pSub = pSubitem->pSelect; assert( pSub!=0 ); - if( p->pWin ) return 0; + if( p->pWin || pSub->pWin ) return 0; pSubSrc = pSub->pSrc; assert( pSubSrc ); @@ -5898,26 +5898,18 @@ int sqlite3Select( assert( p->pEList==pEList ); if( pWin ){ int addrGosub = sqlite3VdbeMakeLabel(v); + int iCont = sqlite3VdbeMakeLabel(v); int regGosub = ++pParse->nMem; int addr = 0; - int bLoop = 0; - sqlite3WindowCodeStep(pParse, p, pWInfo, regGosub, addrGosub, &bLoop); + sqlite3WindowCodeStep(pParse, p, pWInfo, regGosub, addrGosub); - sqlite3VdbeAddOp0(v, OP_Goto); + addr = sqlite3VdbeAddOp0(v, OP_Goto); sqlite3VdbeResolveLabel(v, addrGosub); - if( bLoop ){ - addr = sqlite3VdbeAddOp1(v, OP_Rewind, pWin->iEphCsr); - }else{ - addr = sqlite3VdbeCurrentAddr(v); - } - selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest, addr+1, 0); - if( bLoop ){ - sqlite3VdbeAddOp2(v, OP_Next, pWin->iEphCsr, addr+1); - sqlite3VdbeJumpHere(v, addr); - } + selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest, iCont, 0); + sqlite3VdbeResolveLabel(v, iCont); sqlite3VdbeAddOp1(v, OP_Return, regGosub); - sqlite3VdbeJumpHere(v, addr-1); /* OP_Goto jumps here */ + sqlite3VdbeJumpHere(v, addr); }else{ /* Use the standard inner loop. */ |