[tarantool-patches] Re: [PATCH v3 2/4] sql: do not show IDs generated by trigger

n.pettik korablev at tarantool.org
Mon Jul 15 20:50:42 MSK 2019


I’ve edited commit message:

    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 opcode OP_SaveAutoincValue, which follows each
    OP_IdxInsert when there's autoincrement field. On the other hand, we can
    avoid adding this opcode while producing VDBE instructions for triggers.
    OP_SaveAutoincValue retrieves and saves recently generated identifiers
    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_SaveAutoincValue. 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
    
    Closes #4188



More information about the Tarantool-patches mailing list