sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY
Table (aka space) can be created without indexes at least from Lua-land (note that according ANSI SQL table may lack PK). Since there were no facilities to create primary key constraint on already existing table, lets extend ADD CONSTRAINT statement with UNIQUE and PRIMARY KEY clauses. In this case, UNIQUE works exactly in the same way as CREATE UNIQUE INDEX ... statement does. In Tarantool primary index is an index with id == 0, so during execution of ADD CONSTRAINT PRIMARY KEY we check that there is no any entries in _index space and create that one. Otherwise, error is raised. Part of #3097 Follow-up #3914 @TarantoolBot document Title: ALTER TABLE ADD CONSTRAINT UNIQUE/PK Currently, tables which lack primary key can take part neither in DDL nor DQL routines. Attempt to do this leads to error. Such tables (without PK) may appear as spaces created from Lua NoSQL interface. To improve NoSQL-SQL interoperability, we are introducing way to add primary key to already existing table: ALTER TABLE <table name> ADD CONSTRAINT <constraint name> PRIMARY KEY(<column list>) And alongside with this another one alias to CREATE UNIQUE INDEX: ALTER TABLE <table name> ADD CONSTRAINT <constraint name> UNIQUE(<column list>) Note that Tarantool PK constraint should be explicitly added before any other unique constraints or secondary indexes. Otherwise, error is raised: "can not add a secondary key before primary".
Showing
- src/box/sql/build.c 53 additions, 11 deletionssrc/box/sql/build.c
- src/box/sql/parse.y 10 additions, 0 deletionssrc/box/sql/parse.y
- test/sql-tap/alter.test.lua 56 additions, 1 deletiontest/sql-tap/alter.test.lua
- test/sql-tap/index1.test.lua 10 additions, 1 deletiontest/sql-tap/index1.test.lua
- test/sql/misc.result 3 additions, 3 deletionstest/sql/misc.result
Loading
Please register or sign in to comment