From: AKhatskevich <avkhatskevich@tarantool.org> To: tarantool-patches@freelists.org Cc: AKhatskevich <avkhatskevich@tarantool.org> Subject: [tarantool-patches] [PATCH 1/3] sql: Generate rowid by counter Date: Thu, 29 Mar 2018 13:17:50 +0300 [thread overview] Message-ID: <25d8fcea03e7e9cfb9fea86c7fb0315f08e65e3a.1522318267.git.avkhatskevich@tarantool.org> (raw) In-Reply-To: <cover.1522318267.git.avkhatskevich@tarantool.org> In-Reply-To: <cover.1522318267.git.avkhatskevich@tarantool.org> The function `OP_NextIdEphemeral` do not produce unique ids. The new way to get rowid is to create sequential a counter. One of registers initializes with int64_t = 0 and increases after each insert. There are similar cases in `select.c` file, however, they are not as straight-forward and would be fixed in future commits. Related to #3297 --- src/box/sql/insert.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index 28c01092d..4f3cb3116 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -536,6 +536,7 @@ sqlite3Insert(Parse * pParse, /* Parser context */ int regTempId; /* Register to hold temp table ID */ int regCopy; /* Register to keep copy of registers from select */ int addrL; /* Label "L" */ + int64_t initial_pk = 0; srcTab = pParse->nTab++; regRec = sqlite3GetTempReg(pParse); @@ -544,9 +545,16 @@ sqlite3Insert(Parse * pParse, /* Parser context */ KeyInfo *pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, 1+nColumn, 0); sqlite3VdbeAddOp4(v, OP_OpenTEphemeral, srcTab, nColumn+1, 0, (char*)pKeyInfo, P4_KEYINFO); + /* Create counter for rowid */ + sqlite3VdbeAddOp4Dup8(v, OP_Int64, + 0 /* unused */, + regTempId, + 0 /* unused */, + (const unsigned char*) &initial_pk, + P4_INT64); addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v); - sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, srcTab, 2, regTempId); + sqlite3VdbeAddOp2(v, OP_AddImm, regTempId, 1); sqlite3VdbeAddOp3(v, OP_Copy, regFromSelect, regCopy, nColumn-1); sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, nColumn + 1, regRec); -- 2.14.1
next 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 ` AKhatskevich [this message] 2018-03-29 10:17 ` [tarantool-patches] [PATCH 2/3] sql: fix memory leak AKhatskevich 2018-03-29 10:17 ` [tarantool-patches] [PATCH 3/3] sql: report errors in EphemeralGetMaxId AKhatskevich
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=25d8fcea03e7e9cfb9fea86c7fb0315f08e65e3a.1522318267.git.avkhatskevich@tarantool.org \ --to=avkhatskevich@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 1/3] sql: Generate rowid by counter' \ /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