[tarantool-patches] [PATCH v4 1/4] sql: remove unnecessary AUTOINCREMENT ID generation

imeevma at tarantool.org imeevma at tarantool.org
Wed Jul 17 12:54:52 MSK 2019


Hi! Thank you for review. My answer and new version below.


On 7/15/19 8:50 PM, n.pettik wrote:
>
>>>> src/box/sql/insert.c                    |  5 +----
>>>> test/sql/gh-2981-check-autoinc.result   | 32 ++++++++++++++++++++++++++++++++
>>>> test/sql/gh-2981-check-autoinc.test.lua | 11 ++++++++++-
>>>> 3 files changed, 43 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
>>>> index b353148..d2b4e17 100644
>>>> --- a/src/box/sql/insert.c
>>>> +++ b/src/box/sql/insert.c
>>>> @@ -628,10 +628,7 @@ sqlInsert(Parse * pParse,	/* Parser context */
>>>> 			if (j < 0 || nColumn == 0
>>>> 			    || (pColumn && j >= pColumn->nId)) {
>>>> 				if (i == (int) autoinc_fieldno) {
>>>> -					sqlVdbeAddOp2(v,
>>>> -							  OP_NextAutoincValue,
>>>> -							  space->def->id,
>>>> -							  iRegStore);
>>>
>>> Why didn’t you delete OP_NextAutioncValue?
>>>
>> I changed it functionality in the next patch.
>
> You changes affect more than 50% of opcode's content.
> Please, to make patches well structured, remove opcode
> in current patch and resurrect in the next one.
>
Removed the opcode.


New patch:

>From a82a75782cc536af3e1001674759a1476af7dee7 Mon Sep 17 00:00:00 2001
From: Mergen Imeev <imeevma at gmail.com>
Date: Wed, 3 Jul 2019 14:05:11 +0300
Subject: [PATCH] sql: remove unnecessary AUTOINCREMENT ID generation

Currently, if we perform something like
CREATE TABLE t1 (
        s1 INTEGER PRIMARY KEY AUTOINCREMENT,
        s2 INTEGER,
        CHECK (s1 <> 19)
);
INSERT INTO t1 VALUES (18, NULL);
INSERT INTO t1 (s2) VALUES (NULL);

we generate a new identifier in VDBE, but in any other case we
generate it in BOX. That was needed since the CHECK did not work
properly. This is not necessary now, because CHECK was moved to
BOX due to issue #3691. After this patch all new identifiers will
be generated in BOX.

Part of #4188

diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index b353148..d2b4e17 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -628,10 +628,7 @@ sqlInsert(Parse * pParse,	/* Parser context */
 			if (j < 0 || nColumn == 0
 			    || (pColumn && j >= pColumn->nId)) {
 				if (i == (int) autoinc_fieldno) {
-					sqlVdbeAddOp2(v,
-							  OP_NextAutoincValue,
-							  space->def->id,
-							  iRegStore);
+					sqlVdbeAddOp2(v, OP_Null, 0, iRegStore);
 					continue;
 				}
 				struct Expr *dflt = NULL;
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 9f4ee7a..6bb7bc3 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1149,34 +1149,6 @@ case OP_String: {          /* out2 */
 	break;
 }
 
-/* Opcode: NextAutoincValue P1 P2 * * *
- * Synopsis: r[P2] = next value from space sequence, which pageno is r[P1]
- *
- * Get next value from space sequence, which pageno is written into register
- * P1, write this value into register P2. If space doesn't exists (invalid
- * space_id or something else), raise an error. If space with
- * specified space_id doesn't have attached sequence, also raise an error.
- */
-case OP_NextAutoincValue: {
-	assert(pOp->p1 > 0);
-	assert(pOp->p2 > 0);
-
-	struct space *space = space_by_id(pOp->p1);
-	if (space == NULL)
-		goto abort_due_to_error;
-
-	int64_t value;
-	struct sequence *sequence = space->sequence;
-	if (sequence == NULL || sequence_next(sequence, &value) != 0)
-		goto abort_due_to_error;
-
-	pOut = out2Prerelease(p, pOp);
-	pOut->flags = MEM_Int;
-	pOut->u.i = value;
-
-	break;
-}
-
 /* Opcode: Null P1 P2 P3 * *
  * Synopsis: r[P2..P3]=NULL
  *




More information about the Tarantool-patches mailing list