From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 3ADF529224 for ; Mon, 1 Apr 2019 13:58:23 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vHKsFKP1JNef for ; Mon, 1 Apr 2019 13:58:23 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id E72AD240BB for ; Mon, 1 Apr 2019 13:58:22 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 4/4] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY References: <07f3d310-a7d0-e843-38e3-139074584ced@tarantool.org> From: Vladislav Shpilevoy Message-ID: <230e0ca4-8182-1bad-173c-1a806eeda2fe@tarantool.org> Date: Mon, 1 Apr 2019 20:58:20 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: "n.pettik" , tarantool-patches@freelists.org, Kirill Yukhin Your diff to the previous commit is ok to me. But probably in such a case it is worth doing the same for the next commit, creating a primary index? I force pushed my review fixes and copy pasted them below. After that LGTM. Kirill, note, I *force* pushed. Do not forget to pull the newest version before push into the master. =============================================================== diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 38cd74da4..c7248f734 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1993,30 +1993,6 @@ vdbe_emit_new_sec_index_id(struct Parse *parse, uint32_t space_id, return iid_reg; } -/** - * Generate code that pushes a primary index id 0, but checks if a - * space with @a space_id has any indexes. If it does, then the - * execution is stopped with an error. - * - * @return Register holding a new index id. - */ -static int -vdbe_emit_new_pk_index_id(struct Parse *parse, uint32_t space_id, - int _index_cursor) -{ - struct Vdbe *v = sqlGetVdbe(parse); - int not_found_addr, found_addr = - vdbe_emit_space_index_search(parse, space_id, _index_cursor, - ¬_found_addr); - sqlVdbeJumpHere(v, found_addr); - sqlVdbeAddOp4(v, OP_Halt, SQL_ERROR, ON_CONFLICT_ACTION_FAIL, 0, - "multiple primary keys are not allowed", P4_STATIC); - sqlVdbeJumpHere(v, not_found_addr); - int index_id = parse->nMem++; - sqlVdbeAddOp2(v, OP_Integer, 0, index_id); - return index_id; -} - /** * Add new index to table's indexes list. * We follow convention that PK comes first in list. @@ -2482,8 +2458,8 @@ sql_create_index(struct Parse *parse) { * we can immediately halt execution of VDBE. */ if (idx_type == SQL_INDEX_TYPE_CONSTRAINT_PK) { - index_id = vdbe_emit_new_pk_index_id(parse, def->id, - cursor); + index_id = ++parse->nMem; + sqlVdbeAddOp2(vdbe, OP_Integer, 0, index_id); } else { index_id = vdbe_emit_new_sec_index_id(parse, def->id, cursor); diff --git a/test/sql-tap/alter.test.lua b/test/sql-tap/alter.test.lua index 3e87fbb8b..2aba4c4e9 100755 --- a/test/sql-tap/alter.test.lua +++ b/test/sql-tap/alter.test.lua @@ -546,7 +546,7 @@ test:do_catchsql_test( [[ ALTER TABLE t ADD CONSTRAINT pk1 PRIMARY KEY("f2"); ]], { - 1, "multiple primary keys are not allowed" + 1, "Duplicate key exists in unique index 'primary' in space '_index'" }) test:do_catchsql_test(