forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
SQL: constraints checks order
Bulat Niatshin edited this page Dec 19, 2017
·
2 revisions
In SQL we have three four major constraints - 'UNIQUE', 'FOREIGN KEY', 'CHECK' and 'NOT NULL'.
Also we have non-standard ON CONFLICT clause, which propose what kind of action SQL should do if error happens. ON CONFLICT clause can be ABORT, FAIL, ROLLBACK, IGNORE, REPLACE. Except for REPLACE option, constraint checking order doesn't matter, because ABORT, FAIL, ROLLBACK, IGNORE semantics doesn't affect space data. According to that, constraint checking order in INSERT/UPDATE statements:
- Check all NOT NULL constraints with ON CONFLICT REPLACE option. If user didn't specify DEFAULT value for that column, change error action to ABORT and check new value. If user specified DEFAULT value and conflict happened, replace conflicting value with a DEFAULT one.
- Check all UNIQUE constraints with ON CONFLICT REPLACE clause. If there is a conflicting row, replace it with a new one.
- Fire all BEFORE triggers.
- Check all NOT NULL constraints. If there was a REPLACE error action for a particular column, change it to ABORT and check new values.
- Check all CHECK constraints.
- Check all UNIQUE constraints. During that iteration error action is ABORT for all constraints with ON CONFLICT REPLACE. All conflicting rows replacing happened on step 2, on that step we don't change anything in space.
- Fire all AFTER triggers.
- Prepare new tuples and finish insertion/update by calling Tarantool API.
Architecture Specifications
- Server architecture
- Feature specifications
- What's in a good specification
- Functional indexes
- Space _index structure
- R tree index quick start and usage
- LuaJIT
- Vinyl
- SQL
- Testing
- Performance
How To ...?
- ... add new fuzzers
- ... build RPM or Deb package using packpack
- ... calculate memory size
- ... debug core dump of stripped tarantool
- ... debug core from different OS
- ... debug Lua state with GDB
- ... generate new bootstrap snapshot
- ... use Address Sanitizer
- ... collect a coredump
Lua modules
Useful links