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

Queries with more than 10 joins are now faster.

上级 51821000
......@@ -18,15 +18,16 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Opening a connection with AUTO_SERVER=TRUE is now fast
when the database is already open in another process (less than 0.01 seconds
instead of 2 seconds).
<ul><li>Queries with more than 10 joins are now faster.
</li><li>Opening a connection with AUTO_SERVER=TRUE is now fast
when the database is already open in another process (less than 0.01 seconds
instead of 2 seconds).
</li><li>IF NOT EXISTS is supported for named constraints in
ALTER TABLE ... ADD CONSTRAINT.
ALTER TABLE ... ADD CONSTRAINT.
</li><li>IF EXISTS is supported for named constraints in
ALTER TABLE ... DROP CONSTRAINT.
ALTER TABLE ... DROP CONSTRAINT.
</li><li>The error messages have been translated to Spanish by Dario V. Fassi.
Thanks a lot!
Thanks a lot!
</li><li>Linked tables: the automatic connection sharing didn't work. Actually the
system property h2.shareLinkedConnections was working in the opposite direction:
it was disabled when set to true. Now it works as expected.
......
......@@ -306,7 +306,7 @@ Of course, patches are always welcome, but are not always applied as is. Patches
move Products that Work with H2 to Comparison,
move Performance Tuning to Advanced Topics
</li><li>Support JMX: Create an MBean for each database and server (support JConsole).
See http://thedevcloud.blogspot.com/2008/10/displaying-hsql-database-manager-in.html
See http://thedevcloud.blogspot.com/2008/10/displaying-hsql-database-manager-in.html
</li><li>Translation: use ${.} in help.csv
</li><li>Translated .pdf
</li><li>Cluster: hot deploy (adding a node on runtime)
......
......@@ -6,6 +6,7 @@
*/
package org.h2.command.dml;
import java.math.BigInteger;
import java.sql.SQLException;
import java.util.BitSet;
import java.util.Random;
......@@ -15,6 +16,7 @@ import org.h2.expression.Expression;
import org.h2.table.Plan;
import org.h2.table.PlanItem;
import org.h2.table.TableFilter;
import org.h2.util.MathUtils;
import org.h2.util.ObjectUtils;
import org.h2.util.Permutations;
......@@ -25,8 +27,8 @@ import org.h2.util.Permutations;
public class Optimizer {
private static final int MAX_BRUTE_FORCE_FILTERS = 7;
private static final int MAX_BRUTE_FORCE = 2000;
private static final int MAX_GENETIC = 2000;
private static final BigInteger MAX_BRUTE_FORCE = new BigInteger("" + 2000);
private static final int MAX_GENETIC = 500;
private long start;
private BitSet switched;
......@@ -62,10 +64,11 @@ public class Optimizer {
}
private int getMaxBruteForceFilters(int filterCount) {
int i = 0, j = filterCount, total = filterCount;
while (j > 0 && total < MAX_BRUTE_FORCE) {
int i = 0, j = filterCount;
BigInteger total = new BigInteger("" + filterCount);
while (j > 0 && total.compareTo(MAX_BRUTE_FORCE) < 0) {
j--;
total *= j;
total = total.multiply(MathUtils.factorial(j));
i++;
}
return i;
......
......@@ -39,7 +39,7 @@
90015=SUM \u00F3 AVG sobre un tipo de datos invalidado para {0}
90016=La columna {0} debe estar incluida en la lista de GROUP BY
90017=Intento de definir una segunda clave primaria
90018=La conexi\u00F3n no fue cerrada por la aplicaci\u00F3n y esta siendo limpiada \(garbage collected\)
90018=La conexi\u00F3n no fue cerrada por la aplicaci\u00F3n y esta siendo limpiada (garbage collected)
90019=Imposible eliminar el usuario actual
90020=La base de datos puede que ya est\u00E9 siendo utilizada\: {0}. Soluciones Posibles\: cierre todas las otras conexiones; use el modo server
90021=Conversi\u00F3n de datos fallida, convirtiendo {0}
......
......@@ -7,6 +7,7 @@
package org.h2.util;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.SQLException;
import org.h2.engine.Constants;
......@@ -178,4 +179,29 @@ public class MathUtils {
}
}
/**
* Calculate the factorial (n!) of a number.
* This implementation uses a naive multiplication loop, and
* is very slow for large n.
* For n = 1000, it takes about 10 ms.
* For n = 8000, it takes about 800 ms.
*
* @param n the number
* @return the factorial of n
*/
public static BigInteger factorial(int n) {
if (n < 0) {
throw new IllegalArgumentException(n + "<0");
} else if (n < 2) {
return BigInteger.ONE;
}
BigInteger x = new BigInteger("" + n);
BigInteger result = x;
for (int i = n - 1; i >= 2; i--) {
x = x.subtract(BigInteger.ONE);
result = result.multiply(x);
}
return result;
}
}
......@@ -110,6 +110,7 @@ import org.h2.test.unit.TestFileSystem;
import org.h2.test.unit.TestFtp;
import org.h2.test.unit.TestIntArray;
import org.h2.test.unit.TestIntIntHashMap;
import org.h2.test.unit.TestMathUtils;
import org.h2.test.unit.TestMultiThreadedKernel;
import org.h2.test.unit.TestOverflow;
import org.h2.test.unit.TestPattern;
......@@ -603,6 +604,7 @@ http://www.w3schools.com/sql/
new TestFileSystem().runTest(this);
new TestIntArray().runTest(this);
new TestIntIntHashMap().runTest(this);
new TestMathUtils().runTest(this);
new TestMultiThreadedKernel().runTest(this);
new TestOverflow().runTest(this);
new TestPattern().runTest(this);
......
......@@ -15,6 +15,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import org.h2.constant.SysProperties;
import org.h2.test.TestBase;
/**
......@@ -65,7 +66,7 @@ public class TestLinkedTable extends TestBase {
// }
private void testSharedConnection() throws SQLException {
if (config.memory) {
if (config.memory || !SysProperties.SHARE_LINKED_CONNECTIONS) {
return;
}
org.h2.Driver.load();
......
/*
* Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
import java.sql.SQLException;
import org.h2.test.TestBase;
import org.h2.util.MathUtils;
/**
* Tests math utility methods.
*/
public class TestMathUtils extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws SQLException {
try {
MathUtils.factorial(-1);
fail();
} catch (IllegalArgumentException e) {
// ignore
}
assertEquals("1", MathUtils.factorial(0).toString());
assertEquals("1", MathUtils.factorial(1).toString());
assertEquals("2", MathUtils.factorial(2).toString());
assertEquals("6", MathUtils.factorial(3).toString());
assertEquals("3628800", MathUtils.factorial(10).toString());
assertEquals("2432902008176640000", MathUtils.factorial(20).toString());
}
}
......@@ -566,4 +566,5 @@ implies looping cataloguing mapper frees javaw geographic borges grass
somehow marcio groove roy gis matt targeted brazil dig opt deregister
classname recaptcha unload unloaded unloads activator statistic hence rathsack
reflects doy bloom minimal gmx conserve panic serious robert thursday
wednesday saturday friday tuesday sharing opposite fassi dario clauses
\ No newline at end of file
wednesday saturday friday tuesday sharing opposite fassi dario clauses
factorial blogspot displaying thedevcloud
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论