sql: skip autoinc IDs generated inside SQL trigger
Currently, if an INSERT is executed inside SQL trigger and it results in generated autoincrement identifiers, ones will be displayed as a result of the statement. This is wrong, since we are not able to divide IDs obtained into those that belong to the table mentioned in the statement and those that do not belong to this table. This has been fixed by adding a new argument to OP_IdxInsert. In case the argument is not 0, recently generated identifier is retrieved and saved into the list, which is held in VDBE itself. Note that from now we don't save autoincremented value to VDBE right in sequence_next() - this operation is moved to OP_IdxInsert. So that, VDBE can be removed from struct txn. For example: box.execute('CREATE TABLE t1 (i INT PRIMARY KEY AUTOINCREMENT);') box.execute('CREATE TABLE t2 (i INT PRIMARY KEY AUTOINCREMENT);') box.execute('CREATE TRIGGER r AFTER INSERT ON t1 FOR EACH ROW '.. 'BEGIN INSERT INTO t2 VALUES (null); END') box.execute('INSERT INTO t2 VALUES (100);') box.execute('INSERT INTO t1 VALUES (NULL), (NULL), (NULL);') Result should be: --- - autoincrement_ids: - 1 - 2 - 3 row_count: 3 ... Closes #4188
Showing
- src/box/sequence.c 12 additions, 6 deletionssrc/box/sequence.c
- src/box/sequence.h 9 additions, 3 deletionssrc/box/sequence.h
- src/box/sql/insert.c 9 additions, 3 deletionssrc/box/sql/insert.c
- src/box/sql/sqlInt.h 5 additions, 1 deletionsrc/box/sql/sqlInt.h
- src/box/sql/update.c 1 addition, 1 deletionsrc/box/sql/update.c
- src/box/sql/vdbe.c 13 additions, 2 deletionssrc/box/sql/vdbe.c
- test/sql/iproto.result 0 additions, 2 deletionstest/sql/iproto.result
- test/sql/triggers.result 114 additions, 0 deletionstest/sql/triggers.result
- test/sql/triggers.test.lua 24 additions, 0 deletionstest/sql/triggers.test.lua
Loading
Please register or sign in to comment