From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org, Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [tarantool-patches] Re: [PATCH v2 09/11] sql: new _trigger space format with space_id Date: Wed, 13 Jun 2018 21:53:32 +0300 [thread overview] Message-ID: <36b21e2d-d459-d373-7c56-02537de5fdd9@tarantool.org> (raw) In-Reply-To: <d38823580f81c9b7faf4f078a5445c34c4d84bb6.1528535873.git.kshcherbatov@tarantool.org> Thanks for the patch! Almost ok. See 5 minor comments below. On 09/06/2018 12:32, Kirill Shcherbatov wrote: > As we would like to lookup triggers by space_id in future > on space deletion to delete assocoated _trigger tuples we 1. "assocoated" - typo. > need to introduce new field space_id as secondary key. > > Part of #3273. > --- > src/box/bootstrap.snap | Bin 1698 -> 1704 bytes > src/box/lua/upgrade.lua | 6 +++++- > src/box/sql.c | 18 +++++++++++------- > src/box/sql/sqliteInt.h | 2 ++ > src/box/sql/trigger.c | 8 +++++--- > test/sql/gh2141-delete-trigger-drop-table.result | 4 ++-- > test/sql/gh2141-delete-trigger-drop-table.test.lua | 4 ++-- > test/sql/persistency.result | 8 ++++---- > test/sql/persistency.test.lua | 8 ++++---- > 9 files changed, 35 insertions(+), 23 deletions(-) > > diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua > index 18bfaa9..e54b394 100644 > --- a/src/box/lua/upgrade.lua > +++ b/src/box/lua/upgrade.lua > @@ -477,12 +477,16 @@ local function upgrade_to_2_1_0() > > log.info("create space _trigger") > local format = {{name='name', type='string'}, > + {name='space_id', type='unsigned'}, > {name='opts', type='map'}} > _space:insert{_trigger.id, ADMIN, '_trigger', 'memtx', 0, MAP, format} > > log.info("create index primary on _trigger") > _index:insert{_trigger.id, 0, 'primary', 'tree', { unique = true }, > - {{0, 'string'}}} > + {{0, 'string'}} } 2. Unnecessary diff. Either do this: {data, data}, or this { data, data }. Not this: {data, data }. Same below. > + log.info("create index secondary on _trigger") > + _index:insert{_trigger.id, 1, 'space_id', 'tree', { unique = false }, > + {{1, 'unsigned'}} } > > local stat1_ft = {{name='tbl', type='string'}, > {name='idx', type='string'}, > diff --git a/src/box/sql.c b/src/box/sql.c > index 599cb60..0ba0346 100644 > --- a/src/box/sql.c > +++ b/src/box/sql.c > @@ -693,16 +696,17 @@ int tarantoolSqlite3RenameTrigger(const char *trig_name, > uint32_t trigger_stmt_new_len = trigger_stmt_len + new_table_name_len - > old_table_name_len + 2 * (!is_quoted); > assert(trigger_stmt_new_len > 0); > - key_len = mp_sizeof_array(2) + mp_sizeof_str(trig_name_len) + > + key_len = mp_sizeof_array(3) + mp_sizeof_str(trig_name_len) + > mp_sizeof_map(1) + mp_sizeof_str(3) + > - mp_sizeof_str(trigger_stmt_new_len); > + mp_sizeof_str(trigger_stmt_new_len) + mp_sizeof_uint(space_id); 3. Out of 80. > char *new_tuple = (char*)region_alloc(&fiber()->gc, key_len); > if (new_tuple == NULL) { > diag_set(OutOfMemory, key_len, "region_alloc", "new_tuple"); > return SQL_TARANTOOL_ERROR; > } > - char *new_tuple_end = mp_encode_array(new_tuple, 2); > + char *new_tuple_end = mp_encode_array(new_tuple, 3); > new_tuple_end = mp_encode_str(new_tuple_end, trig_name, trig_name_len); > + new_tuple_end = mp_encode_uint(new_tuple_end, space_id); > new_tuple_end = mp_encode_map(new_tuple_end, 1); > new_tuple_end = mp_encode_str(new_tuple_end, "sql", 3); > new_tuple_end = mp_encode_str(new_tuple_end, trigger_stmt, > diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h > index ecbd573..6ca59c4 100644 > --- a/src/box/sql/sqliteInt.h > +++ b/src/box/sql/sqliteInt.h > @@ -3032,6 +3032,8 @@ struct Parse { > */ > struct Trigger { > char *zName; /* The name of the trigger */ > + /** The ID of space the trigger is refer to. */ 4. 'is refer to' is incorrect construction. Maybe did you mean 'refers to'? > + uint32_t space_id; > char *table; /* The table or view to which the trigger applies */ > u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ > u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */ 5. How about to test space_id is stored in _trigger? I mean test box.space._trigger:select{} full result. Not two columns only.
next prev parent reply other threads:[~2018-06-13 18:53 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-09 9:58 [tarantool-patches] [PATCH v2 00/11] sql: remove Triggers to server Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 10/11] sql: move " Kirill Shcherbatov 2018-06-13 18:53 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-14 16:12 ` Kirill Shcherbatov 2018-06-28 7:18 ` Konstantin Osipov 2018-06-28 7:33 ` Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 11/11] sql: VDBE tests for trigger existence Kirill Shcherbatov 2018-06-13 18:53 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-14 16:12 ` Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 02/11] box: move db->pShchema init to sql_init Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 04/11] sql: fix sql len in tarantoolSqlite3RenameTrigger Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 06/11] sql: refactor sql_expr_compile to return AST Kirill Shcherbatov 2018-06-13 18:53 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-14 16:12 ` Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 07/11] sql: move sqlite3DeleteTrigger to sql.h Kirill Shcherbatov 2018-06-13 18:53 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-14 16:12 ` Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 08/11] box: sort error codes in misc.test Kirill Shcherbatov 2018-06-09 9:32 ` [tarantool-patches] [PATCH v2 09/11] sql: new _trigger space format with space_id Kirill Shcherbatov 2018-06-13 18:53 ` Vladislav Shpilevoy [this message] 2018-06-14 16:12 ` [tarantool-patches] " Kirill Shcherbatov 2018-06-09 9:58 ` [tarantool-patches] [PATCH v2 01/11] box: remove migration from alpha 1.8.2 and 1.8.4 Kirill Shcherbatov 2018-06-09 9:58 ` [tarantool-patches] [PATCH v2 03/11] sql: fix leak on CREATE TABLE and resolve self ref Kirill Shcherbatov 2018-06-13 18:53 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-14 16:12 ` Kirill Shcherbatov 2018-06-09 9:58 ` [tarantool-patches] [PATCH v2 05/11] box: port schema_find_id to C Kirill Shcherbatov 2018-06-13 18:53 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-14 16:12 ` Kirill Shcherbatov
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=36b21e2d-d459-d373-7c56-02537de5fdd9@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH v2 09/11] sql: new _trigger space format with space_id' \ /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