sql: transactional DDL
Box recently added support of transactional DDL allowing to do any number of non-yielding DDL operations atomically. This is really a big relief of one of the biggest pains of SQL. Before this patch each multirow SQL DDL statement needed to prepare its own rollback procedure for a case if something would go wrong. Now with box support SQL wraps each DDL statement into a transaction, and doesn't need own escape-routes in a form of 'struct save_record' and others. Closes #4086 @TarantoolBot document Title: SQL DDL is transactional SQL DDL operations are atomic now. For example, if a CREATE TABLE request fails somewhere in the middle, it won't leave any garbage. Like a space without indexes, or unused sequences. Even if the instance is powered off during the request. Also, SQL DDL can be manually included into transactions, with certain limitations - such a transaction can't yield. For example, this is legal: START TRANSACTION; CREATE TABLE test(a INTEGER PRIMARY KEY, b INTEGER); CREATE INDEX test_a ON test(a); COMMIT; If you want to test it in the console, then wrap it into a function to do not get a rollback by yield, because the console yields after each command: function create() box.execute('START TRANSACTION;') box.execute('CREATE TABLE test(a INTEGER PRIMARY KEY, b INTEGER);') box.execute('CREATE INDEX test_a ON test(a);') box.execute('COMMIT;') end create() But the following example is illegal and you will get an error: box.execute('CREATE TABLE test(a INTEGER PRIMARY KEY, b INTEGER, c INTEGER);') box.execute('INSERT INTO test VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);') function index() box.execute('START TRANSACTION;') box.execute('CREATE INDEX test_b ON test(b);') box.execute('CREATE INDEX test_c ON test(c);') box.execute('COMMIT;') end tarantool> index() --- - error: Can not perform index build in a multi-statement transaction ... The error is because an attempt to build an index on a non-empty space leads to immediate yield.
Showing
- src/box/sql/build.c 20 additions, 139 deletionssrc/box/sql/build.c
- src/box/sql/parse.y 12 additions, 1 deletionsrc/box/sql/parse.y
- src/box/sql/prepare.c 0 additions, 1 deletionsrc/box/sql/prepare.c
- src/box/sql/sqlInt.h 1 addition, 6 deletionssrc/box/sql/sqlInt.h
- src/box/sql/trigger.c 2 additions, 4 deletionssrc/box/sql/trigger.c
- src/box/sql/vdbe.c 8 additions, 7 deletionssrc/box/sql/vdbe.c
- test/sql/ddl.result 595 additions, 0 deletionstest/sql/ddl.result
- test/sql/ddl.test.lua 329 additions, 0 deletionstest/sql/ddl.test.lua
- test/sql/errinj.result 0 additions, 50 deletionstest/sql/errinj.result
- test/sql/errinj.test.lua 0 additions, 22 deletionstest/sql/errinj.test.lua
- test/sql/view_delayed_wal.result 6 additions, 6 deletionstest/sql/view_delayed_wal.result
- test/sql/view_delayed_wal.test.lua 4 additions, 4 deletionstest/sql/view_delayed_wal.test.lua
Loading
Please register or sign in to comment