schema: add new system space for CHECK constraints
This patch introduces a new system space to persist check constraints. The format of the new system space is _ck_constraint (space id = 364) [<space id> UINT, <constraint name> STR, <is_deferred>BOOL, <language>STR, <code>STR] A CK constraint is local for a space, so every pair <space id, CK name> is unique (it is also the PK in the _ck_constraint space). After insertion into this space, a new instance describing check constraint is created. Check constraint holds an exspression AST. While space features some check constraints, it isn't allowed to be dropped. The :drop() space method firstly deletes all check constraints and then removes an entry from the _space. Because the space alter, the index alter and the space truncate operations cause space recreation process, a new RebuildCkConstrains object is introduced. This alter object compiles a new ck constraint object, replaces and removes an existent instances atomically (but if the assembly of some ck constraint object fails, nothing is changed). In fact, in scope of this patch we don't really need to recreate a ck_constraint object in such situations (it is enough to patch space_def pointer in AST tree like we did it before, but we are going to recompile a VDBE that represents ck constraint in further patches, and that operation is not safe). The main motivation for these changes is an ability to support ADD CHECK CONSTRAINT operation in the future. CK constraints are easier to manage as self-sustained objects: such change is managed with atomic insertion(unlike the current architecture). Finally, the xfer optimization is disabled now if some space have ck constraints. In following patches this xfer optimisation becomes impossible, so there is no reason to rewrite this code now. Needed for #3691
Showing
- src/box/CMakeLists.txt 1 addition, 0 deletionssrc/box/CMakeLists.txt
- src/box/alter.cc 247 additions, 11 deletionssrc/box/alter.cc
- src/box/alter.h 1 addition, 0 deletionssrc/box/alter.h
- src/box/bootstrap.snap 0 additions, 0 deletionssrc/box/bootstrap.snap
- src/box/ck_constraint.c 146 additions, 0 deletionssrc/box/ck_constraint.c
- src/box/ck_constraint.h 203 additions, 0 deletionssrc/box/ck_constraint.h
- src/box/errcode.h 2 additions, 1 deletionsrc/box/errcode.h
- src/box/lua/schema.lua 4 additions, 0 deletionssrc/box/lua/schema.lua
- src/box/lua/space.cc 2 additions, 0 deletionssrc/box/lua/space.cc
- src/box/lua/upgrade.lua 40 additions, 0 deletionssrc/box/lua/upgrade.lua
- src/box/schema.cc 8 additions, 0 deletionssrc/box/schema.cc
- src/box/schema_def.h 11 additions, 0 deletionssrc/box/schema_def.h
- src/box/space.c 2 additions, 0 deletionssrc/box/space.c
- src/box/space.h 5 additions, 0 deletionssrc/box/space.h
- src/box/space_def.c 1 addition, 97 deletionssrc/box/space_def.c
- src/box/space_def.h 0 additions, 4 deletionssrc/box/space_def.h
- src/box/sql.c 1 addition, 85 deletionssrc/box/sql.c
- src/box/sql.h 1 addition, 39 deletionssrc/box/sql.h
- src/box/sql/build.c 192 additions, 37 deletionssrc/box/sql/build.c
- src/box/sql/insert.c 24 additions, 31 deletionssrc/box/sql/insert.c
Loading
Please register or sign in to comment