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

Read-only databases: some queries (such as distinct queries) tried to create…

Read-only databases: some queries (such as distinct queries) tried to create temporary tables, which failed for read only databases.
上级 9ded294c
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>This database no longer uses finalize() except for temporary files. <ul><li>Read-only databases: some queries (such as distinct queries)
tried to create temporary tables, which failed for read only databases.
</li><li>This database no longer uses finalize() except for temporary files.
The system property "h2.runFinalize" is no longer supported. The system property "h2.runFinalize" is no longer supported.
Unclosed connections are still detected, but the opening stack trace is now collected Unclosed connections are still detected, but the opening stack trace is now collected
only if connections are not closed repeatedly (starting with the second unclosed connection). only if connections are not closed repeatedly (starting with the second unclosed connection).
......
...@@ -253,7 +253,7 @@ public class LocalResult implements ResultInterface, ResultTarget { ...@@ -253,7 +253,7 @@ public class LocalResult implements ResultInterface, ResultTarget {
distinctRows.put(array, values); distinctRows.put(array, values);
rowCount = distinctRows.size(); rowCount = distinctRows.size();
Database db = session.getDatabase(); Database db = session.getDatabase();
if (rowCount > db.getSettings().maxMemoryRowsDistinct && db.isPersistent()) { if (rowCount > db.getSettings().maxMemoryRowsDistinct && db.isPersistent() && !db.isReadOnly()) {
external = new ResultTempTable(session, sort); external = new ResultTempTable(session, sort);
rowCount = external.addRows(distinctRows.values()); rowCount = external.addRows(distinctRows.values());
distinctRows = null; distinctRows = null;
...@@ -268,7 +268,10 @@ public class LocalResult implements ResultInterface, ResultTarget { ...@@ -268,7 +268,10 @@ public class LocalResult implements ResultInterface, ResultTarget {
if (rows.size() > maxMemoryRows && session.getDatabase().isPersistent()) { if (rows.size() > maxMemoryRows && session.getDatabase().isPersistent()) {
if (external == null) { if (external == null) {
if (randomAccess) { if (randomAccess) {
external = new ResultTempTable(session, sort); Database db = session.getDatabase();
if (!db.isReadOnly()) {
external = new ResultTempTable(session, sort);
}
} else { } else {
external = new ResultDiskBuffer(session, sort, values.length); external = new ResultDiskBuffer(session, sort, values.length);
} }
...@@ -308,7 +311,10 @@ public class LocalResult implements ResultInterface, ResultTarget { ...@@ -308,7 +311,10 @@ public class LocalResult implements ResultInterface, ResultTarget {
} }
if (external == null) { if (external == null) {
if (randomAccess) { if (randomAccess) {
external = new ResultTempTable(session, sort); Database db = session.getDatabase();
if (!db.isReadOnly()) {
external = new ResultTempTable(session, sort);
}
} else { } else {
external = new ResultDiskBuffer(session, sort, list.length); external = new ResultDiskBuffer(session, sort, list.length);
} }
......
...@@ -36,6 +36,7 @@ public class TestReadOnly extends TestBase { ...@@ -36,6 +36,7 @@ public class TestReadOnly extends TestBase {
if (config.memory) { if (config.memory) {
return; return;
} }
testReadOnlyTempTableResult();
testReadOnlyConnect(); testReadOnlyConnect();
testReadOnlyDbCreate(); testReadOnlyDbCreate();
if (!config.googleAppEngine) { if (!config.googleAppEngine) {
...@@ -45,6 +46,18 @@ public class TestReadOnly extends TestBase { ...@@ -45,6 +46,18 @@ public class TestReadOnly extends TestBase {
deleteDb("readonly"); deleteDb("readonly");
} }
private void testReadOnlyTempTableResult() throws SQLException {
deleteDb("readonly");
Connection conn = getConnection("readonly");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)");
conn.close();
conn = getConnection("readonly;ACCESS_MODE_DATA=r;MAX_MEMORY_ROWS_DISTINCT=10");
stat = conn.createStatement();
stat.execute("SELECT DISTINCT ID FROM TEST");
conn.close();
}
private void testReadOnlyDbCreate() throws SQLException { private void testReadOnlyDbCreate() throws SQLException {
deleteDb("readonly"); deleteDb("readonly");
Connection conn = getConnection("readonly"); Connection conn = getConnection("readonly");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论