提交 dc268c8b authored 作者: Noel Grandin's avatar Noel Grandin

format and remove some debug

上级 1e48ee39
...@@ -160,8 +160,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -160,8 +160,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
* @param sortOrder the sort order * @param sortOrder the sort order
* @return the estimated cost * @return the estimated cost
*/ */
protected final long getCostRangeIndex(int[] masks, long rowCount, protected final long getCostRangeIndex(int[] masks, long rowCount, TableFilter[] filters, int filter,
TableFilter[] filters, int filter, SortOrder sortOrder, boolean isScanIndex) { SortOrder sortOrder, boolean isScanIndex) {
rowCount += Constants.COST_ROW_OFFSET; rowCount += Constants.COST_ROW_OFFSET;
int totalSelectivity = 0; int totalSelectivity = 0;
long rowsCost = rowCount; long rowsCost = rowCount;
...@@ -175,8 +175,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -175,8 +175,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
rowsCost = 3; rowsCost = 3;
break; break;
} }
totalSelectivity = 100 - ((100 - totalSelectivity) * totalSelectivity = 100 - ((100 - totalSelectivity) * (100 - column.getSelectivity()) / 100);
(100 - column.getSelectivity()) / 100);
long distinctRows = rowCount * totalSelectivity / 100; long distinctRows = rowCount * totalSelectivity / 100;
if (distinctRows <= 0) { if (distinctRows <= 0) {
distinctRows = 1; distinctRows = 1;
...@@ -197,10 +196,11 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -197,10 +196,11 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
} }
} }
// If the ORDER BY clause matches the ordering of this index, // If the ORDER BY clause matches the ordering of this index,
// it will be cheaper than another index, so adjust the cost accordingly. // it will be cheaper than another index, so adjust the cost
// accordingly.
long sortingCost = 0; long sortingCost = 0;
if (sortOrder != null) { if (sortOrder != null) {
sortingCost = 100 + rowCount/10; sortingCost = 100 + rowCount / 10;
} }
if (sortOrder != null && !isScanIndex) { if (sortOrder != null && !isScanIndex) {
boolean sortOrderMatches = true; boolean sortOrderMatches = true;
...@@ -239,8 +239,9 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -239,8 +239,9 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
sortingCost = 100 - coveringCount; sortingCost = 100 - coveringCount;
} }
} }
// 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
// without needing to read from the primary table, make that one slightly lower cost. // satisfy the query without needing to read from the primary table,
// make that one slightly lower cost.
boolean needsToReadFromScanIndex = true; boolean needsToReadFromScanIndex = true;
if (!isScanIndex) { if (!isScanIndex) {
HashSet<Column> set1 = New.hashSet(); HashSet<Column> set1 = New.hashSet();
...@@ -268,14 +269,14 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -268,14 +269,14 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
} else if (needsToReadFromScanIndex) { } else if (needsToReadFromScanIndex) {
rc = rowsCost + rowsCost + sortingCost + 20; rc = rowsCost + rowsCost + sortingCost + 20;
} else { } else {
/* The (20-x) calculation makes sure that when we pick a covering index, we pick the covering /*
* index that has the smallest number of columns. This is faster because a smaller index will fit into * The (20-x) calculation makes sure that when we pick a covering
* index, we pick the covering index that has the smallest number of
* columns. This is faster because a smaller index will fit into
* fewer data blocks. * fewer data blocks.
*/ */
rc = rowsCost + sortingCost + (20 - columns.length); rc = rowsCost + sortingCost + (20 - columns.length);
} }
getDatabase().getTrace(0).debug("needsToReadFromScanIndex " + needsToReadFromScanIndex + " isScanIndex "
+ isScanIndex + " rowsCost " + rowsCost + " rowCount " + rowCount + " sortingCost " + sortingCost + " rc " +rc);
return rc; return rc;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论