提交 08b98324 authored 作者: Thomas Mueller's avatar Thomas Mueller

Foreign key: don't add a single column index if column is leading key of existing index.

上级 555af2d5
......@@ -20,7 +20,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Pull request #4: Creating and removing temporary tables was getting
<ul><li>Foreign key: don't add a single column index if column
is leading key of existing index.
</li><li>Pull request #4: Creating and removing temporary tables was getting
slower and slower over time, because an internal object id was allocated but
never de-allocated.
</li><li>Issue 609: the spatial index did not support NULL with update and delete operations.
......
......@@ -199,15 +199,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
isOwner = true;
index.getIndexType().setBelongsToConstraint(true);
} else {
if (db.isStarting()) {
// before version 1.3.176, an existing index was used:
// must do the same to avoid
// Unique index or primary key violation:
// "PRIMARY KEY ON """".PAGE_INDEX"
index = getIndex(table, indexColumns, true);
} else {
index = getIndex(table, indexColumns, false);
}
index = getIndex(table, indexColumns, true);
if (index == null) {
index = createIndex(table, indexColumns, false);
isOwner = true;
......
......@@ -145,6 +145,16 @@ public class TestCases extends TestBase {
"foreign key(a_id) references a(id)");
stat.execute("update a set x=200");
stat.execute("drop table if exists a, b");
stat.execute("drop all objects");
stat.execute("create table parent(id int primary key)");
stat.execute("create table child(id int, parent_id int, x int)");
stat.execute("create index y on child(parent_id, x)");
stat.execute("alter table child add constraint z foreign key(parent_id) references parent(id)");
ResultSet rs = stat.executeQuery("select * from information_schema.indexes where table_name = 'CHILD'");
while (rs.next()) {
assertEquals("Y", rs.getString("index_name"));
}
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论