[patches] [PATCH 0/2] Implement proper constraint check order

Bulat Niatshin niatshin at tarantool.org
Wed Feb 21 20:34:51 MSK 2018


Branch: https://github.com/tarantool/tarantool/tree/bn/gh-2963-proper-replace

The problem is that SQLite allows to have several constraints with
ON CONFLICT REPLACE clause. Second problem is that replace action
happens after firing BEFORE triggers, which may bring potential
conflicts.

1. According to Peter Gulutzan, constraints check order should be:
   1) Check constraints with ON CONFLICT REPLACE, if there is a violation,
     delete conflicting row
   2) Fire BEFORE triggers
   3) Check all constraints including the ones with REPLACE clause, but
      during that check REPLACE error action will become ABORT and error
      message will be raised if conflict still happens.
   4) Do the insertion into Tarantool space
   5) Fire AFTER triggers

2. Also Peter said that only one UNIQUE constraint and only one NOT NULL
   constraint should have REPLACE as an error action.

Bulat Niatshin (2):
  sql: ban multiple ON CONFLICT REPLACE
  sql: change constraints checks order

 src/box/sql/build.c                            |  53 ++++
 src/box/sql/insert.c                           | 324 ++++++++++++++++---------
 src/box/sql/sqliteInt.h                        |  21 +-
 src/box/sql/update.c                           |  25 +-
 test/sql-tap/gh-2963-multiple-replace.test.lua |  69 ++++++
 5 files changed, 377 insertions(+), 115 deletions(-)
 create mode 100755 test/sql-tap/gh-2963-multiple-replace.test.lua

-- 
2.14.1




More information about the Tarantool-patches mailing list