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

Various system properties have been replaced with database level settings.

上级 8967ca57
......@@ -76,7 +76,6 @@ import org.h2.command.dml.SetTypes;
import org.h2.command.dml.TransactionCommand;
import org.h2.command.dml.Update;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential;
import org.h2.engine.Constants;
import org.h2.engine.Database;
......@@ -970,7 +969,7 @@ public class Parser {
table = TableView.createTempView(s, session.getUser(), alias, query, currentSelect);
} else {
TableFilter top;
if (SysProperties.NESTED_JOINS) {
if (database.getSettings().nestedJoins) {
String joinTable = Constants.PREFIX_JOIN + parseIndex;
top = new TableFilter(session, getDualTable(true), joinTable, rightsChecked, currentSelect);
TableFilter n = readTableFilter(false);
......@@ -1234,6 +1233,7 @@ public class Parser {
private TableFilter readJoin(TableFilter top, Select command, boolean fromOuter) {
TableFilter last = top;
boolean nestedJoins = database.getSettings().nestedJoins;
while (true) {
if (readIf("RIGHT")) {
readIf("OUTER");
......@@ -1245,7 +1245,7 @@ public class Parser {
if (readIf("ON")) {
on = readExpression();
}
if (SysProperties.NESTED_JOINS) {
if (nestedJoins) {
String joinTable = Constants.PREFIX_JOIN + parseIndex;
TableFilter nt = new TableFilter(session, getDualTable(true), joinTable, rightsChecked, currentSelect);
nt.addJoin(top, false, true, null);
......@@ -1276,7 +1276,7 @@ public class Parser {
if (readIf("ON")) {
on = readExpression();
}
if (SysProperties.NESTED_JOINS) {
if (nestedJoins) {
top.addJoin(join, false, false, on);
} else {
top.addJoin(join, fromOuter, false, on);
......@@ -1289,7 +1289,7 @@ public class Parser {
if (readIf("ON")) {
on = readExpression();
}
if (SysProperties.NESTED_JOINS) {
if (nestedJoins) {
top.addJoin(join, false, false, on);
} else {
top.addJoin(join, fromOuter, false, on);
......@@ -1298,7 +1298,7 @@ public class Parser {
} else if (readIf("CROSS")) {
read("JOIN");
TableFilter join = readTableFilter(fromOuter);
if (SysProperties.NESTED_JOINS) {
if (nestedJoins) {
top.addJoin(join, false, false, null);
} else {
top.addJoin(join, fromOuter, false, null);
......@@ -1331,7 +1331,7 @@ public class Parser {
}
}
}
if (SysProperties.NESTED_JOINS) {
if (nestedJoins) {
top.addJoin(join, false, false, on);
} else {
top.addJoin(join, fromOuter, false, on);
......
......@@ -8,7 +8,6 @@ package org.h2.command;
import java.util.ArrayList;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
......@@ -110,7 +109,7 @@ public abstract class Prepared {
}
// parser: currently, compiling every create/drop/... twice
// because needRecompile return true even for the first execution
return SysProperties.RECOMPILE_ALWAYS || prepareAlways || modificationMetaId < db.getModificationMetaId();
return prepareAlways || modificationMetaId < db.getModificationMetaId() || db.getSettings().recompileAlways;
}
/**
......
......@@ -548,7 +548,7 @@ public class Select extends Query {
}
int columnCount = expressions.size();
LocalResult result = null;
if (!SysProperties.optimizeInsertFromSelect || target == null) {
if (target == null || !session.getDatabase().getSettings().optimizeInsertFromSelect) {
result = createLocalResult(result);
}
if (sort != null && (!sortUsingIndex || distinct)) {
......@@ -795,7 +795,7 @@ public class Select extends Query {
}
}
cost = preparePlan();
if (SysProperties.OPTIMIZE_DISTINCT && distinct && !isGroupQuery && filters.size() == 1 && expressions.size() == 1 && condition == null) {
if (distinct && session.getDatabase().getSettings().optimizeDistinct && !isGroupQuery && filters.size() == 1 && expressions.size() == 1 && condition == null) {
Expression expr = expressions.get(0);
expr = expr.getNonAliasExpression();
if (expr instanceof ExpressionColumn) {
......@@ -910,7 +910,7 @@ public class Select extends Query {
Expression on = f.getJoinCondition();
if (on != null) {
if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
if (SysProperties.NESTED_JOINS) {
if (session.getDatabase().getSettings().nestedJoins) {
// need to check that all added are bound to a table
on = on.optimize(session);
if (!f.isJoinOuter() && !f.isJoinOuterIndirect()) {
......@@ -1177,7 +1177,7 @@ public class Select extends Query {
break;
}
case ExpressionVisitor.EVALUATABLE: {
if (!SysProperties.OPTIMIZE_EVALUATABLE_SUBQUERIES) {
if (!session.getDatabase().getSettings().optimizeEvaluatableSubqueries) {
return false;
}
break;
......
......@@ -126,7 +126,7 @@ public class SelectUnion extends Query {
}
limitExpr = ValueExpression.get(ValueInt.get(maxrows));
}
if (SysProperties.optimizeInsertFromSelect) {
if (session.getDatabase().getSettings().optimizeInsertFromSelect) {
if (unionType == UNION_ALL && target != null) {
if (sort == null && !distinct && maxrows == 0 && offsetExpr == null && limitExpr == null) {
left.query(0, target);
......
......@@ -103,18 +103,46 @@ public class DbSettings extends SettingsBase {
public final boolean functionsInSchema = get("FUNCTIONS_IN_SCHEMA", false);
/**
* System property <code>h2.largeResultBufferSize</code> (default: 4096).<br />
* Database setting <code>LARGE_RESULT_BUFFER_SIZE</code> (default: 4096).<br />
* Buffer size for large result sets. Set this value to 0 to disable the
* buffer.
*/
public final int largeResultBufferSize = get("LARGE_RESULT_BUFFER_SIZE", 4 * 1024);
/**
* System property <code>h2.largeTransactions</code> (default: false).<br />
* Database setting <code>LARGE_TRANSACTIONS</code> (default: false).<br />
* Support very large transactions
*/
public final boolean largeTransactions = get("LARGE_TRANSACTIONS", false);
/**
* Database setting <code>MAX_COMPACT_COUNT</code>
* (default: Integer.MAX_VALUE).<br />
* The maximum number of pages to move when closing a database.
*/
public final int maxCompactCount = get("MAX_COMPACT_COUNT", Integer.MAX_VALUE);
/**
* Database setting <code>MAX_COMPACT_TIME</code> (default: 200).<br />
* The maximum time in milliseconds used to compact a database when closing.
*/
public final int maxCompactTime = get("MAX_COMPACT_TIME", 200);
/**
* Database setting <code>MAX_MEMORY_ROWS_DISTINCT</code> (default:
* Integer.MAX_VALUE).<br />
* The maximum number of rows kept in-memory for SELECT DISTINCT queries. If
* more than this number of rows are in a result set, a temporary table is
* used.
*/
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
......@@ -133,6 +161,104 @@ 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.
*/
public final boolean optimizeInsertFromSelect = get("OPTIMIZE_INSERT_FROM_SELECT", false);
/**
* Database setting <code>OPTIMIZE_DISTINCT</code> (default: true).<br />
* Improve the performance of simple DISTINCT queries if an index is
* available for the given column. The optimization is used if:
* <ul>
* <li>The select is a single column query without condition </li>
* <li>The query contains only one table, and no group by </li>
* <li>There is only one table involved </li>
* <li>There is an ascending index on the column </li>
* <li>The selectivity of the column is below 20 </li>
* </ul>
*/
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 />
* Optimize subqueries that are not dependent on the outer query.
*/
public final boolean optimizeEvaluatableSubqueries = get("OPTIMIZE_EVALUATABLE_SUBQUERIES", true);
/**
* Database setting <code>OPTIMIZE_IN_LIST</code> (default: true).<br />
* Optimize IN(...) and IN(SELECT ...) comparisons. This includes
* optimization for SELECT, DELETE, and UPDATE.
*/
public final boolean optimizeInList = get("OPTIMIZE_IN_LIST", true);
/**
* Database setting <code>OPTIMIZE_IS_NULL</code> (default: false).<br />
* Use an index for condition of the form columnName IS NULL.
*/
public final boolean optimizeIsNull = get("OPTIMIZE_IS_NULL", true);
/**
* Database setting <code>OPTIMIZE_OR</code> (default: false).<br />
* Convert (C=? OR C=?) to (C IN(?, ?)).
*/
public final boolean optimizeOr = get("OPTIMIZE_OR", false);
/**
* Database setting <code>OPTIMIZE_SUBQUERY_CACHE</code> (default: true).<br />
* Cache subquery results.
*/
public final boolean optimizeSubqueryCache = get("OPTIMIZE_SUBQUERY_CACHE", true);
/**
* Database setting <code>OPTIMIZE_TWO_EQUALS</code> (default: true).<br />
* Optimize expressions of the form A=B AND B=1. In this case, AND A=1 is
* added so an index on A can be used.
*/
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.
*/
public final boolean pageStoreTrim = get("PAGE_STORE_TRIM", true);
/**
* Database setting <code>PAGE_STORE_INTERNAL_COUNT</code> (default: false).<br />
* Update the row counts on a node level.
*/
public final boolean pageStoreInternalCount = get("PAGE_STORE_INTERNAL_COUNT", false);
/**
* 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 />
* Check the .lock.db file every this many milliseconds to detect that the
* database was changed. The process writing to the database must first
* notify a change in the .lock.db file, then wait twice this many
* milliseconds before updating the database.
*/
public final int reconnectCheckDelay = get("RECONNECT_CHECK_DELAY", 200);
// DbSettings
private DbSettings(HashMap<String, String> s) {
super(s);
}
......
......@@ -37,12 +37,6 @@ public class SysProperties {
*/
public static final String H2_SCRIPT_DIRECTORY = "h2.scriptDirectory";
/**
* INTERNAL
*/
public static final String H2_COLLATOR_CACHE_SIZE = "h2.collatorCacheSize";
// TODO DbSettings
/**
* System property <code>file.encoding</code> (default: Cp1252).<br />
* It is usually set by the system and is the default encoding used for the
......@@ -143,6 +137,13 @@ public class SysProperties {
*/
public static final String CLIENT_TRACE_DIRECTORY = getStringSetting("h2.clientTraceDirectory", "trace.db/");
/**
* System property <code>h2.collatorCacheSize</code> (default: 32000).<br />
* The cache size for collation keys (in elements). Used when a collator has
* been set for the database.
*/
public static final int COLLATOR_CACHE_SIZE = getIntSetting("h2.collatorCacheSize", 32000);
/**
* System property <code>h2.consoleStream</code> (default: true).<br />
* H2 Console: stream query results.
......@@ -198,7 +199,6 @@ public class SysProperties {
* Store LOB files in the database.
*/
public static final boolean LOB_IN_DATABASE = getBooleanSetting("h2.lobInDatabase", false);
// DbSettings
/**
* System property <code>h2.lobClientMaxSizeMemory</code> (default: 65536).<br />
......@@ -220,21 +220,6 @@ public class SysProperties {
*/
public static final String LOG_ALL_ERRORS_FILE = getStringSetting("h2.logAllErrorsFile", "h2errors.txt");
/**
* System property <code>h2.maxCompactCount</code>
* (default: Integer.MAX_VALUE).<br />
* The maximum number of pages to move when closing a database.
*/
public static final int MAX_COMPACT_COUNT = getIntSetting("h2.maxCompactCount", Integer.MAX_VALUE);
// DbSettings
/**
* System property <code>h2.maxCompactTime</code> (default: 200).<br />
* The maximum time in milliseconds used to compact a database when closing.
*/
public static final int MAX_COMPACT_TIME = getIntSetting("h2.maxCompactTime", 200);
// DbSettings
/**
* System property <code>h2.maxFileRetry</code> (default: 16).<br />
* Number of times to retry file delete and rename. in Windows, files can't
......@@ -245,16 +230,6 @@ public class SysProperties {
*/
public static final int MAX_FILE_RETRY = Math.max(1, getIntSetting("h2.maxFileRetry", 16));
/**
* System property <code>h2.maxMemoryRowsDistinct</code> (default:
* Integer.MAX_VALUE).<br />
* The maximum number of rows kept in-memory for SELECT DISTINCT queries. If
* more than this number of rows are in a result set, a temporary table is
* used.
*/
public static final int MAX_MEMORY_ROWS_DISTINCT = getIntSetting("h2.maxMemoryRowsDistinct", Integer.MAX_VALUE);
// DbSettings
/**
* System property <code>h2.maxReconnect</code> (default: 3).<br />
* The maximum number of tries to reconnect in a row.
......@@ -266,7 +241,6 @@ public class SysProperties {
* The maximum size of a LOB value that is written as data to the trace system.
*/
public static final long MAX_TRACE_DATA_LENGTH = getIntSetting("h2.maxTraceDataLength", 65535);
// DbSettings
/**
* System property <code>h2.minColumnNameMap</code> (default: 3).<br />
......@@ -275,20 +249,6 @@ public class SysProperties {
*/
public static final int MIN_COLUMN_NAME_MAP = getIntSetting("h2.minColumnNameMap", 3);
/**
* System property <code>h2.minWriteDelay</code> (default: 5).<br />
* The minimum write delay that causes commits to be delayed.
*/
public static final int MIN_WRITE_DELAY = getIntSetting("h2.minWriteDelay", 5);
// DbSettings
/**
* System property <code>h2.nestedJoins</code> (default: false).<br />
* Whether nested joins should be supported.
*/
public static final boolean NESTED_JOINS = getBooleanSetting("h2.nestedJoins", false);
// DbSettings
/**
* System property <code>h2.nioLoadMapped</code> (default: false).<br />
* If the mapped buffer should be loaded when the file is opened.
......@@ -326,104 +286,6 @@ public class SysProperties {
*/
public static final int OBJECT_CACHE_SIZE = MathUtils.nextPowerOf2(getIntSetting("h2.objectCacheSize", 1024));
/**
* System property <code>h2.optimizeInsertFromSelect</code>
* (default: false).<br />
* Insert into table from query directly bypassing temporary disk storage.
* This also applies to create table as select.
*/
public static boolean optimizeInsertFromSelect = getBooleanSetting("h2.optimizeInsertFromSelect", false);
// DbSettings
/**
* System property <code>h2.optimizeDistinct</code> (default: true).<br />
* Improve the performance of simple DISTINCT queries if an index is
* available for the given column. The optimization is used if:
* <ul>
* <li>The select is a single column query without condition </li>
* <li>The query contains only one table, and no group by </li>
* <li>There is only one table involved </li>
* <li>There is an ascending index on the column </li>
* <li>The selectivity of the column is below 20 </li>
* </ul>
*/
public static final boolean OPTIMIZE_DISTINCT = getBooleanSetting("h2.optimizeDistinct", true);
// DbSettings
/**
* System property <code>h2.optimizeUpdate</code> (default: true).<br />
* Speed up inserts, updates, and deletes by not reading all rows from a
* page unless necessary.
*/
public static final boolean OPTIMIZE_UPDATE = getBooleanSetting("h2.optimizeUpdate", true);
// DbSettings
/**
* System property <code>h2.optimizeEvaluatableSubqueries</code> (default:
* true).<br />
* Optimize subqueries that are not dependent on the outer query.
*/
public static final boolean OPTIMIZE_EVALUATABLE_SUBQUERIES = getBooleanSetting("h2.optimizeEvaluatableSubqueries", true);
// DbSettings
/**
* System property <code>h2.optimizeInList</code> (default: true).<br />
* Optimize IN(...) and IN(SELECT ...) comparisons. This includes
* optimization for SELECT, DELETE, and UPDATE.
*/
public static final boolean OPTIMIZE_IN_LIST = getBooleanSetting("h2.optimizeInList", true);
// DbSettings
/**
* System property <code>h2.optimizeIsNull</code> (default: false).<br />
* Use an index for condition of the form columnName IS NULL.
*/
public static final boolean OPTIMIZE_IS_NULL = getBooleanSetting("h2.optimizeIsNull", true);
// DbSettings
/**
* System property <code>h2.optimizeOr</code> (default: false).<br />
* Convert (C=? OR C=?) to (C IN(?, ?)).
*/
public static final boolean OPTIMIZE_OR = getBooleanSetting("h2.optimizeOr", false);
// DbSettings
/**
* System property <code>h2.optimizeSubqueryCache</code> (default: true).<br />
* Cache subquery results.
*/
public static final boolean OPTIMIZE_SUBQUERY_CACHE = getBooleanSetting("h2.optimizeSubqueryCache", true);
// DbSettings
/**
* System property <code>h2.optimizeTwoEquals</code> (default: true).<br />
* Optimize expressions of the form A=B AND B=1. In this case, AND A=1 is
* added so an index on A can be used.
*/
public static final boolean OPTIMIZE_TWO_EQUALS = getBooleanSetting("h2.optimizeTwoEquals", true);
// DbSettings
/**
* System property <code>h2.pageSize</code> (default: 2048).<br />
* The page size to use for new databases.
*/
public static final int PAGE_SIZE = getIntSetting("h2.pageSize", 2048);
// DbSettings (already!)
/**
* System property <code>h2.pageStoreTrim</code> (default: true).<br />
* Trim the database size when closing.
*/
public static final boolean PAGE_STORE_TRIM = getBooleanSetting("h2.pageStoreTrim", true);
// DbSettings
/**
* System property <code>h2.pageStoreInternalCount</code> (default: false).<br />
* Update the row counts on a node level.
*/
public static final boolean PAGE_STORE_INTERNAL_COUNT = getBooleanSetting("h2.pageStoreInternalCount", false);
// DbSettings
/**
* System property <code>h2.pgClientEncoding</code> (default: UTF-8).<br />
* Default client encoding for PG server. It is used if the client does not
......@@ -437,23 +299,6 @@ public class SysProperties {
*/
public static final String PREFIX_TEMP_FILE = getStringSetting("h2.prefixTempFile", "h2.temp");
/**
* System property <code>h2.recompileAlways</code> (default: false).<br />
* Always recompile prepared statements.
*/
public static final boolean RECOMPILE_ALWAYS = getBooleanSetting("h2.recompileAlways", false);
// DbSettings
/**
* System property <code>h2.reconnectCheckDelay</code> (default: 200).<br />
* Check the .lock.db file every this many milliseconds to detect that the
* database was changed. The process writing to the database must first
* notify a change in the .lock.db file, then wait twice this many
* milliseconds before updating the database.
*/
public static final int RECONNECT_CHECK_DELAY = getIntSetting("h2.reconnectCheckDelay", 200);
// DbSettings
/**
* System property <code>h2.returnLobObjects</code> (default: true).<br />
* When true, ResultSet.getObject for CLOB or BLOB will return a
......@@ -632,15 +477,4 @@ public class SysProperties {
return getStringSetting(H2_SCRIPT_DIRECTORY, "");
}
/**
* System property <code>h2.collatorCacheSize</code> (default: 32000).<br />
* The cache size for collation keys (in elements). Used when a collator has
* been set for the database.
*
* @return the current value
*/
public static int getCollatorCacheSize() {
return getIntSetting(H2_COLLATOR_CACHE_SIZE, 32000);
}
}
......@@ -400,7 +400,17 @@ public class Constants {
*/
public static final String USER_PACKAGE = "org.h2.dynamic";
int sortByName;
int sortByNameAndDocument;
/**
* The default page size to use for new databases.
*/
public static final int DEFAULT_PAGE_SIZE = 2048;
/**
* The minimum write delay that causes commits to be delayed.
*/
public static final int MIN_WRITE_DELAY = 5;
/**
* The default result set concurrency for statements created with
......
......@@ -167,13 +167,15 @@ public class Database implements DataHandler {
private volatile boolean metaTablesInitialized;
private boolean flushOnEachCommit;
private LobStorage lobStorage;
private int pageSize = SysProperties.PAGE_SIZE;
private int pageSize = Constants.DEFAULT_PAGE_SIZE;
private int defaultTableType = Table.TYPE_CACHED;
private DbSettings dbSettings;
private final DbSettings dbSettings;
private final int reconnectCheckDelay;
public Database(ConnectionInfo ci, String cipher) {
String name = ci.getName();
this.dbSettings = ci.getDbSettings();
this.reconnectCheckDelay = dbSettings.reconnectCheckDelay;
this.compareMode = CompareMode.getInstance(null, 0);
this.persistent = ci.isPersistent();
this.filePasswordHash = ci.getFilePasswordHash();
......@@ -186,7 +188,7 @@ public class Database implements DataHandler {
this.accessModeData = ci.getProperty("ACCESS_MODE_DATA", "rw").toLowerCase();
this.autoServerMode = ci.getProperty("AUTO_SERVER", false);
this.cacheSize = ci.getProperty("CACHE_SIZE", Constants.CACHE_SIZE_DEFAULT);
this.pageSize = ci.getProperty("PAGE_SIZE", SysProperties.PAGE_SIZE);
this.pageSize = ci.getProperty("PAGE_SIZE", Constants.DEFAULT_PAGE_SIZE);
if ("r".equals(accessModeData)) {
readOnly = true;
}
......@@ -315,7 +317,7 @@ public class Database implements DataHandler {
lock.setProperty("logPos", pos);
lock.save();
}
reconnectCheckNext = now + SysProperties.RECONNECT_CHECK_DELAY;
reconnectCheckNext = now + reconnectCheckDelay;
}
return true;
}
......@@ -325,7 +327,7 @@ public class Database implements DataHandler {
return false;
}
getTrace().debug("wait before writing");
Thread.sleep((int) (SysProperties.RECONNECT_CHECK_DELAY * 1.1));
Thread.sleep((int) (reconnectCheckDelay * 1.1));
Properties now = lock.load();
if (!now.equals(old)) {
// somebody else was faster
......@@ -341,11 +343,11 @@ public class Database implements DataHandler {
}
// ensure that the writer thread will
// not reset the flag before we are done
reconnectCheckNext = System.currentTimeMillis() + 2 * SysProperties.RECONNECT_CHECK_DELAY;
reconnectCheckNext = System.currentTimeMillis() + 2 * reconnectCheckDelay;
old = lock.save();
if (pending) {
getTrace().debug("wait before writing again");
Thread.sleep((int) (SysProperties.RECONNECT_CHECK_DELAY * 1.1));
Thread.sleep((int) (reconnectCheckDelay * 1.1));
Properties now = lock.load();
if (!now.equals(old)) {
// somebody else was faster
......@@ -356,7 +358,7 @@ public class Database implements DataHandler {
}
reconnectLastLock = old;
reconnectChangePending = pending;
reconnectCheckNext = System.currentTimeMillis() + SysProperties.RECONNECT_CHECK_DELAY;
reconnectCheckNext = System.currentTimeMillis() + reconnectCheckDelay;
return true;
} catch (Exception e) {
getTrace().error("pending:"+ pending, e);
......@@ -1146,7 +1148,7 @@ public class Database implements DataHandler {
// wait before deleting the .lock file,
// otherwise other connections can not detect that
try {
Thread.sleep((int) (SysProperties.RECONNECT_CHECK_DELAY * 1.1));
Thread.sleep((int) (reconnectCheckDelay * 1.1));
} catch (InterruptedException e) {
traceSystem.getTrace(Trace.DATABASE).error("close", e);
}
......@@ -1623,7 +1625,7 @@ public class Database implements DataHandler {
if (writer != null) {
writer.setWriteDelay(value);
// TODO check if MIN_WRITE_DELAY is a good value
flushOnEachCommit = writeDelay < SysProperties.MIN_WRITE_DELAY;
flushOnEachCommit = writeDelay < Constants.MIN_WRITE_DELAY;
}
}
......@@ -2024,7 +2026,7 @@ public class Database implements DataHandler {
public PageStore getPageStore() {
if (pageStore == null) {
pageStore = new PageStore(this, databaseName + Constants.SUFFIX_PAGE_FILE, accessModeData, cacheSize);
if (pageSize != SysProperties.PAGE_SIZE) {
if (pageSize != Constants.DEFAULT_PAGE_SIZE) {
pageStore.setPageSize(pageSize);
}
if (!readOnly && fileLockMethod == FileLock.LOCK_FS) {
......@@ -2072,7 +2074,7 @@ public class Database implements DataHandler {
if (now < reconnectCheckNext) {
return false;
}
reconnectCheckNext = now + SysProperties.RECONNECT_CHECK_DELAY;
reconnectCheckNext = now + reconnectCheckDelay;
if (lock == null) {
lock = new FileLock(traceSystem, databaseName + Constants.SUFFIX_LOCK_FILE, Constants.LOCK_SLEEP);
}
......@@ -2085,7 +2087,7 @@ public class Database implements DataHandler {
if (prop.getProperty("changePending", null) == null) {
break;
}
if (System.currentTimeMillis() > now + SysProperties.RECONNECT_CHECK_DELAY * 10) {
if (System.currentTimeMillis() > now + reconnectCheckDelay * 10) {
if (first.equals(prop)) {
// the writing process didn't update the file -
// it may have terminated
......@@ -2095,7 +2097,7 @@ public class Database implements DataHandler {
}
}
getTrace().debug("delay (change pending)");
Thread.sleep(SysProperties.RECONNECT_CHECK_DELAY);
Thread.sleep(reconnectCheckDelay);
prop = lock.load();
}
reconnectLastLock = prop;
......@@ -2118,7 +2120,7 @@ public class Database implements DataHandler {
return;
}
long now = System.currentTimeMillis();
if (now > reconnectCheckNext + SysProperties.RECONNECT_CHECK_DELAY) {
if (now > reconnectCheckNext + reconnectCheckDelay) {
if (SysProperties.CHECK && checkpointAllowed < 0) {
DbException.throwInternalError();
}
......
......@@ -162,10 +162,10 @@ public class UndoLog {
file = database.openFile(fileName, "rw", false);
file.setLength(FileStore.HEADER_LENGTH);
}
Data buff = Data.create(database, SysProperties.PAGE_SIZE);
Data buff = Data.create(database, Constants.DEFAULT_PAGE_SIZE);
for (int i = 0; i < records.size(); i++) {
UndoLogRecord r = records.get(i);
buff.checkCapacity(SysProperties.PAGE_SIZE);
buff.checkCapacity(Constants.DEFAULT_PAGE_SIZE);
r.append(buff, this);
if (i == records.size() - 1 || buff.length() > Constants.UNDO_BLOCK_SIZE) {
storedEntriesPos.add(file.getFilePointer());
......@@ -188,7 +188,7 @@ public class UndoLog {
String fileName = database.createTempFile();
file = database.openFile(fileName, "rw", false);
file.seek(FileStore.HEADER_LENGTH);
rowBuff = Data.create(database, SysProperties.PAGE_SIZE);
rowBuff = Data.create(database, Constants.DEFAULT_PAGE_SIZE);
Data buff = rowBuff;
for (int i = 0; i < records.size(); i++) {
UndoLogRecord r = records.get(i);
......
......@@ -334,7 +334,7 @@ public class Comparison extends Condition {
if (l != null) {
switch (compareType) {
case IS_NULL:
if (SysProperties.OPTIMIZE_IS_NULL) {
if (session.getDatabase().getSettings().optimizeIsNull) {
filter.addIndexCondition(IndexCondition.get(Comparison.EQUAL_NULL_SAFE, l, ValueExpression.getNull()));
}
}
......
......@@ -137,7 +137,7 @@ public class ConditionAndOr extends Condition {
// INSERT INTO TEST VALUES(1, NULL);
// SELECT * FROM TEST WHERE NOT (B=A AND B=0); // no rows
// SELECT * FROM TEST WHERE NOT (B=A AND B=0 AND A=0); // 1, NULL
if (SysProperties.OPTIMIZE_TWO_EQUALS && andOrType == AND) {
if (session.getDatabase().getSettings().optimizeTwoEquals && andOrType == AND) {
// try to add conditions (A=B AND B=1: add A=1)
if (left instanceof Comparison && right instanceof Comparison) {
Comparison compLeft = (Comparison) left;
......@@ -152,7 +152,7 @@ public class ConditionAndOr extends Condition {
}
// TODO optimization: convert ((A=1 AND B=2) OR (A=1 AND B=3)) to
// (A=1 AND (B=2 OR B=3))
if (SysProperties.OPTIMIZE_OR && andOrType == OR) {
if (andOrType == OR && session.getDatabase().getSettings().optimizeOr) {
// try to add conditions (A=B AND B=1: add A=1)
if (left instanceof Comparison && right instanceof Comparison) {
Comparison compLeft = (Comparison) left;
......
......@@ -7,7 +7,6 @@
package org.h2.expression;
import java.util.ArrayList;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.index.IndexCondition;
......@@ -110,7 +109,7 @@ public class ConditionIn extends Condition {
if (filter != l.getTableFilter()) {
return;
}
if (SysProperties.OPTIMIZE_IN_LIST) {
if (session.getDatabase().getSettings().optimizeInList) {
ExpressionVisitor visitor = ExpressionVisitor.get(ExpressionVisitor.NOT_FROM_RESOLVER);
visitor.setResolver(filter);
for (Expression e : valueList) {
......
......@@ -8,7 +8,6 @@ package org.h2.expression;
import org.h2.command.dml.Query;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.index.IndexCondition;
......@@ -121,7 +120,7 @@ public class ConditionInSelect extends Condition {
}
public void createIndexConditions(Session session, TableFilter filter) {
if (!SysProperties.OPTIMIZE_IN_LIST) {
if (!session.getDatabase().getSettings().optimizeInList) {
return;
}
if (!(left instanceof ExpressionColumn)) {
......
......@@ -11,7 +11,6 @@ import org.h2.command.Parser;
import org.h2.command.dml.Select;
import org.h2.command.dml.SelectListColumnResolver;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.index.IndexCondition;
......@@ -245,7 +244,7 @@ public class ExpressionColumn extends Expression {
// if the current value is known (evaluatable set)
// or if this columns belongs to a 'higher level' query and is
// therefore just a parameter
if (SysProperties.NESTED_JOINS) {
if (database.getSettings().nestedJoins) {
if (visitor.getQueryLevel() < this.queryLevel) {
return true;
}
......
......@@ -8,8 +8,6 @@ package org.h2.index;
import java.util.ArrayList;
import java.util.HashSet;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
import org.h2.expression.Comparison;
import org.h2.message.DbException;
......@@ -121,7 +119,7 @@ public class IndexCursor implements Cursor {
inList = null;
inResult = null;
}
if (!SysProperties.OPTIMIZE_IS_NULL) {
if (!session.getDatabase().getSettings().optimizeIsNull) {
if (isStart && isEnd) {
if (v == ValueNull.INSTANCE) {
// join on a column=NULL is always false
......@@ -172,7 +170,7 @@ public class IndexCursor implements Cursor {
} else if (b == null) {
return a;
}
if (SysProperties.OPTIMIZE_IS_NULL) {
if (session.getDatabase().getSettings().optimizeIsNull) {
// IS NULL must be checked later
if (a == ValueNull.INSTANCE) {
return b;
......@@ -184,8 +182,8 @@ public class IndexCursor implements Cursor {
if (comp == 0) {
return a;
}
if (SysProperties.OPTIMIZE_IS_NULL) {
if (a == ValueNull.INSTANCE || b == ValueNull.INSTANCE) {
if (a == ValueNull.INSTANCE || b == ValueNull.INSTANCE) {
if (session.getDatabase().getSettings().optimizeIsNull) {
// column IS NULL AND column <op> <not null> is always false
return null;
}
......
......@@ -33,10 +33,12 @@ public class PageBtreeLeaf extends PageBtree {
private static final int OFFSET_LENGTH = 2;
private final boolean optimizeUpdate;
private boolean writtenData;
private PageBtreeLeaf(PageBtreeIndex index, int pageId, Data data) {
super(index, pageId, data);
this.optimizeUpdate = index.getDatabase().getSettings().optimizeUpdate;
}
/**
......@@ -130,7 +132,7 @@ public class PageBtreeLeaf extends PageBtree {
}
}
index.getPageStore().logUndo(this, data);
if (!SysProperties.OPTIMIZE_UPDATE) {
if (!optimizeUpdate) {
readAllRows();
}
changeCount = index.getPageStore().getChangeCount();
......@@ -143,7 +145,7 @@ public class PageBtreeLeaf extends PageBtree {
}
start += OFFSET_LENGTH;
int offset = (x == 0 ? pageSize : offsets[x - 1]) - rowLength;
if (SysProperties.OPTIMIZE_UPDATE && writtenData) {
if (optimizeUpdate && writtenData) {
if (entryCount > 0) {
byte[] d = data.getBytes();
int dataStart = offsets[entryCount - 1];
......@@ -162,7 +164,7 @@ public class PageBtreeLeaf extends PageBtree {
}
private void removeRow(int at) {
if (!SysProperties.OPTIMIZE_UPDATE) {
if (!optimizeUpdate) {
readAllRows();
}
index.getPageStore().logUndo(this, data);
......@@ -176,7 +178,7 @@ public class PageBtreeLeaf extends PageBtree {
int rowLength = startNext - offsets[at];
start -= OFFSET_LENGTH;
if (SysProperties.OPTIMIZE_UPDATE) {
if (optimizeUpdate) {
if (writtenData) {
byte[] d = data.getBytes();
int dataStart = offsets[entryCount];
......@@ -265,14 +267,14 @@ public class PageBtreeLeaf extends PageBtree {
if (written) {
return;
}
if (!SysProperties.OPTIMIZE_UPDATE) {
if (!optimizeUpdate) {
readAllRows();
}
writeHead();
for (int i = 0; i < entryCount; i++) {
data.writeShortInt(offsets[i]);
}
if (!writtenData || !SysProperties.OPTIMIZE_UPDATE) {
if (!writtenData || !optimizeUpdate) {
for (int i = 0; i < entryCount; i++) {
index.writeRow(data, offsets[i], rows[i], onlyPosition);
}
......
......@@ -37,6 +37,8 @@ public class PageBtreeNode extends PageBtree {
private static final int CHILD_OFFSET_PAIR_LENGTH = 6;
private static final int MAX_KEY_LENGTH = 10;
private final boolean pageStoreInternalCount;
/**
* The page ids of the children.
*/
......@@ -48,6 +50,7 @@ public class PageBtreeNode extends PageBtree {
private PageBtreeNode(PageBtreeIndex index, int pageId, Data data) {
super(index, pageId, data);
this.pageStoreInternalCount = index.getDatabase().getSettings().pageStoreInternalCount;
}
/**
......@@ -80,7 +83,7 @@ public class PageBtreeNode extends PageBtree {
// 4 bytes for the rightmost child page id
p.start = p.data.length() + 4;
p.rows = SearchRow.EMPTY_ARRAY;
if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
if (p.pageStoreInternalCount) {
p.rowCount = 0;
}
return p;
......@@ -180,7 +183,7 @@ public class PageBtreeNode extends PageBtree {
add(offsets, x + 1, entryCount + 1, -rowLength);
childPageIds = insert(childPageIds, entryCount + 1, x + 1, childPageId);
start += CHILD_OFFSET_PAIR_LENGTH;
if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
if (pageStoreInternalCount) {
if (rowCount != UNKNOWN_ROWCOUNT) {
rowCount += offset;
}
......@@ -278,7 +281,7 @@ public class PageBtreeNode extends PageBtree {
rows = SearchRow.EMPTY_ARRAY;
offsets = Utils.EMPTY_INT_ARRAY;
addChild(0, page2.getPos(), pivot);
if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
if (pageStoreInternalCount) {
rowCount = page1.getRowCount() + page2.getRowCount();
}
check();
......@@ -375,7 +378,7 @@ public class PageBtreeNode extends PageBtree {
}
void setRowCountStored(int rowCount) {
if (rowCount < 0 && SysProperties.PAGE_STORE_INTERNAL_COUNT) {
if (rowCount < 0 && pageStoreInternalCount) {
return;
}
this.rowCount = rowCount;
......@@ -446,7 +449,7 @@ public class PageBtreeNode extends PageBtree {
private void removeChild(int i) {
readAllRows();
entryCount--;
if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
if (pageStoreInternalCount) {
updateRowCount(-index.getPage(childPageIds[i]).getRowCount());
}
written = false;
......
......@@ -34,6 +34,8 @@ import org.h2.store.PageStore;
*/
public class PageDataLeaf extends PageData {
private final boolean optimizeUpdate;
/**
* The row offsets.
*/
......@@ -72,6 +74,7 @@ public class PageDataLeaf extends PageData {
private PageDataLeaf(PageDataIndex index, int pageId, Data data) {
super(index, pageId, data);
this.optimizeUpdate = index.getDatabase().getSettings().optimizeUpdate;
}
/**
......@@ -183,7 +186,7 @@ public class PageDataLeaf extends PageData {
if (entryCount == 0) {
x = 0;
} else {
if (!SysProperties.OPTIMIZE_UPDATE) {
if (!optimizeUpdate) {
readAllRows();
}
x = findInsertionPoint(row.getKey());
......@@ -199,7 +202,7 @@ public class PageDataLeaf extends PageData {
rows = insert(rows, entryCount, x, row);
entryCount++;
index.getPageStore().update(this);
if (SysProperties.OPTIMIZE_UPDATE) {
if (optimizeUpdate) {
if (writtenData && offset >= start) {
byte[] d = data.getBytes();
int dataStart = offsets[entryCount - 1] + rowLength;
......@@ -267,7 +270,7 @@ public class PageDataLeaf extends PageData {
index.getPageStore().logUndo(this, data);
written = false;
changeCount = index.getPageStore().getChangeCount();
if (!SysProperties.OPTIMIZE_UPDATE) {
if (!optimizeUpdate) {
readAllRows();
}
Row r = getRowAt(i);
......@@ -288,7 +291,7 @@ public class PageDataLeaf extends PageData {
int keyOffsetPairLen = 2 + Data.getVarLongLen(keys[i]);
int startNext = i > 0 ? offsets[i - 1] : index.getPageStore().getPageSize();
int rowLength = startNext - offsets[i];
if (SysProperties.OPTIMIZE_UPDATE) {
if (optimizeUpdate) {
if (writtenData) {
byte[] d = data.getBytes();
int dataStart = offsets[entryCount];
......@@ -481,7 +484,7 @@ public class PageDataLeaf extends PageData {
if (written) {
return;
}
if (!SysProperties.OPTIMIZE_UPDATE) {
if (!optimizeUpdate) {
readAllRows();
}
writeHead();
......@@ -493,7 +496,7 @@ public class PageDataLeaf extends PageData {
data.writeVarLong(keys[i]);
data.writeShortInt(offsets[i]);
}
if (!writtenData || !SysProperties.OPTIMIZE_UPDATE) {
if (!writtenData || !optimizeUpdate) {
for (int i = 0; i < entryCount; i++) {
data.setPos(offsets[i]);
Row r = getRowAt(i);
......
......@@ -9,7 +9,7 @@ package org.h2.result;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.DbException;
......@@ -226,7 +226,8 @@ public class LocalResult implements ResultInterface, ResultTarget {
ValueArray array = ValueArray.get(values);
distinctRows.put(array, values);
rowCount = distinctRows.size();
if (rowCount > SysProperties.MAX_MEMORY_ROWS_DISTINCT && session.getDatabase().isPersistent()) {
Database db = session.getDatabase();
if (rowCount > db.getSettings().maxMemoryRowsDistinct && db.isPersistent()) {
disk = new ResultTempTable(session, sort);
disk.addRows(distinctRows.values());
distinctRows = null;
......
......@@ -64,7 +64,7 @@ class ResultDiskBuffer implements ResultExternal {
this.sort = sort;
this.columnCount = columnCount;
Database db = session.getDatabase();
rowBuff = Data.create(db, SysProperties.PAGE_SIZE);
rowBuff = Data.create(db, Constants.DEFAULT_PAGE_SIZE);
String fileName = session.getDatabase().createTempFile();
file = session.getDatabase().openFile(fileName, "rw", false);
file.setCheckedWriting(false);
......
......@@ -7,7 +7,6 @@
package org.h2.result;
import java.util.ArrayList;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -88,7 +87,7 @@ public class RowList {
String fileName = db.createTempFile();
file = db.openFile(fileName, "rw", false);
file.seek(FileStore.HEADER_LENGTH);
rowBuff = Data.create(db, SysProperties.PAGE_SIZE);
rowBuff = Data.create(db, Constants.DEFAULT_PAGE_SIZE);
file.seek(FileStore.HEADER_LENGTH);
}
Data buff = rowBuff;
......
......@@ -134,7 +134,7 @@ public class PageStore implements CacheWriter {
private String fileName;
private FileStore file;
private String accessMode;
private int pageSize = SysProperties.PAGE_SIZE;
private int pageSize = Constants.DEFAULT_PAGE_SIZE;
private int pageSizeShift;
private long writeCountBase, writeCount, readCount;
private int logKey, logFirstTrunkPage, logFirstDataPage;
......@@ -445,7 +445,7 @@ public class PageStore implements CacheWriter {
* TransactionCommand.SHUTDOWN_COMPACT or TransactionCommand.SHUTDOWN_DEFRAG
*/
public void compact(int compactMode) {
if (!SysProperties.PAGE_STORE_TRIM) {
if (!database.getSettings().pageStoreTrim) {
return;
}
// find the last used page
......@@ -478,8 +478,8 @@ public class PageStore implements CacheWriter {
isCompactFully = isDefrag = true;
}
int maxCompactTime = SysProperties.MAX_COMPACT_TIME;
int maxMove = SysProperties.MAX_COMPACT_COUNT;
int maxCompactTime = database.getSettings().maxCompactTime;
int maxMove = database.getSettings().maxCompactCount;
if (isCompactFully || isDefrag) {
maxCompactTime = Integer.MAX_VALUE;
......
......@@ -8,7 +8,7 @@ package org.h2.store;
import java.lang.ref.WeakReference;
import java.security.AccessControlException;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.message.Trace;
import org.h2.message.TraceSystem;
......@@ -79,7 +79,7 @@ public class WriterThread implements Runnable {
int wait = writeDelay;
try {
if (database.isFileLockSerialized()) {
wait = SysProperties.MIN_WRITE_DELAY;
wait = Constants.MIN_WRITE_DELAY;
database.checkpointIfRequired();
} else {
database.flush();
......@@ -93,9 +93,9 @@ public class WriterThread implements Runnable {
// TODO log writer: could also flush the dirty cache when there is
// low activity
if (wait < SysProperties.MIN_WRITE_DELAY) {
if (wait < Constants.MIN_WRITE_DELAY) {
// wait 0 mean wait forever, which is not what we want
wait = SysProperties.MIN_WRITE_DELAY;
wait = Constants.MIN_WRITE_DELAY;
}
try {
Thread.sleep(wait);
......
......@@ -194,7 +194,7 @@ public class TableFilter implements ColumnResolver {
}
private void setEvaluatable(TableFilter join) {
if (SysProperties.NESTED_JOINS) {
if (session.getDatabase().getSettings().nestedJoins) {
setEvaluatable(true);
return;
}
......@@ -498,7 +498,7 @@ public class TableFilter implements ColumnResolver {
public void addJoin(TableFilter filter, boolean outer, boolean nested, final Expression on) {
if (on != null) {
on.mapColumns(this, 0);
if (SysProperties.NESTED_JOINS) {
if (session.getDatabase().getSettings().nestedJoins) {
visit(new TableFilterVisitor() {
public void accept(TableFilter f) {
on.mapColumns(f, 0);
......@@ -511,7 +511,7 @@ public class TableFilter implements ColumnResolver {
});
}
}
if (nested && SysProperties.NESTED_JOINS) {
if (nested && session.getDatabase().getSettings().nestedJoins) {
if (nestedJoin != null) {
throw DbException.throwInternalError();
}
......@@ -531,7 +531,7 @@ public class TableFilter implements ColumnResolver {
if (join == null) {
join = filter;
filter.joinOuter = outer;
if (SysProperties.NESTED_JOINS) {
if (session.getDatabase().getSettings().nestedJoins) {
if (outer) {
filter.visit(new TableFilterVisitor() {
public void accept(TableFilter f) {
......
......@@ -23,7 +23,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.zip.CRC32;
import org.h2.compress.CompressLZF;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.DbObject;
import org.h2.engine.MetaRecord;
......@@ -381,7 +380,7 @@ public class Recover extends Tool implements DataHandler {
" writeVersion: " + writeVersion +
" readVersion: " + readVersion);
if (pageSize < PageStore.PAGE_SIZE_MIN || pageSize > PageStore.PAGE_SIZE_MAX) {
pageSize = SysProperties.PAGE_SIZE;
pageSize = Constants.DEFAULT_PAGE_SIZE;
writer.println("-- ERROR: page size; using " + pageSize);
}
long pageCount = length / pageSize;
......
......@@ -41,7 +41,7 @@ public class CompareMode {
int cacheSize = 0;
if (collator != null) {
this.collator.setStrength(strength);
cacheSize = SysProperties.getCollatorCacheSize();
cacheSize = SysProperties.COLLATOR_CACHE_SIZE;
}
if (cacheSize != 0) {
collationKeys = SmallLRUCache.newInstance(cacheSize);
......
......@@ -11,7 +11,6 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.constant.SysProperties;
import org.h2.tools.DeleteDbFiles;
/**
......@@ -29,16 +28,17 @@ public class DirectInsert {
public static void main(String... args) throws Exception {
Class.forName("org.h2.Driver");
DeleteDbFiles.execute("~", "test", true);
Connection conn = DriverManager.getConnection("jdbc:h2:~/test;LOG=0", "sa", "");
Statement stat = conn.createStatement();
initialInsert(conn, stat, 200000);
String url = "jdbc:h2:~/test";
initialInsert(url, 200000);
for (int i = 0; i < 3; i++) {
createAsSelect(stat, true);
createAsSelect(stat, false);
createAsSelect(url, true);
createAsSelect(url, false);
}
}
private static void initialInsert(Connection conn, Statement stat, int len) throws SQLException {
private static void initialInsert(String url, int len) throws SQLException {
Connection conn = DriverManager.getConnection(url + ";LOG=0");
Statement stat = conn.createStatement();
stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, 'Test' || SPACE(100))");
......@@ -53,16 +53,19 @@ public class DirectInsert {
prep.execute();
}
conn.commit();
conn.close();
}
private static void createAsSelect(Statement stat, boolean optimize) throws SQLException {
SysProperties.optimizeInsertFromSelect = optimize;
private static void createAsSelect(String url, boolean optimize) throws SQLException {
Connection conn = DriverManager.getConnection(url + ";OPTIMIZE_INSERT_FROM_SELECT=" + optimize);
Statement stat = conn.createStatement();
stat.execute("DROP TABLE IF EXISTS TEST2");
System.out.println("CREATE TABLE ... AS SELECT " + (optimize ? "(optimized)" : ""));
long time = System.currentTimeMillis();
stat.execute("CREATE TABLE TEST2 AS SELECT * FROM TEST");
System.out.printf("%.3f sec.\n", (System.currentTimeMillis() - time) / 1000.0);
stat.execute("INSERT INTO TEST2 SELECT * FROM TEST2");
conn.close();
}
}
......@@ -250,6 +250,11 @@ java org.h2.test.TestAll timer
*/
public boolean splitFileSystem;
/**
* Support nested joins.
*/
public boolean nestedJoins;
/**
* If the transaction log should be kept small (that is, the log should be
* switched early).
......@@ -319,10 +324,10 @@ java org.h2.test.TestAll timer
System.setProperty("h2.check2", "true");
int initialTest;
// System.setProperty("h2.largeTransactions", "true");
// System.setProperty("h2.lobInDatabase", "true");
test.nestedJoins = true;
// System.setProperty("h2.largeTransactions", "true");
// System.setProperty("h2.analyzeAuto", "100");
// System.setProperty("h2.nestedJoins", "true");
// System.setProperty("h2.optimizeOr", "true");
// System.setProperty("h2.queryCacheSize", "100");
// System.setProperty("h2.dropRestrict", "true");
......
......@@ -308,7 +308,9 @@ public abstract class TestBase {
if (config.defrag) {
url += ";DEFRAG_ALWAYS=TRUE";
}
if (config.nestedJoins) {
url += ";NESTED_JOINS=TRUE";
}
return "jdbc:h2:" + url;
}
......
......@@ -16,7 +16,6 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import org.h2.constant.SysProperties;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
import org.h2.util.New;
......@@ -35,14 +34,14 @@ public class TestNestedJoins 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();
}
public void test() throws Exception {
if (!SysProperties.NESTED_JOINS) {
if (!config.nestedJoins) {
return;
}
deleteDb("nestedJoins");
......
......@@ -16,7 +16,6 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import org.h2.constant.SysProperties;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
import org.h2.util.New;
......@@ -42,7 +41,7 @@ public class TestOuterJoins extends TestBase {
}
public void test() throws Exception {
if (!SysProperties.NESTED_JOINS) {
if (!config.nestedJoins) {
return;
}
deleteDb("outerJoins");
......
......@@ -14,7 +14,7 @@ import java.util.ArrayList;
import java.util.Random;
import org.h2.compress.CompressLZF;
import org.h2.compress.Compressor;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
import org.h2.tools.CompressTool;
......@@ -132,7 +132,7 @@ public class TestCompress extends TestBase {
}
conn.close();
Compressor compress = new CompressLZF();
int pageSize = SysProperties.PAGE_SIZE;
int pageSize = Constants.DEFAULT_PAGE_SIZE;
byte[] buff = new byte[pageSize];
byte[] test = new byte[2 * pageSize];
compress.compress(buff, pageSize, test, 0);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论