Skip to content

Commit

Permalink
sql: remove unnecessary AUTOINCREMENT ID generation
Browse files Browse the repository at this point in the history
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 tarantool#3691. After this patch all new identifiers will
be generated in BOX.

Part of tarantool#4188
  • Loading branch information
ImeevMA committed Jul 24, 2019
1 parent a438627 commit a03ec36
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
5 changes: 1 addition & 4 deletions src/box/sql/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 0 additions & 27 deletions src/box/sql/vdbe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,33 +1168,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);
mem_set_i64(pOut, value);

break;
}

/* Opcode: Null P1 P2 P3 * *
* Synopsis: r[P2..P3]=NULL
*
Expand Down

0 comments on commit a03ec36

Please sign in to comment.