Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: "n.pettik" <korablev@tarantool.org>,
	tarantool-patches@freelists.org,
	Kirill Yukhin <kyukhin@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 4/4] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY
Date: Mon, 1 Apr 2019 20:58:20 +0300	[thread overview]
Message-ID: <230e0ca4-8182-1bad-173c-1a806eeda2fe@tarantool.org> (raw)
In-Reply-To: <DA0E7E10-0500-4D96-9FB5-4931F08135FC@tarantool.org>

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,
-					     &not_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(

  reply	other threads:[~2019-04-01 17:58 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
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 [this message]
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=230e0ca4-8182-1bad-173c-1a806eeda2fe@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2 4/4] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY' \
    /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