From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org> Subject: [tarantool-patches] [PATCH] sql: make DROP TABLE delete entry from _sequence_data Date: Mon, 15 Oct 2018 21:36:15 +0300 [thread overview] Message-ID: <20181015183615.28548-1-korablev@tarantool.org> (raw) Before this patch, _sequence_data system space wasn't taken into consideration when space was dropped. However, entries in this space may appear after recovery. For example: CREATE TABLE t (id INT PRIMARY KEY AUTOINCREMENT); INSERT INTO t VALUES (NULL); box.snapshot() os.exit() ... box.cfg{} DROP TABLE t; Last DROP statement didn't generate VDBE code to delete entry from _sequence_data, but it had to do so. This patch simply modifies code generation to remove entry from _sequence_data space before space is dropped. Closes #3712 --- Branch: https://github.com/tarantool/tarantool/tree/np/gh-3712-sql-sequence-recovery Issue: https://github.com/tarantool/tarantool/issues/3712 src/box/sql/build.c | 19 +++++++++++++------ test/sql/drop-table.result | 17 +++++++++++++++++ test/sql/drop-table.test.lua | 9 +++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index a806fb4b3..2704781bd 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1767,9 +1767,10 @@ sql_code_drop_table(struct Parse *parse_context, struct space *space, trigger = trigger->next; } /* - * Remove any entries of the _sequence and _space_sequence - * space associated with the table being dropped. This is - * done before the table is dropped from internal schema. + * Remove any entries from the _sequence_data, _sequence + * and _space_sequence spaces associated with the table + * being dropped. This is done before the table is dropped + * from internal schema. */ int idx_rec_reg = ++parse_context->nMem; int space_id_reg = ++parse_context->nMem; @@ -1777,6 +1778,15 @@ sql_code_drop_table(struct Parse *parse_context, struct space *space, sqlite3VdbeAddOp2(v, OP_Integer, space_id, space_id_reg); sqlite3VdbeAddOp1(v, OP_CheckViewReferences, space_id_reg); if (space->sequence != NULL) { + /* Delete entry from _sequence_data. */ + int sequence_id_reg = ++parse_context->nMem; + sqlite3VdbeAddOp2(v, OP_Integer, space->sequence->def->id, + sequence_id_reg); + sqlite3VdbeAddOp3(v, OP_MakeRecord, sequence_id_reg, 1, + idx_rec_reg); + sqlite3VdbeAddOp2(v, OP_SDelete, BOX_SEQUENCE_DATA_ID, + idx_rec_reg); + VdbeComment((v, "Delete entry from _sequence_data")); /* Delete entry from _space_sequence. */ sqlite3VdbeAddOp3(v, OP_MakeRecord, space_id_reg, 1, idx_rec_reg); @@ -1784,9 +1794,6 @@ sql_code_drop_table(struct Parse *parse_context, struct space *space, idx_rec_reg); VdbeComment((v, "Delete entry from _space_sequence")); /* Delete entry by id from _sequence. */ - int sequence_id_reg = ++parse_context->nMem; - sqlite3VdbeAddOp2(v, OP_Integer, space->sequence->def->id, - sequence_id_reg); sqlite3VdbeAddOp3(v, OP_MakeRecord, sequence_id_reg, 1, idx_rec_reg); sqlite3VdbeAddOp2(v, OP_SDelete, BOX_SEQUENCE_ID, idx_rec_reg); diff --git a/test/sql/drop-table.result b/test/sql/drop-table.result index 08f249668..bf02e3def 100644 --- a/test/sql/drop-table.result +++ b/test/sql/drop-table.result @@ -29,6 +29,23 @@ box.sql.execute("INSERT INTO zzzoobar VALUES (111, 222, 'c3', 444)") --- - error: 'no such table: ZZZOOBAR' ... +-- gh-3712: if space features sequence, data from _sequence_data +-- must be deleted before space is dropped. +-- +box.sql.execute("CREATE TABLE t1 (id INT PRIMARY KEY AUTOINCREMENT);") +--- +... +box.sql.execute("INSERT INTO t1 VALUES (NULL);") +--- +... +box.snapshot() +--- +- ok +... +test_run:cmd('restart server default') +box.sql.execute("DROP TABLE t1;") +--- +... -- Cleanup -- DROP TABLE should do the job -- Debug diff --git a/test/sql/drop-table.test.lua b/test/sql/drop-table.test.lua index 9663074df..2c0e3dc81 100644 --- a/test/sql/drop-table.test.lua +++ b/test/sql/drop-table.test.lua @@ -20,6 +20,15 @@ box.sql.execute("DROP TABLE zzzoobar") -- Table does not exist anymore. Should error here. box.sql.execute("INSERT INTO zzzoobar VALUES (111, 222, 'c3', 444)") +-- gh-3712: if space features sequence, data from _sequence_data +-- must be deleted before space is dropped. +-- +box.sql.execute("CREATE TABLE t1 (id INT PRIMARY KEY AUTOINCREMENT);") +box.sql.execute("INSERT INTO t1 VALUES (NULL);") +box.snapshot() +test_run:cmd('restart server default') +box.sql.execute("DROP TABLE t1;") + -- Cleanup -- DROP TABLE should do the job -- 2.15.1
next reply other threads:[~2018-10-15 18:36 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-10-15 18:36 Nikita Pettik [this message] 2018-10-15 18:54 ` [tarantool-patches] " Vladislav Shpilevoy 2018-10-15 19:04 ` n.pettik 2018-10-15 19:42 ` Vladislav Shpilevoy 2018-11-01 14:55 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20181015183615.28548-1-korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH] sql: make DROP TABLE delete entry from _sequence_data' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox