1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.engine; |
7 | |
8 | import java.util.HashMap; |
9 | |
10 | /** |
11 | * This class contains various database-level settings. To override the |
12 | * documented default value for a database, append the setting in the database |
13 | * URL: "jdbc:h2:test;ALIAS_COLUMN_NAME=TRUE" when opening the first connection |
14 | * to the database. The settings can not be changed once the database is open. |
15 | * <p> |
16 | * Some settings are a last resort and temporary solution to work around a |
17 | * problem in the application or database engine. Also, there are system |
18 | * properties to enable features that are not yet fully tested or that are not |
19 | * backward compatible. |
20 | * </p> |
21 | */ |
22 | public class DbSettings extends SettingsBase { |
23 | |
24 | private static DbSettings defaultSettings; |
25 | |
26 | /** |
27 | * Database setting <code>ALIAS_COLUMN_NAME</code> (default: false).<br /> |
28 | * When enabled, aliased columns (as in SELECT ID AS I FROM TEST) return the |
29 | * alias (I in this case) in ResultSetMetaData.getColumnName() and 'null' in |
30 | * getTableName(). If disabled, the real column name (ID in this case) and |
31 | * table name is returned. |
32 | * <br /> |
33 | * This setting only affects the default and the MySQL mode. When using |
34 | * any other mode, this feature is enabled for compatibility, even if this |
35 | * database setting is not enabled explicitly. |
36 | */ |
37 | public final boolean aliasColumnName = get("ALIAS_COLUMN_NAME", false); |
38 | |
39 | /** |
40 | * Database setting <code>ANALYZE_AUTO</code> (default: 2000).<br /> |
41 | * After changing this many rows, ANALYZE is automatically run for a table. |
42 | * Automatically running ANALYZE is disabled if set to 0. If set to 1000, |
43 | * then ANALYZE will run against each user table after about 1000 changes to |
44 | * that table. The time between running ANALYZE doubles each time since |
45 | * starting the database. It is not run on local temporary tables, and |
46 | * tables that have a trigger on SELECT. |
47 | */ |
48 | public final int analyzeAuto = get("ANALYZE_AUTO", 2000); |
49 | |
50 | /** |
51 | * Database setting <code>ANALYZE_SAMPLE</code> (default: 10000).<br /> |
52 | * The default sample size when analyzing a table. |
53 | */ |
54 | public final int analyzeSample = get("ANALYZE_SAMPLE", 10000); |
55 | |
56 | /** |
57 | * Database setting <code>DATABASE_TO_UPPER</code> (default: true).<br /> |
58 | * Database short names are converted to uppercase for the DATABASE() |
59 | * function, and in the CATALOG column of all database meta data methods. |
60 | * Setting this to "false" is experimental. When set to false, all |
61 | * identifier names (table names, column names) are case sensitive (except |
62 | * aggregate, built-in functions, data types, and keywords). |
63 | */ |
64 | public final boolean databaseToUpper = get("DATABASE_TO_UPPER", true); |
65 | |
66 | /** |
67 | * Database setting <code>DB_CLOSE_ON_EXIT</code> (default: true).<br /> |
68 | * Close the database when the virtual machine exits normally, using a |
69 | * shutdown hook. |
70 | */ |
71 | public final boolean dbCloseOnExit = get("DB_CLOSE_ON_EXIT", true); |
72 | |
73 | /** |
74 | * Database setting <code>DEFAULT_CONNECTION</code> (default: false).<br /> |
75 | * Whether Java functions can use |
76 | * <code>DriverManager.getConnection("jdbc:default:connection")</code> to |
77 | * get a database connection. This feature is disabled by default for |
78 | * performance reasons. Please note the Oracle JDBC driver will try to |
79 | * resolve this database URL if it is loaded before the H2 driver. |
80 | */ |
81 | public boolean defaultConnection = get("DEFAULT_CONNECTION", false); |
82 | |
83 | /** |
84 | * Database setting <code>DEFAULT_ESCAPE</code> (default: \).<br /> |
85 | * The default escape character for LIKE comparisons. To select no escape |
86 | * character, use an empty string. |
87 | */ |
88 | public final String defaultEscape = get("DEFAULT_ESCAPE", "\\"); |
89 | |
90 | /** |
91 | * Database setting <code>DEFRAG_ALWAYS</code> (default: false).<br /> |
92 | * Each time the database is closed normally, it is fully defragmented (the |
93 | * same as SHUTDOWN DEFRAG). If you execute SHUTDOWN COMPACT, then this |
94 | * setting is ignored. |
95 | */ |
96 | public final boolean defragAlways = get("DEFRAG_ALWAYS", false); |
97 | |
98 | /** |
99 | * Database setting <code>DROP_RESTRICT</code> (default: true).<br /> |
100 | * Whether the default action for DROP TABLE and DROP VIEW is RESTRICT. |
101 | */ |
102 | public final boolean dropRestrict = get("DROP_RESTRICT", true); |
103 | |
104 | /** |
105 | * Database setting <code>EARLY_FILTER</code> (default: false).<br /> |
106 | * This setting allows table implementations to apply filter conditions |
107 | * early on. |
108 | */ |
109 | public final boolean earlyFilter = get("EARLY_FILTER", false); |
110 | |
111 | /** |
112 | * Database setting <code>ESTIMATED_FUNCTION_TABLE_ROWS</code> (default: |
113 | * 1000).<br /> |
114 | * The estimated number of rows in a function table (for example, CSVREAD or |
115 | * FTL_SEARCH). This value is used by the optimizer. |
116 | */ |
117 | public final int estimatedFunctionTableRows = get( |
118 | "ESTIMATED_FUNCTION_TABLE_ROWS", 1000); |
119 | |
120 | /** |
121 | * Database setting <code>FUNCTIONS_IN_SCHEMA</code> |
122 | * (default: true).<br /> |
123 | * If set, all functions are stored in a schema. Specially, the SCRIPT |
124 | * statement will always include the schema name in the CREATE ALIAS |
125 | * statement. This is not backward compatible with H2 versions 1.2.134 and |
126 | * older. |
127 | */ |
128 | public final boolean functionsInSchema = get("FUNCTIONS_IN_SCHEMA", true); |
129 | |
130 | /** |
131 | * Database setting <code>LARGE_TRANSACTIONS</code> (default: true).<br /> |
132 | * Support very large transactions |
133 | */ |
134 | public final boolean largeTransactions = get("LARGE_TRANSACTIONS", true); |
135 | |
136 | /** |
137 | * Database setting <code>MAX_COMPACT_COUNT</code> |
138 | * (default: Integer.MAX_VALUE).<br /> |
139 | * The maximum number of pages to move when closing a database. |
140 | */ |
141 | public final int maxCompactCount = get("MAX_COMPACT_COUNT", |
142 | Integer.MAX_VALUE); |
143 | |
144 | /** |
145 | * Database setting <code>MAX_COMPACT_TIME</code> (default: 200).<br /> |
146 | * The maximum time in milliseconds used to compact a database when closing. |
147 | */ |
148 | public final int maxCompactTime = get("MAX_COMPACT_TIME", 200); |
149 | |
150 | /** |
151 | * Database setting <code>MAX_QUERY_TIMEOUT</code> (default: 0).<br /> |
152 | * The maximum timeout of a query in milliseconds. The default is 0, meaning |
153 | * no limit. Please note the actual query timeout may be set to a lower |
154 | * value. |
155 | */ |
156 | public int maxQueryTimeout = get("MAX_QUERY_TIMEOUT", 0); |
157 | |
158 | /** |
159 | * Database setting <code>NESTED_JOINS</code> (default: true).<br /> |
160 | * Whether nested joins should be supported. |
161 | */ |
162 | public final boolean nestedJoins = get("NESTED_JOINS", true); |
163 | |
164 | /** |
165 | * Database setting <code>OPTIMIZE_DISTINCT</code> (default: true).<br /> |
166 | * Improve the performance of simple DISTINCT queries if an index is |
167 | * available for the given column. The optimization is used if: |
168 | * <ul> |
169 | * <li>The select is a single column query without condition </li> |
170 | * <li>The query contains only one table, and no group by </li> |
171 | * <li>There is only one table involved </li> |
172 | * <li>There is an ascending index on the column </li> |
173 | * <li>The selectivity of the column is below 20 </li> |
174 | * </ul> |
175 | */ |
176 | public final boolean optimizeDistinct = get("OPTIMIZE_DISTINCT", true); |
177 | |
178 | /** |
179 | * Database setting <code>OPTIMIZE_EVALUATABLE_SUBQUERIES</code> (default: |
180 | * true).<br /> |
181 | * Optimize subqueries that are not dependent on the outer query. |
182 | */ |
183 | public final boolean optimizeEvaluatableSubqueries = get( |
184 | "OPTIMIZE_EVALUATABLE_SUBQUERIES", true); |
185 | |
186 | /** |
187 | * Database setting <code>OPTIMIZE_INSERT_FROM_SELECT</code> |
188 | * (default: true).<br /> |
189 | * Insert into table from query directly bypassing temporary disk storage. |
190 | * This also applies to create table as select. |
191 | */ |
192 | public final boolean optimizeInsertFromSelect = get( |
193 | "OPTIMIZE_INSERT_FROM_SELECT", true); |
194 | |
195 | /** |
196 | * Database setting <code>OPTIMIZE_IN_LIST</code> (default: true).<br /> |
197 | * Optimize IN(...) and IN(SELECT ...) comparisons. This includes |
198 | * optimization for SELECT, DELETE, and UPDATE. |
199 | */ |
200 | public final boolean optimizeInList = get("OPTIMIZE_IN_LIST", true); |
201 | |
202 | /** |
203 | * Database setting <code>OPTIMIZE_IN_SELECT</code> (default: true).<br /> |
204 | * Optimize IN(SELECT ...) comparisons. This includes |
205 | * optimization for SELECT, DELETE, and UPDATE. |
206 | */ |
207 | public final boolean optimizeInSelect = get("OPTIMIZE_IN_SELECT", true); |
208 | |
209 | /** |
210 | * Database setting <code>OPTIMIZE_IS_NULL</code> (default: false).<br /> |
211 | * Use an index for condition of the form columnName IS NULL. |
212 | */ |
213 | public final boolean optimizeIsNull = get("OPTIMIZE_IS_NULL", true); |
214 | |
215 | /** |
216 | * Database setting <code>OPTIMIZE_OR</code> (default: true).<br /> |
217 | * Convert (C=? OR C=?) to (C IN(?, ?)). |
218 | */ |
219 | public final boolean optimizeOr = get("OPTIMIZE_OR", true); |
220 | |
221 | /** |
222 | * Database setting <code>OPTIMIZE_TWO_EQUALS</code> (default: true).<br /> |
223 | * Optimize expressions of the form A=B AND B=1. In this case, AND A=1 is |
224 | * added so an index on A can be used. |
225 | */ |
226 | public final boolean optimizeTwoEquals = get("OPTIMIZE_TWO_EQUALS", true); |
227 | |
228 | /** |
229 | * Database setting <code>OPTIMIZE_UPDATE</code> (default: true).<br /> |
230 | * Speed up inserts, updates, and deletes by not reading all rows from a |
231 | * page unless necessary. |
232 | */ |
233 | public final boolean optimizeUpdate = get("OPTIMIZE_UPDATE", true); |
234 | |
235 | /** |
236 | * Database setting <code>PAGE_STORE_MAX_GROWTH</code> |
237 | * (default: 128 * 1024).<br /> |
238 | * The maximum number of pages the file grows at any time. |
239 | */ |
240 | public final int pageStoreMaxGrowth = get("PAGE_STORE_MAX_GROWTH", |
241 | 128 * 1024); |
242 | |
243 | /** |
244 | * Database setting <code>PAGE_STORE_INTERNAL_COUNT</code> |
245 | * (default: false).<br /> |
246 | * Update the row counts on a node level. |
247 | */ |
248 | public final boolean pageStoreInternalCount = get( |
249 | "PAGE_STORE_INTERNAL_COUNT", false); |
250 | |
251 | /** |
252 | * Database setting <code>PAGE_STORE_TRIM</code> (default: true).<br /> |
253 | * Trim the database size when closing. |
254 | */ |
255 | public final boolean pageStoreTrim = get("PAGE_STORE_TRIM", true); |
256 | |
257 | /** |
258 | * Database setting <code>QUERY_CACHE_SIZE</code> (default: 8).<br /> |
259 | * The size of the query cache, in number of cached statements. Each session |
260 | * has it's own cache with the given size. The cache is only used if the SQL |
261 | * statement and all parameters match. Only the last returned result per |
262 | * query is cached. The following statement types are cached: SELECT |
263 | * statements are cached (excluding UNION and FOR UPDATE statements), CALL |
264 | * if it returns a single value, DELETE, INSERT, MERGE, UPDATE, and |
265 | * transactional statements such as COMMIT. This works for both statements |
266 | * and prepared statement. |
267 | */ |
268 | public final int queryCacheSize = get("QUERY_CACHE_SIZE", 8); |
269 | |
270 | /** |
271 | * Database setting <code>RECOMPILE_ALWAYS</code> (default: false).<br /> |
272 | * Always recompile prepared statements. |
273 | */ |
274 | public final boolean recompileAlways = get("RECOMPILE_ALWAYS", false); |
275 | |
276 | /** |
277 | * Database setting <code>RECONNECT_CHECK_DELAY</code> (default: 200).<br /> |
278 | * Check the .lock.db file every this many milliseconds to detect that the |
279 | * database was changed. The process writing to the database must first |
280 | * notify a change in the .lock.db file, then wait twice this many |
281 | * milliseconds before updating the database. |
282 | */ |
283 | public final int reconnectCheckDelay = get("RECONNECT_CHECK_DELAY", 200); |
284 | |
285 | /** |
286 | * Database setting <code>REUSE_SPACE</code> (default: true).<br /> |
287 | * If disabled, all changes are appended to the database file, and existing |
288 | * content is never overwritten. This setting has no effect if the database |
289 | * is already open. |
290 | */ |
291 | public final boolean reuseSpace = get("REUSE_SPACE", true); |
292 | |
293 | /** |
294 | * Database setting <code>ROWID</code> (default: true).<br /> |
295 | * If set, each table has a pseudo-column _ROWID_. |
296 | */ |
297 | public final boolean rowId = get("ROWID", true); |
298 | |
299 | /** |
300 | * Database setting <code>SELECT_FOR_UPDATE_MVCC</code> |
301 | * (default: true).<br /> |
302 | * If set, SELECT .. FOR UPDATE queries lock only the selected rows when |
303 | * using MVCC. |
304 | */ |
305 | public final boolean selectForUpdateMvcc = get("SELECT_FOR_UPDATE_MVCC", true); |
306 | |
307 | /** |
308 | * Database setting <code>SHARE_LINKED_CONNECTIONS</code> |
309 | * (default: true).<br /> |
310 | * Linked connections should be shared, that means connections to the same |
311 | * database should be used for all linked tables that connect to the same |
312 | * database. |
313 | */ |
314 | public final boolean shareLinkedConnections = get( |
315 | "SHARE_LINKED_CONNECTIONS", true); |
316 | |
317 | /** |
318 | * Database setting <code>DEFAULT_TABLE_ENGINE</code> |
319 | * (default: null).<br /> |
320 | * The default table engine to use for new tables. |
321 | */ |
322 | public String defaultTableEngine = get("DEFAULT_TABLE_ENGINE", null); |
323 | |
324 | /** |
325 | * Database setting <code>MV_STORE</code> |
326 | * (default: false for version 1.3, true for version 1.4).<br /> |
327 | * Use the MVStore storage engine. |
328 | */ |
329 | public boolean mvStore = get("MV_STORE", Constants.VERSION_MINOR >= 4); |
330 | |
331 | /** |
332 | * Database setting <code>COMPRESS</code> |
333 | * (default: false).<br /> |
334 | * Compress data when storing. |
335 | */ |
336 | public final boolean compressData = get("COMPRESS", false); |
337 | |
338 | private DbSettings(HashMap<String, String> s) { |
339 | super(s); |
340 | } |
341 | |
342 | /** |
343 | * INTERNAL. |
344 | * Get the settings for the given properties (may not be null). |
345 | * |
346 | * @param s the settings |
347 | * @return the settings |
348 | */ |
349 | public static DbSettings getInstance(HashMap<String, String> s) { |
350 | return new DbSettings(s); |
351 | } |
352 | |
353 | /** |
354 | * INTERNAL. |
355 | * Get the default settings. Those must not be modified. |
356 | * |
357 | * @return the settings |
358 | */ |
359 | public static DbSettings getDefaultSettings() { |
360 | if (defaultSettings == null) { |
361 | defaultSettings = new DbSettings(new HashMap<String, String>()); |
362 | } |
363 | return defaultSettings; |
364 | } |
365 | |
366 | } |