From: AKhatskevich <avkhatskevich@tarantool.org> To: tarantool-patches@freelists.org Cc: AKhatskevich <avkhatskevich@tarantool.org> Subject: [tarantool-patches] [PATCH 3/3] sql: report errors in EphemeralGetMaxId Date: Thu, 29 Mar 2018 13:17:52 +0300 [thread overview] Message-ID: <a94ae0c1427445fa7a4b43be527565cb12d2071e.1522318267.git.avkhatskevich@tarantool.org> (raw) In-Reply-To: <cover.1522318267.git.avkhatskevich@tarantool.org> In-Reply-To: <cover.1522318267.git.avkhatskevich@tarantool.org> In case of error in `tarantoolSqlite3EphemeralGetMaxId` it was creating diag string and silently continue working. It was a huge luck that non-valid output of the function did not lead to crashes. After the fix, it was found that some opcodes in `select.c` were using wrong registers. These were fixed too, but they still have bugs. For more information see #3297. Related to #3297 --- src/box/sql.c | 3 ++- src/box/sql/select.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 98bcd93ca..31ceacb53 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -1744,7 +1744,8 @@ int tarantoolSqlite3EphemeralGetMaxId(BtCursor *pCur, uint32_t fieldno, *max_id = 0; return SQLITE_OK; } - tuple_field_u64(tuple, fieldno, max_id); + if (tuple_field_u64(tuple, fieldno, max_id) == -1) + return SQL_TARANTOOL_ERROR; return SQLITE_OK; } diff --git a/src/box/sql/select.c b/src/box/sql/select.c index a76286f23..c91685f7f 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -1025,7 +1025,7 @@ selectInnerLoop(Parse * pParse, /* The parser context */ /* Last column is required for ID. */ int regCopy = sqlite3GetTempRange(pParse, nResultCol + 1); sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, - 0, regCopy + nResultCol); + nResultCol, regCopy + nResultCol); /* Positioning ID column to be last in inserted tuple. * NextId -> regCopy + n + 1 * Copy [regResult, regResult + n] -> [regCopy, regCopy + n] @@ -1504,7 +1504,7 @@ generateSortTail(Parse * pParse, /* Parsing context */ case SRT_Table: case SRT_EphemTab: { int regCopy = sqlite3GetTempRange(pParse, nColumn); - sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, 0, regTupleid); + sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, nColumn, regTupleid); sqlite3VdbeAddOp3(v, OP_Copy, regRow, regCopy, nSortData - 1); sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, nColumn + 1, regRow); sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, regRow); @@ -2957,7 +2957,7 @@ generateOutputSubroutine(Parse * pParse, /* Parsing context */ int regRec = sqlite3GetTempReg(pParse); int regCopy = sqlite3GetTempRange(pParse, pIn->nSdst + 1); sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, pDest->iSDParm, - 0, regCopy + pIn->nSdst); + pIn->nSdst, regCopy + pIn->nSdst); sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regCopy, pIn->nSdst - 1); sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, -- 2.14.1
prev parent reply other threads:[~2018-03-29 10:18 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-03-29 10:17 [tarantool-patches] [PATCH 0/3] Ephemeral tables perf leak & next rowid bug AKhatskevich 2018-03-29 10:17 ` [tarantool-patches] [PATCH 1/3] sql: Generate rowid by counter AKhatskevich 2018-03-29 10:17 ` [tarantool-patches] [PATCH 2/3] sql: fix memory leak AKhatskevich 2018-03-29 10:17 ` AKhatskevich [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=a94ae0c1427445fa7a4b43be527565cb12d2071e.1522318267.git.avkhatskevich@tarantool.org \ --to=avkhatskevich@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 3/3] sql: report errors in EphemeralGetMaxId' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox