提交 b9283ea4 authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Formatting / Javadocs

上级 2134953d
...@@ -54,11 +54,13 @@ class Optimizer { ...@@ -54,11 +54,13 @@ class Optimizer {
} }
/** /**
* @return {@code true} If join reordering is enabled (it can be disabled by hint). * Whether join reordering is enabled (it can be disabled by hint).
*
* @return {@code true} if yes
*/ */
private static boolean isJoinReorderingEnabled() { private static boolean isJoinReorderingEnabled() {
OptimizerHints hints = OptimizerHints.get(); OptimizerHints hints = OptimizerHints.get();
return hints == null || hints.joinReorderEnabled; return hints == null || hints.getJoinReorderEnabled();
} }
/** /**
......
...@@ -6,23 +6,26 @@ ...@@ -6,23 +6,26 @@
package org.h2.command.dml; package org.h2.command.dml;
/** /**
* Thread local hints for H2 query optimizer. All the ongoing queries in the current thread * Thread local hints for H2 query optimizer. All the ongoing queries in the
* will run with respect to these hints, so if they are needed only for a single * current thread will run with respect to these hints, so if they are needed
* operation it is preferable to setup and drop them in try-finally block. * only for a single operation it is preferable to setup and drop them in
* try-finally block.
* *
* Currently works only in embedded mode. * Currently works only in embedded mode.
* *
* @author Sergi Vladykin * @author Sergi Vladykin
*/ */
public class OptimizerHints { public class OptimizerHints {
private static final ThreadLocal<OptimizerHints> HINTS = new ThreadLocal<OptimizerHints>();
boolean joinReorderEnabled = true; private static final ThreadLocal<OptimizerHints> HINTS =
new ThreadLocal<OptimizerHints>();
private boolean joinReorderEnabled = true;
/** /**
* Set thread local hints or {@code null} to drop any existing hints. * Set thread local hints or {@code null} to drop any existing hints.
* *
* @param hints * @param hints the hints
*/ */
public static void set(OptimizerHints hints) { public static void set(OptimizerHints hints) {
if (hints != null) { if (hints != null) {
...@@ -33,19 +36,25 @@ public class OptimizerHints { ...@@ -33,19 +36,25 @@ public class OptimizerHints {
} }
/** /**
* @return Current thread local hints or {@code null} if none. * Get the current thread local hints or {@code null} if none.
*
* @return the hints
*/ */
public static OptimizerHints get() { public static OptimizerHints get() {
return HINTS.get(); return HINTS.get();
} }
/** /**
* Set whether reordering of tables (or anything else in the {@code FROM} clause) is enabled. * Set whether reordering of tables (or anything else in the {@code FROM}
* By default is {@code true}. * clause) is enabled. By default is {@code true}.
* *
* @param joinReorderEnabled Flag value. * @param joinReorderEnabled Flag value.
*/ */
public void setJoinReorderEnabled(boolean joinReorderEnabled) { public void setJoinReorderEnabled(boolean joinReorderEnabled) {
this.joinReorderEnabled = joinReorderEnabled; this.joinReorderEnabled = joinReorderEnabled;
} }
public boolean getJoinReorderEnabled() {
return joinReorderEnabled;
}
} }
...@@ -49,7 +49,8 @@ public class TestMvcc4 extends TestBase { ...@@ -49,7 +49,8 @@ public class TestMvcc4 extends TestBase {
+ "entity_id VARCHAR(100) NOT NULL PRIMARY KEY, " + "entity_id VARCHAR(100) NOT NULL PRIMARY KEY, "
+ "lastUpdated TIMESTAMP NOT NULL)"); + "lastUpdated TIMESTAMP NOT NULL)");
PreparedStatement ps = setup.prepareStatement("INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)"); PreparedStatement ps = setup.prepareStatement(
"INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)");
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
String id = "" + i; String id = "" + i;
ps.setString(1, id); ps.setString(1, id);
...@@ -72,7 +73,8 @@ public class TestMvcc4 extends TestBase { ...@@ -72,7 +73,8 @@ public class TestMvcc4 extends TestBase {
Connection c2 = getConnection("mvcc4"); Connection c2 = getConnection("mvcc4");
c2.setAutoCommit(false); c2.setAutoCommit(false);
PreparedStatement ps = c2.prepareStatement("SELECT * FROM test WHERE entity_id = ? FOR UPDATE"); PreparedStatement ps = c2.prepareStatement(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE");
ps.setString(1, "1"); ps.setString(1, "1");
ps.executeQuery().next(); ps.executeQuery().next();
...@@ -93,32 +95,32 @@ public class TestMvcc4 extends TestBase { ...@@ -93,32 +95,32 @@ public class TestMvcc4 extends TestBase {
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
{ // Execute an update. This should initially fail, and enter the waiting
//Execute an update. This should initially fail, and enter the waiting for lock case. // for lock case.
PreparedStatement ps = c1.prepareStatement("UPDATE test SET lastUpdated = ?"); PreparedStatement ps = c1.prepareStatement("UPDATE test SET lastUpdated = ?");
ps.setTimestamp(1, new Timestamp(System.currentTimeMillis())); ps.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
ps.executeUpdate(); ps.executeUpdate();
}
c1.commit(); c1.commit();
c1.close(); c1.close();
Connection verify = getConnection("mvcc4"); Connection verify = getConnection("mvcc4");
{
verify.setAutoCommit(false); verify.setAutoCommit(false);
PreparedStatement ps = verify.prepareStatement("SELECT COUNT(*) FROM test"); ps = verify.prepareStatement("SELECT COUNT(*) FROM test");
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
assertTrue(rs.next()); assertTrue(rs.next());
assertTrue(rs.getInt(1) == 2); assertTrue(rs.getInt(1) == 2);
verify.commit(); verify.commit();
verify.close(); verify.close();
}
setup.close(); setup.close();
} }
private static void waitForThreadToBlockOnDB(Thread t) { private static void waitForThreadToBlockOnDB(Thread t) {
while (true) { while (true) {
// TODO must not use getAllStackTraces, as the method names are
// implementation details
Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces(); Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces();
StackTraceElement[] elements = threadMap.get(t); StackTraceElement[] elements = threadMap.get(t);
if (elements != null if (elements != null
......
...@@ -777,4 +777,4 @@ bradmesserle dan incorporated keegan industries tagtraum cyr israels rafel ...@@ -777,4 +777,4 @@ bradmesserle dan incorporated keegan industries tagtraum cyr israels rafel
dance schedule hitting reverted youngest footers inliner deadlocked reorder nger dance schedule hitting reverted youngest footers inliner deadlocked reorder nger
nullid syspublic sysibmts sysibminternal syscat sysfun sysstat systools sysibmadm nullid syspublic sysibmts sysibminternal syscat sysfun sysstat systools sysibmadm
sysproc jcc expecting gpg showed unreferenced activating cvf stephane lacoin sysproc jcc expecting gpg showed unreferenced activating cvf stephane lacoin
centrale umr ecole nantes sticc lab centrale umr ecole nantes sticc lab reordering preferable
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论