提交 4be1a5ce authored 作者: S.Vladykin's avatar S.Vladykin

Checkstyle fixes + trace.isDebugEnabled() check added.

上级 d6f7374e
...@@ -241,7 +241,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -241,7 +241,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
// If we have two indexes with the same cost, and one of the indexes can satisfy the query // If we have two indexes with the same cost, and one of the indexes can satisfy the query
// without needing to read from the primary table, make that one slightly lower cost // without needing to read from the primary table, make that one slightly lower cost
HashSet<Column> set1 = New.hashSet(); HashSet<Column> set1 = New.hashSet();
for (int i=0; i < filters.length; i++) { for (int i = 0; i < filters.length; i++) {
if (filters[i].getSelect() != null) { if (filters[i].getSelect() != null) {
filters[i].getSelect().isEverything(ExpressionVisitor.getColumnsVisitor(set1)); filters[i].getSelect().isEverything(ExpressionVisitor.getColumnsVisitor(set1));
} }
......
...@@ -8,10 +8,10 @@ package org.h2.table; ...@@ -8,10 +8,10 @@ package org.h2.table;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.ExpressionVisitor; import org.h2.expression.ExpressionVisitor;
import org.h2.message.Trace;
import org.h2.table.TableFilter.TableFilterVisitor; import org.h2.table.TableFilter.TableFilterVisitor;
import org.h2.util.New; import org.h2.util.New;
...@@ -106,17 +106,23 @@ public class Plan { ...@@ -106,17 +106,23 @@ public class Plan {
* @return the cost * @return the cost
*/ */
public double calculateCost(Session session) { public double calculateCost(Session session) {
if (session.getTrace().isDebugEnabled()) { Trace t = session.getTrace();
session.getTrace().debug("Plan : calculate cost for plan {0}", Arrays.toString(allFilters)); if (t.isDebugEnabled()) {
t.debug("Plan : calculate cost for plan {0}", Arrays.toString(allFilters));
} }
double cost = 1; double cost = 1;
boolean invalidPlan = false; boolean invalidPlan = false;
for (int i = 0; i < allFilters.length; i++) { for (int i = 0; i < allFilters.length; i++) {
TableFilter tableFilter = allFilters[i]; TableFilter tableFilter = allFilters[i];
session.getTrace().debug("Plan : for table filter {0}", tableFilter); if (t.isDebugEnabled()) {
t.debug("Plan : for table filter {0}", tableFilter);
}
PlanItem item = tableFilter.getBestPlanItem(session, allFilters, i); PlanItem item = tableFilter.getBestPlanItem(session, allFilters, i);
planItems.put(tableFilter, item); planItems.put(tableFilter, item);
session.getTrace().debug("Plan : best plan item cost {0} index {1}", (int)item.cost, item.getIndex().getPlanSQL()); if (t.isDebugEnabled()) {
t.debug("Plan : best plan item cost {0} index {1}",
item.cost, item.getIndex().getPlanSQL());
}
cost += cost * item.cost; cost += cost * item.cost;
setEvaluatable(tableFilter, true); setEvaluatable(tableFilter, true);
Expression on = tableFilter.getJoinCondition(); Expression on = tableFilter.getJoinCondition();
...@@ -130,7 +136,9 @@ public class Plan { ...@@ -130,7 +136,9 @@ public class Plan {
if (invalidPlan) { if (invalidPlan) {
cost = Double.POSITIVE_INFINITY; cost = Double.POSITIVE_INFINITY;
} }
session.getTrace().debug("Plan : plan cost {0}", (int)cost); if (t.isDebugEnabled()) {
session.getTrace().debug("Plan : plan cost {0}", cost);
}
for (TableFilter f : allFilters) { for (TableFilter f : allFilters) {
setEvaluatable(f, false); setEvaluatable(f, false);
} }
......
...@@ -697,13 +697,20 @@ public abstract class Table extends SchemaObjectBase { ...@@ -697,13 +697,20 @@ public abstract class Table extends SchemaObjectBase {
PlanItem item = new PlanItem(); PlanItem item = new PlanItem();
item.setIndex(getScanIndex(session)); item.setIndex(getScanIndex(session));
item.cost = item.getIndex().getCost(session, null, filters, filter, null); item.cost = item.getIndex().getCost(session, null, filters, filter, null);
session.getTrace().debug("Table : potential plan item cost {0} index {1}", item.cost, item.getIndex().getPlanSQL()); Trace t = session.getTrace();
if (t.isDebugEnabled()) {
t.debug("Table : potential plan item cost {0} index {1}",
item.cost, item.getIndex().getPlanSQL());
}
ArrayList<Index> indexes = getIndexes(); ArrayList<Index> indexes = getIndexes();
if (indexes != null && masks != null) { if (indexes != null && masks != null) {
for (int i = 1, size = indexes.size(); i < size; i++) { for (int i = 1, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i); Index index = indexes.get(i);
double cost = index.getCost(session, masks, filters, filter, sortOrder); double cost = index.getCost(session, masks, filters, filter, sortOrder);
session.getTrace().debug("Table : potential plan item cost {0} index {1}", cost, index.getPlanSQL()); if (t.isDebugEnabled()) {
t.debug("Table : potential plan item cost {0} index {1}",
cost, index.getPlanSQL());
}
if (cost < item.cost) { if (cost < item.cost) {
item.cost = cost; item.cost = cost;
item.setIndex(index); item.setIndex(index);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论