From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org, Nikita Pettik <korablev@tarantool.org> Subject: [tarantool-patches] Re: [PATCH v2 3/4] sql: fix error message for improperly created index Date: Thu, 28 Mar 2019 18:11:55 +0300 [thread overview] Message-ID: <e5df7cba-1031-9d50-bf78-5d481b63642d@tarantool.org> (raw) In-Reply-To: <1e34e241c5647b34a59ae0703eea3bcdc39c8fac.1553729426.git.korablev@tarantool.org> 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. On 28/03/2019 15:07, Nikita Pettik wrote: > Table can be created without any indexes (for instance, from Lua-land). > On the other hand, bytecode generated for CREATE INDEX statement > attempts at finding entry in _index space with given space id. > In case it is not found error "wrong space id" is raised. On the other > hand, it is obvious that such message is appeared when table doesn't > have any created indexes yet. Hence, lets fix this message to indicate > that primary key should be created before any secondary indexes. > > Closes #3914 > --- > src/box/sql/build.c | 3 +-- > test/sql-tap/index1.test.lua | 19 ++++++++++++++++++- > 2 files changed, 19 insertions(+), 3 deletions(-) > > diff --git a/src/box/sql/build.c b/src/box/sql/build.c > index f55f6d800..20cc346a0 100644 > --- a/src/box/sql/build.c > +++ b/src/box/sql/build.c > @@ -1946,8 +1946,7 @@ generate_index_id(struct Parse *parse, uint32_t space_id, int cursor) > sqlVdbeJumpHere(v, seek_adr); > sqlVdbeJumpHere(v, seek_adr + 1); > sqlVdbeAddOp4(v, OP_Halt, SQL_ERROR, ON_CONFLICT_ACTION_FAIL, 0, > - sqlMPrintf(parse->db, "Invalid space id: %d", space_id), > - P4_DYNAMIC); > + "can not add a secondary key before primary", P4_STATIC); > > sqlVdbeJumpHere(v, goto_succ_addr); > /* Fetch iid from the row and increment it. */ ======================================================================== commit 50adf5f01374a4cd6741c862e23ba902ab651909 Author: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Date: Thu Mar 28 16:03:26 2019 +0300 Review fix diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 076f62dde..78cd3cee6 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1943,11 +1943,16 @@ vdbe_emit_new_sec_index_id(struct Parse *parse, uint32_t space_id, sqlVdbeAddOp4Int(v, OP_IdxLT, _index_cursor, 0, key_reg, 1); /* Jump over Halt block. */ int goto_succ_addr = sqlVdbeAddOp0(v, OP_Goto); - /* Invalid space id handling block starts here. */ + /* + * Absence of any records in _index for that space is + * handled here. + */ sqlVdbeJumpHere(v, seek_adr); sqlVdbeJumpHere(v, seek_adr + 1); - sqlVdbeAddOp4(v, OP_Halt, SQL_ERROR, ON_CONFLICT_ACTION_FAIL, 0, - "can not add a secondary key before primary", P4_STATIC); + 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); sqlVdbeJumpHere(v, goto_succ_addr); /* Fetch iid from the row and increment it. */
next prev parent reply other threads:[~2019-03-28 15:11 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 [this message] 2019-03-29 18:16 ` n.pettik 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=e5df7cba-1031-9d50-bf78-5d481b63642d@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.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