From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id B252D2A1FF for ; Thu, 29 Mar 2018 06:18:31 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ymr1KXrStpQD for ; Thu, 29 Mar 2018 06:18:31 -0400 (EDT) Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 6DC4B207A6 for ; Thu, 29 Mar 2018 06:18:31 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH 1/3] sql: Generate rowid by counter Date: Thu, 29 Mar 2018 13:17:50 +0300 Message-Id: <25d8fcea03e7e9cfb9fea86c7fb0315f08e65e3a.1522318267.git.avkhatskevich@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: AKhatskevich 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