HSQLDB:如何创建大小大于堆 space 的 table?

HSQLDB: How to create a table with size larger than heap space?

我想创建一个简单的 table (id INT PRIMARY KEY, value INT) 并插入 1600 万行。

如果我使用MySQL,那可能需要128M+数据(MyISAM固定格式)。

现在我正在使用 HSQLDB 并且只提供 128M 堆 space(即 运行 和 -Xmx128m)。

我使用文件模式jdbc:hsqldb:file:...,这是我的代码:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Collections;

import org.hsqldb.jdbc.JDBCDriver;

public class HSQLDBTest {
    private static final int BULK_SIZE = 16384;
    private static final int BATCHES = 1024;

    public static void main(String[] args) throws Exception {
        String sql = "INSERT INTO test (value) VALUES " + String.join(", ", Collections.nCopies(BULK_SIZE, "(?)"));
        try (Connection conn = new JDBCDriver().connect("jdbc:hsqldb:file:test", null)) {
            conn.createStatement().execute("CREATE TABLE test (id INT NOT NULL PRIMARY KEY IDENTITY, value INT DEFAULT 0 NOT NULL)");
            PreparedStatement ps = conn.prepareStatement(sql);
            for (int i = 0; i < BATCHES; i ++) {
                for (int j = 0; j < BULK_SIZE; j ++) {
                    ps.setInt(j + 1, j * j);
                }
                ps.executeUpdate();
                System.out.println(i);
            }
        }
    }
}

插入停止在大约 0.7M 行 (i = 40) 并抛出 java.sql.SQLException: java.lang.OutOfMemoryError: GC overhead limit exceeded

是否有任何其他模式或 属性 可以使 HSQLDB 创建 table 且大小大于堆 space?

使用 cached table。如果您未指定 table,则假定类型为 memory

create cached table test (...);

引用from the manual

CACHED tables are created with the CREATE CACHED TABLE command. Only part of their data or indexes is held in memory, allowing large tables that would otherwise take up to several hundred megabytes of memory.