[tarantool-patches] Re: [PATCH v2 4/4] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Mon Apr 1 20:58:20 MSK 2019


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(




More information about the Tarantool-patches mailing list