diff options
author | drh <> | 2021-02-04 23:20:13 +0000 |
---|---|---|
committer | drh <> | 2021-02-04 23:20:13 +0000 |
commit | 70bd2124ed8dba89ee3ad2ccb25c5686b1d0ead5 (patch) | |
tree | 3f27cf04afa15c2b4e1e001bc8c99b6b3d2c5e02 /src/sqliteInt.h | |
parent | 8ab79d6135b33523a5d7f5c988b080a63fb15db3 (diff) | |
parent | 7dec804d4210cf928820693735135f4307fef050 (diff) | |
download | sqlite-70bd2124ed8dba89ee3ad2ccb25c5686b1d0ead5.tar.gz sqlite-70bd2124ed8dba89ee3ad2ccb25c5686b1d0ead5.zip |
Change the RETURNING algorithm so that outputs accumulate in an ephemeral
table until all modifications have been completed, and only then do results
start being returned. This should help prevent problems with interleaved
sqlite3_step() calls on two separate DML statements. It also seems to be
closer to how PostgreSQL works, which might prevent compatibility problems.
FossilOrigin-Name: c4615eb28c3dd2d473daf104f32e60d02799f3158d9d275a899c39129cc71401
Diffstat (limited to 'src/sqliteInt.h')
-rw-r--r-- | src/sqliteInt.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3cadb7f53..7b22b6b3b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3037,6 +3037,7 @@ struct NameContext { ExprList *pEList; /* Optional list of result-set columns */ AggInfo *pAggInfo; /* Information about aggregates at this level */ Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */ + int iBaseReg; /* For TK_REGISTER when parsing RETURNING */ } uNC; NameContext *pNext; /* Next outer name context. NULL for outermost */ int nRef; /* Number of names resolved by this context */ @@ -3065,6 +3066,7 @@ struct NameContext { #define NC_UEList 0x00080 /* True if uNC.pEList is used */ #define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */ #define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */ +#define NC_UBaseReg 0x00400 /* True if uNC.iBaseReg is used */ #define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */ #define NC_Complex 0x02000 /* True if a function or subquery seen */ #define NC_AllowWin 0x04000 /* Window functions are allowed here */ @@ -3425,7 +3427,10 @@ struct Parse { Table *pTriggerTab; /* Table triggers are being coded for */ Parse *pParentParse; /* Parent parser if this parser is nested */ AggInfo *pAggList; /* List of all AggInfo objects */ - int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */ + union { + int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */ + Returning *pReturning; /* The RETURNING clause */ + } u1; u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ u32 oldmask; /* Mask of old.* columns referenced */ u32 newmask; /* Mask of new.* columns referenced */ @@ -3647,7 +3652,7 @@ struct TriggerStep { char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ SrcList *pFrom; /* FROM clause for UPDATE statement (if any) */ Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ - ExprList *pExprList; /* SET clause for UPDATE */ + ExprList *pExprList; /* SET clause for UPDATE, or RETURNING clause */ IdList *pIdList; /* Column names for INSERT */ Upsert *pUpsert; /* Upsert clauses on an INSERT */ char *zSpan; /* Original SQL text of this command */ @@ -3663,8 +3668,9 @@ struct Returning { ExprList *pReturnEL; /* List of expressions to return */ Trigger retTrig; /* The transient trigger that implements RETURNING */ TriggerStep retTStep; /* The trigger step */ - Select retSel; /* The SELECT statement that implements RETURNING */ - u64 retSrcList; /* The empty FROM clause of the SELECT */ + int iRetCur; /* Transient table holding RETURNING results */ + int nRetCol; /* Number of in pReturnEL after expansion */ + int iRetReg; /* Register array for holding a row of RETURNING */ }; /* |