mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Refactor the SrcItem object so that information about subqueries is stored
in a separately allocated Subquery object. This reduces the memory requirements for SrcItem and makes the code run faster. It also provides an expansion path for subquery processing that does not burden simple queries. The current checking mostly works, but there are still issues that need to be tracked down and fixed. FossilOrigin-Name: 8ff5dda8448d7e1a533d7f27db2573ce68fa9956b9d9847ced45e83c1f06bab0
This commit is contained in:
18
src/window.c
18
src/window.c
@@ -1077,9 +1077,10 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){
|
||||
assert( pSub!=0 || p->pSrc==0 ); /* Due to db->mallocFailed test inside
|
||||
** of sqlite3DbMallocRawNN() called from
|
||||
** sqlite3SrcListAppend() */
|
||||
if( p->pSrc ){
|
||||
if( p->pSrc==0 ){
|
||||
sqlite3SelectDelete(db, pSub);
|
||||
}else if( sqlite3SrcItemAttachSubquery(pParse, &p->pSrc->a[0], pSub, 0) ){
|
||||
Table *pTab2;
|
||||
p->pSrc->a[0].sq.pSelect = pSub;
|
||||
p->pSrc->a[0].fg.isCorrelated = 1;
|
||||
sqlite3SrcListAssignCursors(pParse, p->pSrc);
|
||||
pSub->selFlags |= SF_Expanded|SF_OrderByReqd;
|
||||
@@ -1101,8 +1102,6 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){
|
||||
w.xSelectCallback2 = sqlite3WalkerDepthDecrease;
|
||||
sqlite3WalkSelect(&w, pSub);
|
||||
}
|
||||
}else{
|
||||
sqlite3SelectDelete(db, pSub);
|
||||
}
|
||||
if( db->mallocFailed ) rc = SQLITE_NOMEM;
|
||||
|
||||
@@ -1389,10 +1388,15 @@ int sqlite3WindowCompare(
|
||||
** and initialize registers and cursors used by sqlite3WindowCodeStep().
|
||||
*/
|
||||
void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){
|
||||
int nEphExpr = pSelect->pSrc->a[0].sq.pSelect->pEList->nExpr;
|
||||
Window *pMWin = pSelect->pWin;
|
||||
Window *pWin;
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
int nEphExpr;
|
||||
Window *pMWin;
|
||||
Vdbe *v;
|
||||
|
||||
assert( pSelect->pSrc->a[0].fg.isSubquery );
|
||||
nEphExpr = pSelect->pSrc->a[0].u4.pSubq->pSelect->pEList->nExpr;
|
||||
pMWin = pSelect->pWin;
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
|
||||
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, nEphExpr);
|
||||
sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
|
||||
|
Reference in New Issue
Block a user