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 329B7260EA for ; Wed, 23 Jan 2019 12:56:24 -0500 (EST) 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 5MipcojFAdPG for ; Wed, 23 Jan 2019 12:56:24 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 CEE46261F7 for ; Wed, 23 Jan 2019 12:56:23 -0500 (EST) From: Nikita Pettik Subject: [tarantool-patches] [PATCH v2 4/5] sql: fix error message for improperly created index Date: Wed, 23 Jan 2019 20:56:17 +0300 Message-Id: <978bc9e1438aca0b2978afe3aad9a6d0e18cdf31.1548265148.git.korablev@tarantool.org> In-Reply-To: References: In-Reply-To: References: 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: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, kostja@tarantool.org, Nikita Pettik 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 | 4 ++-- test/sql-tap/index1.test.lua | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index d7dcc5cb4..660d5acfc 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -2092,8 +2092,8 @@ generate_index_id(struct Parse *parse, uint32_t space_id, int cursor) sqlite3VdbeJumpHere(v, seek_adr); sqlite3VdbeJumpHere(v, seek_adr + 1); sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_ERROR, ON_CONFLICT_ACTION_FAIL, 0, - sqlite3MPrintf(parse->db, "Invalid space id: %d", - space_id), P4_DYNAMIC); + "can not add a secondary key before primary", + P4_STATIC); sqlite3VdbeJumpHere(v, goto_succ_addr); /* Fetch iid from the row and increment it. */ diff --git a/test/sql-tap/index1.test.lua b/test/sql-tap/index1.test.lua index 49f61a52a..121381747 100755 --- a/test/sql-tap/index1.test.lua +++ b/test/sql-tap/index1.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(70) +test:plan(72) --!./tcltestrunner.lua -- 2001 September 15 @@ -1016,5 +1016,22 @@ if (0 > 0) end +test:do_test( + "index-22.1.0", + function() + format = {} + format[1] = { name = 'id', type = 'scalar'} + format[2] = { name = 'f2', type = 'scalar'} + s = box.schema.create_space('T', {format = format}) + end, + {}) + +test:do_catchsql_test( + "alter-8.1.1", + [[ + CREATE UNIQUE INDEX pk ON t("id"); + ]], { + 1, "can not add a secondary key before primary" + }) test:finish_test() -- 2.15.1