[tarantool-patches] [PATCH 1/3] sql: Generate rowid by counter
AKhatskevich
avkhatskevich at tarantool.org
Thu Mar 29 13:17:50 MSK 2018
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
More information about the Tarantool-patches
mailing list