From: "n.pettik" <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, Konstantin Osipov <kostja@tarantool.org> Subject: [tarantool-patches] Re: [PATCH v2 3/4] sql: fix error message for improperly created index Date: Fri, 29 Mar 2019 21:16:01 +0300 [thread overview] Message-ID: <EF378E7D-7662-4BAA-8BA3-8B6140791C6D@tarantool.org> (raw) In-Reply-To: <e5df7cba-1031-9d50-bf78-5d481b63642d@tarantool.org> > On 28 Mar 2019, at 18:11, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote: > > Thanks for the patch! See my review fix at the bottom > of the email, and on the branch. In my fixes I've accounted > Kostja's comment about a proper error code. I guess Kostja meant to remove this check and use means of on_replace_dd_index() trigger. In other words, generate creation of secondary index without HALT and index id == 1 to delegate verification of index correctness to on replace trigger. Here’s what I did: (I put this version on separate branch: https://github.com/tarantool/tarantool/tree/np/gh-3914-fix-create-index-v3) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 78cd3cee6..ef19ac926 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1924,9 +1924,14 @@ sql_drop_foreign_key(struct Parse *parse_context) * following: * * 1 Seek for space id in _index, goto l1 if seeks fails. - * 2 Goto l2. - * 3 l1: Halt. - * 4 l2: Fetch index id from _index record. + * 2 Fetch index id from _index record. + * 3 Goto l2 + * 4 l1: Generate iid == 1.. + * 6 l2: Continue index creation. + * + * Note that we generate iid == 1 in case of index search on + * purpose: it allows on_replace_dd_index() raise correct + * error - "can not add a secondary key before primary". * * @return Register holding a new index id. */ @@ -1941,24 +1946,20 @@ vdbe_emit_new_sec_index_id(struct Parse *parse, uint32_t space_id, int seek_adr = sqlVdbeAddOp4Int(v, OP_SeekLE, _index_cursor, 0, key_reg, 1); sqlVdbeAddOp4Int(v, OP_IdxLT, _index_cursor, 0, key_reg, 1); - /* Jump over Halt block. */ + int iid_reg = ++parse->nMem; + /* Fetch iid from the row and increment it. */ + sqlVdbeAddOp3(v, OP_Column, _index_cursor, BOX_INDEX_FIELD_ID, iid_reg); + sqlVdbeAddOp2(v, OP_AddImm, iid_reg, 1); int goto_succ_addr = sqlVdbeAddOp0(v, OP_Goto); + sqlVdbeJumpHere(v, seek_adr); + sqlVdbeJumpHere(v, seek_adr + 1); /* * Absence of any records in _index for that space is - * handled here. + * handled here: to indicate that secondary index can't + * be created before primary. */ - sqlVdbeJumpHere(v, seek_adr); - sqlVdbeJumpHere(v, seek_adr + 1); - sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, ON_CONFLICT_ACTION_FAIL, - 0, "can not add a secondary key before primary", - P4_STATIC); - sqlVdbeChangeP5(v, ER_ALTER_SPACE); - + sqlVdbeAddOp2(v, OP_Integer, 1, iid_reg); sqlVdbeJumpHere(v, goto_succ_addr); - /* Fetch iid from the row and increment it. */ - int iid_reg = ++parse->nMem; - sqlVdbeAddOp3(v, OP_Column, _index_cursor, BOX_INDEX_FIELD_ID, iid_reg); - sqlVdbeAddOp2(v, OP_AddImm, iid_reg, 1); return iid_reg; } diff --git a/test/sql-tap/index1.test.lua b/test/sql-tap/index1.test.lua index 5f6706a40..63c98e206 100755 --- a/test/sql-tap/index1.test.lua +++ b/test/sql-tap/index1.test.lua @@ -1031,7 +1031,7 @@ test:do_catchsql_test( [[ CREATE UNIQUE INDEX pk ON t("id"); ]], { - 1, "can not add a secondary key before primary" + 1, "Can't modify space 'T': can not add a secondary key before primary" })
next prev parent reply other threads:[~2019-03-29 18:16 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-28 12:07 [tarantool-patches] [PATCH v2 0/4] Introduce ALTER TABLE ADD CONSTRAINT PK/UNIQUE Nikita Pettik 2019-03-28 12:07 ` [tarantool-patches] [PATCH v2 1/4] sql: rework ALTER TABLE grammar Nikita Pettik 2019-03-28 12:07 ` [tarantool-patches] [PATCH v2 2/4] sql: refactor getNewIid() function Nikita Pettik 2019-03-28 15:11 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-29 18:15 ` n.pettik 2019-04-01 5:17 ` Konstantin Osipov 2019-03-28 12:07 ` [tarantool-patches] [PATCH v2 3/4] sql: fix error message for improperly created index Nikita Pettik 2019-03-28 14:01 ` [tarantool-patches] " Konstantin Osipov 2019-03-28 15:11 ` Vladislav Shpilevoy 2019-03-29 18:16 ` n.pettik [this message] 2019-03-28 12:07 ` [tarantool-patches] [PATCH v2 4/4] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY Nikita Pettik 2019-03-28 15:11 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-29 18:16 ` n.pettik 2019-04-01 17:58 ` Vladislav Shpilevoy 2019-04-03 7:57 ` [tarantool-patches] Re: [PATCH v2 0/4] Introduce ALTER TABLE ADD CONSTRAINT PK/UNIQUE 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=EF378E7D-7662-4BAA-8BA3-8B6140791C6D@tarantool.org \ --to=korablev@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='[tarantool-patches] Re: [PATCH v2 3/4] sql: fix error message for improperly created index' \ /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