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 7BE3922B44 for ; Wed, 9 Jan 2019 07:13:28 -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 pcpSDvF-cjc2 for ; Wed, 9 Jan 2019 07:13:28 -0500 (EST) Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (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 31B9D1FE0E for ; Wed, 9 Jan 2019 07:13:28 -0500 (EST) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 0/6] Introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PK Date: Wed, 9 Jan 2019 14:13:14 +0200 Message-Id: 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, Nikita Pettik Branch: https://github.com/tarantool/tarantool/tree/np/gh-3914-fix-create-index Issues: https://github.com/tarantool/tarantool/issues/3097 https://github.com/tarantool/tarantool/issues/3914 It turns out that if space is created from Lua and has no indexes, simply CREATE INDEX statement executed from SQL will raise strange error "Wrong space id". It appears due to fetch of new index id from _index space. However, in case it containts no entries with given space id it doesn't really mean that there is no space with given id. It only implies that space with given id lacks any indexes. This issue is resovled by using correct error message. However, we still need way to primary key on already existing table. Hence, lets introduce ALTER TABLE ADD CONSTRAINT PRIMARY KEY, which would create index with id == 0. Note that CREATE INDEX is not suitable for creating PK owing to the following scenario: Create table with no indexes Create index (it implicitly becomes PK since it is the first index) Create constraint PK (fails since index with id == 0 already exists) Indexes are out of ANSI specification, so example above must not fail (all vendors I've checked don't fail). Nikita Pettik (6): sql: move constraint name to struct contraint_parse sql: rework ALTER TABLE grammar sql: remove start token from sql_create_index args sql: refactor getNewIid() function sql: fix error message for improperly created index sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY src/box/sql/alter.c | 4 +- src/box/sql/build.c | 141 +++++++++++++++++++++++++------------------ src/box/sql/parse.y | 76 ++++++++++++++++------- src/box/sql/prepare.c | 11 ++++ src/box/sql/sqliteInt.h | 37 ++++++------ test/sql-tap/alter.test.lua | 58 +++++++++++++++++- test/sql-tap/index1.test.lua | 28 ++++++++- 7 files changed, 254 insertions(+), 101 deletions(-) -- 2.15.1