提交 5a7685a3 authored 作者: Thomas Mueller's avatar Thomas Mueller

After truncating tables, opening large databases could become slow.

上级 f7eebbbb
...@@ -32,6 +32,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -32,6 +32,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
} }
public void test() throws SQLException { public void test() throws SQLException {
testIndexRebuiltOnce();
testIndexNotRebuilt(); testIndexNotRebuilt();
testCalled(); testCalled();
testCloseLog0(false); testCloseLog0(false);
...@@ -39,6 +40,45 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -39,6 +40,45 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
deleteDb("databaseEventListener"); deleteDb("databaseEventListener");
} }
private void testIndexRebuiltOnce() throws SQLException {
if (config.memory) {
return;
}
deleteDb("databaseEventListener");
String url = getURL("databaseEventListener", true);
String user = getUser(), password = getPassword();
Properties p = new Properties();
p.setProperty("user", user);
p.setProperty("password", password);
Connection conn = DriverManager.getConnection(url, p);
Statement stat = conn.createStatement();
// the old.id index head is at position 0
stat.execute("create table old(id identity) as select 1");
// the test.id index head is at position 1
stat.execute("create table test(id identity) as select 1");
conn.close();
conn = DriverManager.getConnection(url, p);
stat = conn.createStatement();
// free up space at position 0
stat.execute("drop table old");
stat.execute("insert into test values(2)");
stat.execute("checkpoint sync");
stat.execute("shutdown immediately");
try {
conn.close();
} catch (SQLException e) {
assertKnownException(e);
}
// now the index should be re-built
conn = DriverManager.getConnection(url, p);
conn.close();
TestDatabaseEventListener l = new TestDatabaseEventListener();
p.put("DATABASE_EVENT_LISTENER_OBJECT", l);
conn = org.h2.Driver.load().connect(url, p);
conn.close();
assertTrue(!l.calledCreateIndex);
}
private void testIndexNotRebuilt() throws SQLException { private void testIndexNotRebuilt() throws SQLException {
if (config.memory) { if (config.memory) {
return; return;
...@@ -69,7 +109,6 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -69,7 +109,6 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
conn = org.h2.Driver.load().connect(url, p); conn = org.h2.Driver.load().connect(url, p);
conn.close(); conn.close();
assertTrue(!l.calledCreateIndex); assertTrue(!l.calledCreateIndex);
} }
private void testCloseLog0(boolean shutdown) throws SQLException { private void testCloseLog0(boolean shutdown) throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论