sql: introduce ADD CONSTRAINT statement
After introducing separate space for persisting foreign key constraints, nothing prevents us from adding ALTER TABLE statement to add or drop named constraints. According to ANSI syntax is following: ALTER TABLE <referencing table> ADD CONSTRAINT <referential constraint name> FOREIGN KEY <left paren> <referencing columns> <right paren> REFERENCES <referenced table> [ <referenced columns> ] [ MATCH <match type> ] [ <referential triggered action> ] [ <constraint check time> ] ALTER TABLE <referencing table> DROP CONSTRAINT <constrain name> In our terms it looks like: ALTER TABLE t1 ADD CONSTRAINT f1 FOREIGN KEY(id, a) REFERENCES t2 (id, b) MATCH FULL; ALTER TABLE t1 DROP CONSTRAINT f1; FK constraints which come with CREATE TABLE statement are also persisted with auto-generated name. They are coded after space and its indexes. Moreover, we don't use original SQLite foreign keys anymore: those obsolete structs have been removed alongside FK hash. Now FK constraints are stored only in space. Since types of referencing and referenced fields must match, and now in SQL only PK is allowed to feature INT (other fields are always SCALAR), some tests have been corrected to obey this rule. Part of #3271
Showing
- extra/mkkeywordhash.c 3 additions, 0 deletionsextra/mkkeywordhash.c
- src/box/alter.cc 56 additions, 0 deletionssrc/box/alter.cc
- src/box/fkey.h 16 additions, 2 deletionssrc/box/fkey.h
- src/box/space.h 6 additions, 0 deletionssrc/box/space.h
- src/box/sql.c 11 additions, 97 deletionssrc/box/sql.c
- src/box/sql/alter.c 0 additions, 82 deletionssrc/box/sql/alter.c
- src/box/sql/build.c 511 additions, 262 deletionssrc/box/sql/build.c
- src/box/sql/callback.c 4 additions, 7 deletionssrc/box/sql/callback.c
- src/box/sql/delete.c 8 additions, 7 deletionssrc/box/sql/delete.c
- src/box/sql/fkey.c 572 additions, 1021 deletionssrc/box/sql/fkey.c
- src/box/sql/insert.c 13 additions, 13 deletionssrc/box/sql/insert.c
- src/box/sql/main.c 0 additions, 5 deletionssrc/box/sql/main.c
- src/box/sql/parse.y 26 additions, 11 deletionssrc/box/sql/parse.y
- src/box/sql/pragma.c 25 additions, 221 deletionssrc/box/sql/pragma.c
- src/box/sql/pragma.h 1 addition, 10 deletionssrc/box/sql/pragma.h
- src/box/sql/prepare.c 4 additions, 0 deletionssrc/box/sql/prepare.c
- src/box/sql/sqliteInt.h 149 additions, 70 deletionssrc/box/sql/sqliteInt.h
- src/box/sql/status.c 2 additions, 7 deletionssrc/box/sql/status.c
- src/box/sql/tarantoolInt.h 15 additions, 5 deletionssrc/box/sql/tarantoolInt.h
- src/box/sql/update.c 10 additions, 11 deletionssrc/box/sql/update.c
Loading
Please register or sign in to comment