[tarantool-patches] [PATCH 0/6] Introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PK

Nikita Pettik korablev at tarantool.org
Wed Jan 9 15:13:14 MSK 2019


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





More information about the Tarantool-patches mailing list