Nit: ck_constraint_def_sizeof() return uint32_t
Also why do we not use vdbe_emit_halt_with_presence_test()
during creation of check constraints?
tarantool> create table t2(id int primary key, constraint ck1 check(id > 0),
constraint ck1 check(id < 0))
---
- error: Duplicate key exists in unique index 'primary' in space
'_ck_constraint'
...
tarantool> create table t2(id int primary key, constraint fk1 foreign
key(id) references t2, constraint fk1 foreign key(id) references t2)
---
- error: Constraint FK1 already exists
...
And this is a bug in FK
https://github.com/tarantool/tarantool/issues/4183
+ if (rlist_next(dst_ck_link) != &dest->ck_constraint)
+ return 0;
After next patch this check could be removed: VDBE program for checking
consistency of check constraints would be generated automatically.
In SQLite xFer allows to avoid generation of this program. On the other hand,
if you added way to temporarily disable check constraints, we would able
to leave this check and re-enable them after query is executed. So, consider
way of disabling/enabling check constraints - it might be useful for other
cases as well.
At first, there is no way to control this state as you propose.
Next, disabling/enabling triggers is required for upgrade() functionality
and is not a part of public API.
As in further patches ck constraint are rely
on trigger machinery, we don't need a separate controller.
So, I've reject xfer optimization when source or destination space has
ck constraints.
This patch introduces a new system space to persist check
constraints. Format of the space:
_ck_constraint (space id = 357)
[<constraint name> STR, <space id> UINT, <expression string>STR]
Because space alter, index alter and space truncate operations
cause space recreation, introduced RebuildCkConstrains object
that compile
new ck constraint objects, replace and remove
existent instances atomically(when some compilation fails,
nothing changed).
In fact, in scope of this patch we don't
really need to recreate ck_constraint object in such situations
(patch space_def pointer in AST like we did it before is enough
now, but we would
The main motivation for these changes is the ability to support
ADD CHECK CONSTRAINT operation in the future. CK constraints are
are easier to manage as self-sustained objects: we mustn’t
the tuple describing target space to do it(unlike the current
architecture).
Disabled xfer optimization when some space have ck constraints
because in the following patches this xfer optimisation becomes
impossible. No reason to rewrite this code.
Needed for #3691
—