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

Referential integrity constraints sometimes used the wrong index.

上级 16d95eef
...@@ -18,7 +18,10 @@ Change Log ...@@ -18,7 +18,10 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>The Polish translation was completed and corrected by Wojtek Jurczyk. Thanks a lot! <ul><li>Referential integrity constraints sometimes used the wrong index,
such that updating a row in the referenced table incorrectly failed with
a constraint violation.
</li><li>The Polish translation was completed and corrected by Wojtek Jurczyk. Thanks a lot!
</li><li>Issue 545: Unnecessary duplicate code was removed. </li><li>Issue 545: Unnecessary duplicate code was removed.
</li><li>The profiler tool can now process files with full thread dumps. </li><li>The profiler tool can now process files with full thread dumps.
</li><li>MVStore: the file format was changed slightly. </li><li>MVStore: the file format was changed slightly.
......
...@@ -327,16 +327,13 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -327,16 +327,13 @@ public class AlterTableAddConstraint extends SchemaCommand {
return false; return false;
} }
Column[] indexCols = existingIndex.getColumns(); Column[] indexCols = existingIndex.getColumns();
if (indexCols.length < cols.length) { if (indexCols.length != cols.length) {
return false; return false;
} }
for (IndexColumn col : cols) { for (IndexColumn col : cols) {
// all columns of the list must be part of the index, // all columns of the list must be part of the index
// but not all columns of the index need to be part of the list
// holes are not allowed (index=a,b,c & list=a,b is ok; but list=a,c
// is not)
int idx = existingIndex.getColumnIndex(col.column); int idx = existingIndex.getColumnIndex(col.column);
if (idx < 0 || idx >= cols.length) { if (idx < 0) {
return false; return false;
} }
} }
......
...@@ -39,6 +39,7 @@ public class TestCases extends TestBase { ...@@ -39,6 +39,7 @@ public class TestCases extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
testReferenceableIndexUsage();
testClearSyntaxException(); testClearSyntaxException();
testEmptyStatements(); testEmptyStatements();
testViewParameters(); testViewParameters();
...@@ -102,6 +103,19 @@ public class TestCases extends TestBase { ...@@ -102,6 +103,19 @@ public class TestCases extends TestBase {
testBinaryCollation(); testBinaryCollation();
deleteDb("cases"); deleteDb("cases");
} }
private void testReferenceableIndexUsage() throws SQLException {
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("drop table if exists a, b");
stat.execute("create table a(id int, x int) as select 1, 100");
stat.execute("create index idx1 on a(id, x)");
stat.execute("create table b(id int primary key, a_id int) as select 1, 1");
stat.execute("alter table b add constraint x foreign key(a_id) references a(id)");
stat.execute("update a set x=200");
stat.execute("drop table if exists a, b");
conn.close();
}
private void testClearSyntaxException() throws SQLException { private void testClearSyntaxException() throws SQLException {
Connection conn = getConnection("cases"); Connection conn = getConnection("cases");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论