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

Checkstyle fixes + trace.isDebugEnabled() check added.

上级 d6f7374e
......@@ -240,23 +240,23 @@ 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
// without needing to read from the primary table, make that one slightly lower cost
HashSet<Column> set1 = New.hashSet();
for (int i=0; i < filters.length; i++) {
if (filters[i].getSelect() != null) {
filters[i].getSelect().isEverything(ExpressionVisitor.getColumnsVisitor(set1));
}
HashSet<Column> set1 = New.hashSet();
for (int i = 0; i < filters.length; i++) {
if (filters[i].getSelect() != null) {
filters[i].getSelect().isEverything(ExpressionVisitor.getColumnsVisitor(set1));
}
}
if (!set1.isEmpty()) {
HashSet<Column> set2 = New.hashSet();
for (Column c : set1) {
if (c.getTable() == getTable()) {
set2.add(c);
}
}
set2.removeAll(Arrays.asList(getColumns()));
if (set2.isEmpty()) {
cost -= 1;
}
HashSet<Column> set2 = New.hashSet();
for (Column c : set1) {
if (c.getTable() == getTable()) {
set2.add(c);
}
}
set2.removeAll(Arrays.asList(getColumns()));
if (set2.isEmpty()) {
cost -= 1;
}
}
return cost;
}
......
......@@ -8,10 +8,10 @@ package org.h2.table;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.ExpressionVisitor;
import org.h2.message.Trace;
import org.h2.table.TableFilter.TableFilterVisitor;
import org.h2.util.New;
......@@ -106,17 +106,23 @@ public class Plan {
* @return the cost
*/
public double calculateCost(Session session) {
if (session.getTrace().isDebugEnabled()) {
session.getTrace().debug("Plan : calculate cost for plan {0}", Arrays.toString(allFilters));
}
Trace t = session.getTrace();
if (t.isDebugEnabled()) {
t.debug("Plan : calculate cost for plan {0}", Arrays.toString(allFilters));
}
double cost = 1;
boolean invalidPlan = false;
for (int i = 0; i < allFilters.length; 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);
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;
setEvaluatable(tableFilter, true);
Expression on = tableFilter.getJoinCondition();
......@@ -130,7 +136,9 @@ public class Plan {
if (invalidPlan) {
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) {
setEvaluatable(f, false);
}
......
......@@ -697,13 +697,20 @@ public abstract class Table extends SchemaObjectBase {
PlanItem item = new PlanItem();
item.setIndex(getScanIndex(session));
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();
if (indexes != null && masks != null) {
for (int i = 1, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
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) {
item.cost = cost;
item.setIndex(index);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论