提交 c1d91a75 authored 作者: Thomas Mueller's avatar Thomas Mueller

improved referential constraint performance

上级 ace817f4
......@@ -16,7 +16,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The Lucene fulltext index was empty when opening a database with fulltext
<ul></li>Referential constraint checking improvement: now the constraint is only checked
if the key column values change.
<li>The Lucene fulltext index was empty when opening a database with fulltext
index enabled, and re-indexing it didn't work. Fixed.
</li><li>The character '$' could not be used in identifier names (table name,
column names and so on). Fixed.
......
......@@ -286,7 +286,7 @@ public class ConstraintReferential extends Constraint {
}
if (t == table) {
if (!skipOwnTable) {
checkRowOwnTable(session, newRow);
checkRowOwnTable(session, oldRow, newRow);
}
}
if (t == refTable) {
......@@ -294,25 +294,31 @@ public class ConstraintReferential extends Constraint {
}
}
private void checkRowOwnTable(Session session, Row newRow) throws SQLException {
private void checkRowOwnTable(Session session, Row oldRow, Row newRow) throws SQLException {
if (newRow == null) {
return;
}
boolean containsNull = false;
boolean constraintColumnsEqual = oldRow != null;
for (int i = 0; i < columns.length; i++) {
int idx = columns[i].column.getColumnId();
Value v = newRow.getValue(idx);
if (v == ValueNull.INSTANCE) {
containsNull = true;
break;
// return early if one of the columns is NULL
return;
}
if (constraintColumnsEqual) {
if (!v.compareEqual(oldRow.getValue(idx))) {
constraintColumnsEqual = false;
}
}
}
if (containsNull) {
if (constraintColumnsEqual) {
// return early if the key columns didn't change
return;
}
if (refTable == table) {
// special case self referencing constraints: check the inserted row
// first
// special case self referencing constraints:
// check the inserted row first
boolean self = true;
for (int i = 0; i < columns.length; i++) {
int idx = columns[i].column.getColumnId();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论