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

improved referential constraint performance

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