截断花费太多时间 hsqldb

Truncating takes too much time hsqldb

我使用 HSQLDB 2.3.2,但遇到了以下问题:

  1. 我的数据库缓存了 table 10 000 000 条记录,没有任何约束和索引。它的大小约为 900mb。我关闭自动提交模式,当我尝试执行 "Truncate table tableName" 时,执行挂起但只有 dbName.backup 在增长。原因如下:

TRACE ENGINE:? - copyShadow [size, time] 2246252 9721
TRACE ENGINE:? - setFileModified flag set
TRACE ENGINE:? - cache save rows [count,time] totals 24801,9921 operation 24801,9921 txts 96
TRACE ENGINE:? - copyShadow [size, time] 4426920 7732
TRACE ENGINE:? - cache save rows [count,time] totals 49609,17775 operation 24808,7854 txts 96
TRACE ENGINE:? - copyShadow [size, time] 6574796 9024

大约需要 1500-2000 秒,最后我可以得到空 table 或类似这样的异常:

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1,525.509 sec
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.OutOfMemoryError: Java heap space

删除截断后 dbName.backup。我不必在我的应用程序中使用任何备份,我怎样才能避免复制?

  1. dbName.properties 不起作用。它包含以下文本:

    #HSQL Database Engine 2.3.2

    #Thu Mar 19 08:42:10 EAT 2015

    version=2.3.2
    modified=no

I tried to append hsqldb.applog=1 but nothing happened.
dbName.app.log appears in case you change the line SET DATABASE EVENT LOG LEVEL 1 in dbName.script
After working with the database from my application dbName.properties is overwrited: 'modified' changes on 'yes' and any lines below are deleted. What do I do wrong?

My database has cached table with 10 000 000 records without any constraints and indexes.

没有任何约束和索引的大 table 是完全错误的。 SELECT 上影响少数行的任何 SELECT、UPDATE 或 DELETE 都必须搜索 table.

中的所有行

I try to execute "Truncate table tableName"

以上语句允许您在提交之前回滚操作。回滚的信息保存在内存中,当table很大时,内存会运行溢出。当您确实要提交更改时,请改用此语句:

TRUNCATE TABLE tableName AND COMMIT

指南中提到了这一点:http://hsqldb.org/doc/2.0/guide/dataaccess-chapt.html#dac_truncate_statement

您可以对 .properties 文件进行的唯一添加是将数据库文件设置为只读。任何其他更改都将被忽略和删除。

.backup 文件供数据库引擎内部使用,您无法停止使用。