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

Various system properties have been replaced with database level settings.

上级 85acb30b
......@@ -22,10 +22,24 @@ Change Log
</li><li>When the system property h2.lobInDatabase is set, CREATE TABLE ... AS SELECT
with a LOB column did not always work.
</li><li>Some system properties are not supported any longer, because they can
already be set in the database URL. Those settings are:
h2.cacheSizeDefault, h2.cacheTypeDefault
already be set in the database URL. The constants are:
CACHE_SIZE_DEFAULT, CACHE_TYPE_DEFAULT, DEFAULT_LOCK_MODE,
LOCK_MODE_READ_COMMITTED, DEFAULT_MAX_LENGTH_INPLACE_LOB,
DEFAULT_MAX_LENGTH_INPLACE_LOB2, DEFAULT_MAX_MEMORY_UNDO,
DEFAULT_MAX_OPERATION_MEMORY, DEFAULT_PAGE_SIZE,
DEFAULT_RESULT_SET_CONCURRENCY, MIN_WRITE_DELAY.
</li><li>Various system properties have been replaced with database level settings:
ALIAS_COLUMN_NAME, ANALYZE_AUTO, ANALYZE_SAMPLE, DATABASE_TO_UPPER,...
ALIAS_COLUMN_NAME, ANALYZE_AUTO, ANALYZE_SAMPLE, DATABASE_TO_UPPER,
DEFAULT_ESCAPE, DEFRAG_ALWAYS, DROP_RESTRICT,
ESTIMATED_FUNCTION_TABLE_ROWS, FUNCTIONS_IN_SCHEMA,
LARGE_RESULT_BUFFER_SIZE, LARGE_TRANSACTIONS, MAX_COMPACT_COUNT,
MAX_COMPACT_TIME, MAX_MEMORY_ROWS_DISTINCT, MAX_QUERY_TIMEOUT,
NESTED_JOINS, OPTIMIZE_DISTINCT, OPTIMIZE_EVALUATABLE_SUBQUERIES,
OPTIMIZE_INSERT_FROM_SELECT, OPTIMIZE_IN_LIST, OPTIMIZE_IS_NULL,
OPTIMIZE_OR, OPTIMIZE_SUBQUERY_CACHE, OPTIMIZE_TWO_EQUALS,
OPTIMIZE_UPDATE, PAGE_STORE_INTERNAL_COUNT, PAGE_STORE_TRIM,
QUERY_CACHE_SIZE, RECOMPILE_ALWAYS, RECONNECT_CHECK_DELAY,
SELECT_FOR_UPDATE_MVCC, SHARE_LINKED_CONNECTIONS.
See the Javadoc documentation of DbSettings for details.
The system properties are still supported for backward compatibility.
</li><li>When the system property h2.nestedJoins was enabled, some outer joins returned the wrong result.
......
......@@ -24,7 +24,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
<h2>Version 1.3.x: Planned Changes</h2>
<ul><li>Enable h2.lobInDatabase (store CLOB and BLOB in the database file).
</li><li>Set h2.analyzeAuto to 2000 (automatic ANALYZE).
</li><li>Set AUTO_ANALYZE to 2000 (automatic ANALYZE).
</li><li>Enable h2.functionsInSchema (allow to store functions in a schema).
</li><li>Enable h2.selectForUpdateMvcc (MVCC and SELECT FOR UPDATE).
</li><li>Enable h2.largeTransactions (support for very large transactions).
......@@ -60,6 +60,8 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Access rights: remember the owner of an object. Create, alter and drop privileges. COMMENT: allow owner of object to change it. Issue 208. Access rights for schemas.
</li><li>Test multi-threaded in-memory db access.
</li><li>Support hints for the optimizer (which index to use, enforce the join order).
</li><li>Migrate database tool (also from other database engines). For Oracle, maybe use
DBMS_METADATA.GET_DDL / GET_DEPENDENT_DDL.
</li><li>Full outer joins.
</li><li>Clustering: support mixed clustering mode (one embedded, others in server mode).
</li><li>Clustering: reads should be randomly distributed (optional) or to a designated database on RAM (parameter: READ_FROM=3).
......@@ -70,8 +72,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Deferred integrity checking (DEFERRABLE INITIALLY DEFERRED).
</li><li>Groovy Stored Procedures: http://groovy.codehaus.org/Groovy+SQL
</li><li>Add a migration guide (list differences between databases).
</li><li>Migrate database tool (also from other database engines). For Oracle, maybe use
DBMS_METADATA.GET_DDL / GET_DEPENDENT_DDL.
</li><li>Optimization: automatic index creation suggestion using the trace file?
</li><li>Compression performance: don't allocate buffers, compress / expand in to out buffer.
</li><li>Rebuild index functionality to shrink index size and improve performance.
......
......@@ -1067,7 +1067,7 @@ public class Select extends Query {
public void setForUpdate(boolean b) {
this.isForUpdate = b;
if (SysProperties.SELECT_FOR_UPDATE_MVCC && session.getDatabase().isMultiVersion()) {
if (session.getDatabase().getSettings().selectForUpdateMvcc && session.getDatabase().isMultiVersion()) {
isForUpdateMvcc = b;
}
}
......
......@@ -137,22 +137,6 @@ public class DbSettings extends SettingsBase {
*/
public final int maxMemoryRowsDistinct = get("MAX_MEMORY_ROWS_DISTINCT", Integer.MAX_VALUE);
/**
* Database setting <code>h2.nestedJoins</code> (default: false).<br />
* Whether nested joins should be supported.
*/
public final boolean nestedJoins = get("NESTED_JOINS", false);
/**
* Database setting <code>QUERY_CACHE_SIZE</code> (default: 0).<br />
* The size of the query cache. Each session has it's own cache with the
* given size. The cache is only used if the SQL statement and all
* parameters match. Only the last returned result per query is cached. Only
* SELECT statements are cached (excluding UNION and FOR UPDATE statements).
* This works for both statements and prepared statement.
*/
public final int queryCacheSize = get("QUERY_CACHE_SIZE", 0);
/**
* Database setting <code>MAX_QUERY_TIMEOUT</code> (default: 0).<br />
* The maximum timeout of a query in milliseconds. The default is 0, meaning
......@@ -162,12 +146,10 @@ public class DbSettings extends SettingsBase {
public int maxQueryTimeout = get("MAX_QUERY_TIMEOUT", 0);
/**
* Database setting <code>OPTIMIZE_INSERT_FROM_SELECT</code>
* (default: false).<br />
* Insert into table from query directly bypassing temporary disk storage.
* This also applies to create table as select.
* Database setting <code>h2.nestedJoins</code> (default: false).<br />
* Whether nested joins should be supported.
*/
public final boolean optimizeInsertFromSelect = get("OPTIMIZE_INSERT_FROM_SELECT", false);
public final boolean nestedJoins = get("NESTED_JOINS", false);
/**
* Database setting <code>OPTIMIZE_DISTINCT</code> (default: true).<br />
......@@ -183,13 +165,6 @@ public class DbSettings extends SettingsBase {
*/
public final boolean optimizeDistinct = get("OPTIMIZE_DISTINCT", true);
/**
* Database setting <code>OPTIMIZE_UPDATE</code> (default: true).<br />
* Speed up inserts, updates, and deletes by not reading all rows from a
* page unless necessary.
*/
public final boolean optimizeUpdate = get("OPTIMIZE_UPDATE", true);
/**
* Database setting <code>OPTIMIZE_EVALUATABLE_SUBQUERIES</code> (default:
* true).<br />
......@@ -197,6 +172,14 @@ public class DbSettings extends SettingsBase {
*/
public final boolean optimizeEvaluatableSubqueries = get("OPTIMIZE_EVALUATABLE_SUBQUERIES", true);
/**
* Database setting <code>OPTIMIZE_INSERT_FROM_SELECT</code>
* (default: false).<br />
* Insert into table from query directly bypassing temporary disk storage.
* This also applies to create table as select.
*/
public final boolean optimizeInsertFromSelect = get("OPTIMIZE_INSERT_FROM_SELECT", false);
/**
* Database setting <code>OPTIMIZE_IN_LIST</code> (default: true).<br />
* Optimize IN(...) and IN(SELECT ...) comparisons. This includes
......@@ -230,10 +213,11 @@ public class DbSettings extends SettingsBase {
public final boolean optimizeTwoEquals = get("OPTIMIZE_TWO_EQUALS", true);
/**
* Database setting <code>PAGE_STORE_TRIM</code> (default: true).<br />
* Trim the database size when closing.
* Database setting <code>OPTIMIZE_UPDATE</code> (default: true).<br />
* Speed up inserts, updates, and deletes by not reading all rows from a
* page unless necessary.
*/
public final boolean pageStoreTrim = get("PAGE_STORE_TRIM", true);
public final boolean optimizeUpdate = get("OPTIMIZE_UPDATE", true);
/**
* Database setting <code>PAGE_STORE_INTERNAL_COUNT</code> (default: false).<br />
......@@ -241,12 +225,27 @@ public class DbSettings extends SettingsBase {
*/
public final boolean pageStoreInternalCount = get("PAGE_STORE_INTERNAL_COUNT", false);
/**
* Database setting <code>PAGE_STORE_TRIM</code> (default: true).<br />
* Trim the database size when closing.
*/
public final boolean pageStoreTrim = get("PAGE_STORE_TRIM", true);
/**
* Database setting <code>QUERY_CACHE_SIZE</code> (default: 0).<br />
* The size of the query cache. Each session has it's own cache with the
* given size. The cache is only used if the SQL statement and all
* parameters match. Only the last returned result per query is cached. Only
* SELECT statements are cached (excluding UNION and FOR UPDATE statements).
* This works for both statements and prepared statement.
*/
public final int queryCacheSize = get("QUERY_CACHE_SIZE", 0);
/**
* Database setting <code>RECOMPILE_ALWAYS</code> (default: false).<br />
* Always recompile prepared statements.
*/
public final boolean recompileAlways = get("RECOMPILE_ALWAYS", false);
// DbSettings
/**
* Database setting <code>RECONNECT_CHECK_DELAY</code> (default: 200).<br />
......@@ -256,8 +255,21 @@ public class DbSettings extends SettingsBase {
* milliseconds before updating the database.
*/
public final int reconnectCheckDelay = get("RECONNECT_CHECK_DELAY", 200);
// DbSettings
/**
* Database setting <code>SELECT_FOR_UPDATE_MVCC</code> (default: false).<br />
* If set, SELECT .. FOR UPDATE queries lock only the selected rows when using MVCC.
*/
public final boolean selectForUpdateMvcc = get("SELECT_FOR_UPDATE_MVCC", false);
/**
* Database setting <code>SHARE_LINKED_CONNECTIONS</code>
* (default: true).<br />
* Linked connections should be shared, that means connections to the same
* database should be used for all linked tables that connect to the same
* database.
*/
public final boolean shareLinkedConnections = get("SHARE_LINKED_CONNECTIONS", true);
private DbSettings(HashMap<String, String> s) {
super(s);
......@@ -267,7 +279,7 @@ public class DbSettings extends SettingsBase {
* INTERNAL.
* Get the settings for the given properties (may be null).
*
* @param p the properties
* @param s the settings
* @return the settings
*/
public static DbSettings getInstance(HashMap<String, String> s) {
......
......@@ -6,6 +6,7 @@
*/
package org.h2.constant;
import org.h2.engine.Constants;
import org.h2.message.TraceSystem;
import org.h2.util.MathUtils;
......@@ -198,7 +199,7 @@ public class SysProperties {
* System property <code>h2.lobInDatabase</code> (default: false).<br />
* Store LOB files in the database.
*/
public static final boolean LOB_IN_DATABASE = getBooleanSetting("h2.lobInDatabase", false);
public static final boolean LOB_IN_DATABASE = getBooleanSetting("h2.lobInDatabase", Constants.VERSION_MINOR < 3 ? false : true);
/**
* System property <code>h2.lobClientMaxSizeMemory</code> (default: 65536).<br />
......@@ -313,13 +314,6 @@ public class SysProperties {
*/
public static boolean runFinalize = getBooleanSetting("h2.runFinalize", true);
/**
* System property <code>h2.selectForUpdateMvcc</code> (default: false).<br />
* If set, SELECT .. FOR UPDATE queries lock the rows when using MVCC.
*/
public static final boolean SELECT_FOR_UPDATE_MVCC = getBooleanSetting("h2.selectForUpdateMvcc", false);
// DbSettings
/**
* System property <code>h2.serverCachedObjects</code> (default: 64).<br />
* TCP Server: number of cached objects per session.
......@@ -333,16 +327,6 @@ public class SysProperties {
*/
public static final int SERVER_RESULT_SET_FETCH_SIZE = getIntSetting("h2.serverResultSetFetchSize", 100);
/**
* System property <code>h2.shareLinkedConnections</code>
* (default: true).<br />
* Linked connections should be shared, that means connections to the same
* database should be used for all linked tables that connect to the same
* database.
*/
public static final boolean SHARE_LINKED_CONNECTIONS = getBooleanSetting("h2.shareLinkedConnections", true);
// DbSettings
/**
* System property <code>h2.socketConnectRetry</code> (default: 16).<br />
* The number of times to retry opening a socket. Windows sometimes fails
......
......@@ -1995,7 +1995,7 @@ public class Database implements DataHandler {
if (linkConnections == null) {
linkConnections = New.hashMap();
}
return TableLinkConnection.open(linkConnections, driver, url, user, password);
return TableLinkConnection.open(linkConnections, driver, url, user, password, dbSettings.shareLinkedConnections);
}
public String toString() {
......
......@@ -21,6 +21,13 @@ public class SettingsBase {
this.settings = s;
}
/**
* Get the setting for the given key.
*
* @param key the key
* @param defaultValue the default value
* @return the setting
*/
protected boolean get(String key, boolean defaultValue) {
String s = get(key, "" + defaultValue);
try {
......@@ -30,6 +37,13 @@ public class SettingsBase {
}
}
/**
* Get the setting for the given key.
*
* @param key the key
* @param defaultValue the default value
* @return the setting
*/
protected int get(String key, int defaultValue) {
String s = get(key, "" + defaultValue);
try {
......@@ -39,6 +53,13 @@ public class SettingsBase {
}
}
/**
* Get the setting for the given key.
*
* @param key the key
* @param defaultValue the default value
* @return the setting
*/
protected String get(String key, String defaultValue) {
StringBuilder buff = new StringBuilder("h2.");
boolean nextUpper = false;
......@@ -54,19 +75,27 @@ public class SettingsBase {
String sysProperty = buff.toString();
String v = settings.get(key);
if (v == null) {
v = System.getProperty(sysProperty);
}
if (v == null) {
settings.put(key, defaultValue);
v = defaultValue;
v = System.getProperty(sysProperty, defaultValue);
settings.put(key, v);
}
return v;
}
/**
* Check if the settings contains the given key.
*
* @param k the key
* @return true if they do
*/
public boolean containsKey(String k) {
return settings.containsKey(k);
}
/**
* Get all settings.
*
* @return the settings
*/
public HashMap<String, String> getSettings() {
return settings;
}
......
......@@ -9,12 +9,10 @@ package org.h2.table;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import org.h2.constant.SysProperties;
import org.h2.message.DbException;
import org.h2.util.Utils;
import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
/**
* A connection for a linked table. The same connection may be used for multiple
......@@ -59,11 +57,12 @@ public class TableLinkConnection {
* @param url the database URL
* @param user the user name
* @param password the password
* @param shareLinkedConnections if connections should be shared
* @return a connection
*/
public static TableLinkConnection open(HashMap<TableLinkConnection, TableLinkConnection> map, String driver, String url, String user, String password) {
public static TableLinkConnection open(HashMap<TableLinkConnection, TableLinkConnection> map, String driver, String url, String user, String password, boolean shareLinkedConnections) {
TableLinkConnection t = new TableLinkConnection(map, driver, url, user, password);
if (!SysProperties.SHARE_LINKED_CONNECTIONS) {
if (!shareLinkedConnections) {
t.open();
return t;
}
......
......@@ -15,7 +15,6 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import org.h2.constant.SysProperties;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
import org.h2.util.IOUtils;
......@@ -96,12 +95,12 @@ public class TestLinkedTable extends TestBase {
}
private void testHiddenSQL() throws SQLException {
if (config.memory || !SysProperties.SHARE_LINKED_CONNECTIONS) {
if (config.memory) {
return;
}
org.h2.Driver.load();
deleteDb("linkedTable");
Connection conn = getConnection("linkedTable");
Connection conn = getConnection("linkedTable;SHARE_LINKED_CONNECTIONS=TRUE");
try {
conn.createStatement().execute(
"create linked table test(null, 'jdbc:h2:mem:', 'sa', 'pwd', 'DUAL2')");
......@@ -140,12 +139,12 @@ public class TestLinkedTable extends TestBase {
// }
private void testNestedQueriesToSameTable() throws SQLException {
if (config.memory || !SysProperties.SHARE_LINKED_CONNECTIONS) {
if (config.memory) {
return;
}
org.h2.Driver.load();
deleteDb("linkedTable");
String url = getURL("linkedTable", true);
String url = getURL("linkedTable;SHARE_LINKED_CONNECTIONS=TRUE", true);
String user = getUser();
String password = getPassword();
Connection ca = getConnection(url, user, password);
......@@ -161,12 +160,12 @@ public class TestLinkedTable extends TestBase {
}
private void testSharedConnection() throws SQLException {
if (config.memory || !SysProperties.SHARE_LINKED_CONNECTIONS) {
if (config.memory) {
return;
}
org.h2.Driver.load();
deleteDb("linkedTable");
String url = getURL("linkedTable", true);
String url = getURL("linkedTable;SHARE_LINKED_CONNECTIONS=TRUE", true);
String user = getUser();
String password = getPassword();
Connection ca = getConnection(url, user, password);
......
......@@ -140,6 +140,7 @@ public class TestPowerOff extends TestBase {
}
}
}
SysProperties.runFinalize = true;
}
private void testShutdown() throws SQLException {
......
......@@ -11,7 +11,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.test.TestBase;
/**
......@@ -30,7 +29,6 @@ public class TestMvcc2 extends TestBase {
* @param a ignored
*/
public static void main(String... a) throws Exception {
System.setProperty("h2.selectForUpdateMvcc", "true");
TestBase test = TestBase.createCaller().init();
test.config.mvcc = true;
test.test();
......@@ -134,11 +132,8 @@ public class TestMvcc2 extends TestBase {
}
private void testSelectForUpdate() throws SQLException {
if (!SysProperties.SELECT_FOR_UPDATE_MVCC) {
return;
}
Connection conn = getConnection();
Connection conn2 = getConnection();
Connection conn = getConnection("mvcc2;SELECT_FOR_UPDATE_MVCC=true");
Connection conn2 = getConnection("mvcc2;SELECT_FOR_UPDATE_MVCC=true");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
conn.setAutoCommit(false);
......
......@@ -34,9 +34,9 @@ public class TestOuterJoins extends TestBase {
* @param a ignored
*/
public static void main(String... a) throws Exception {
System.setProperty("h2.nestedJoins", "true");
TestBase test = TestBase.createCaller().init();
test.config.traceTest = true;
test.config.nestedJoins = true;
test.test();
}
......
......@@ -35,15 +35,13 @@ public class TestTempTableCrash {
System.setProperty("h2.delayWrongPasswordMin", "0");
System.setProperty("h2.check2", "false");
System.setProperty("h2.lobInDatabase", "true");
System.setProperty("h2.analyzeAuto", "100");
System.setProperty("h2.pageSize", "64");
RecordingFileSystem.register();
System.setProperty("reopenShift", "4");
TestReopen reopen = new TestReopen();
RecordingFileSystem.setRecorder(reopen);
String url = "jdbc:h2:" + RecordingFileSystem.PREFIX +
"memFS:data;PAGE_SIZE=64";
"memFS:data;PAGE_SIZE=64;ANALYZE_AUTO=100";
// String url = "jdbc:h2:" + RecordingFileSystem.PREFIX +
// "data/test;PAGE_SIZE=64";
......
......@@ -23,20 +23,17 @@ public class TestUndoLogMemory {
* @param args ignored
*/
public static void main(String... args) throws Exception {
System.setProperty("h2.largeTransactions", "true");
new TestUndoLogMemory().test(10, "null");
new TestUndoLogMemory().test(100, "space(100000)");
// new TestUndoLogMemory().test(100000, "null");
// new TestUndoLogMemory().test(1000, "space(100000)");
}
private void test(int count, String defaultValue) throws SQLException {
// -Xmx1m -XX:+HeapDumpOnOutOfMemoryError
DeleteDbFiles.execute("data", "test", true);
Connection conn = DriverManager.getConnection("jdbc:h2:data/test");
Connection conn = DriverManager.getConnection("jdbc:h2:data/test;large_transactions=true");
Statement stat = conn.createStatement();
stat.execute("set cache_size 32");
stat.execute("SET max_operation_memory 100");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论