box: implement field foreign keys
Foreign key is a special type of constraint that makes a relation between spaces. When declared in some space, each tuple in that space refers to some tuple in another, foreign space. Reference is defined in foreign key definition as a correspondence of field of that spaces, local and remote. Foreign key preserves that reference between tuples and consists of two checks: 1. When a tuple is added to space with foreign space constraint, it must be checked that there is a corresponding tuple in foreign space, with the same values in fields according to foreign key definitiion. 2. When a tuple is deleted from space that is a foreign space for some other space, it must be checked that no tuple references the deleted one. This commit introduces field foreign keys that link spaces by just one field. They are declared in tuple format in one of the following forms: space:format{..,{name=.., foreign_key=<fkey>},..} space:format{..,{name=.., foreign_key={<name>=<fkey>}},..} Where fkey has a form of a table: {space=<foreign space id/name>, field=<foreign field id/name>} NO_DOC=see later commits NO_CHANGELOG=see later commits
Showing
- src/box/CMakeLists.txt 1 addition, 0 deletionssrc/box/CMakeLists.txt
- src/box/errcode.h 3 additions, 0 deletionssrc/box/errcode.h
- src/box/field_def.c 34 additions, 0 deletionssrc/box/field_def.c
- src/box/lua/schema.lua 80 additions, 0 deletionssrc/box/lua/schema.lua
- src/box/space.c 53 additions, 6 deletionssrc/box/space.c
- src/box/space.h 2 additions, 0 deletionssrc/box/space.h
- src/box/tuple_constraint.c 23 additions, 2 deletionssrc/box/tuple_constraint.c
- src/box/tuple_constraint.h 47 additions, 0 deletionssrc/box/tuple_constraint.h
- src/box/tuple_constraint_def.c 225 additions, 5 deletionssrc/box/tuple_constraint_def.c
- src/box/tuple_constraint_def.h 60 additions, 2 deletionssrc/box/tuple_constraint_def.h
- src/box/tuple_constraint_fkey.c 348 additions, 0 deletionssrc/box/tuple_constraint_fkey.c
- src/box/tuple_constraint_fkey.h 39 additions, 0 deletionssrc/box/tuple_constraint_fkey.h
- src/box/tuple_constraint_func.c 1 addition, 0 deletionssrc/box/tuple_constraint_func.c
- src/box/vinyl.c 2 additions, 1 deletionsrc/box/vinyl.c
- test/box/error.result 3 additions, 0 deletionstest/box/error.result
- test/engine-luatest/gh_6436_field_foreign_key_test.lua 639 additions, 0 deletionstest/engine-luatest/gh_6436_field_foreign_key_test.lua
Loading
Please register or sign in to comment