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

BaseIndex.getCostRangeIndex changed to accept TableFilter[]

上级 13fd5a10
...@@ -152,12 +152,13 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -152,12 +152,13 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
* *
* @param masks the search mask * @param masks the search mask
* @param rowCount the number of rows in the index * @param rowCount the number of rows in the index
* @param filter the table filter * @param filters all joined table filters
* @param filter the current table filter index
* @param sortOrder the sort order * @param sortOrder the sort order
* @return the estimated cost * @return the estimated cost
*/ */
protected long getCostRangeIndex(int[] masks, long rowCount, protected long getCostRangeIndex(int[] masks, long rowCount,
TableFilter filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
rowCount += Constants.COST_ROW_OFFSET; rowCount += Constants.COST_ROW_OFFSET;
long cost = rowCount; long cost = rowCount;
long rows = rowCount; long rows = rowCount;
...@@ -201,6 +202,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -201,6 +202,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
boolean sortOrderMatches = true; boolean sortOrderMatches = true;
int coveringCount = 0; int coveringCount = 0;
int[] sortTypes = sortOrder.getSortTypes(); int[] sortTypes = sortOrder.getSortTypes();
TableFilter tableFilter = filters == null ? null : filters[filter];
for (int i = 0, len = sortTypes.length; i < len; i++) { for (int i = 0, len = sortTypes.length; i < len; i++) {
if (i >= indexColumns.length) { if (i >= indexColumns.length) {
// we can still use this index if we are sorting by more // we can still use this index if we are sorting by more
...@@ -209,7 +211,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -209,7 +211,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
// more of the order by columns // more of the order by columns
break; break;
} }
Column col = sortOrder.getColumn(i, filter); Column col = sortOrder.getColumn(i, tableFilter);
if (col == null) { if (col == null) {
sortOrderMatches = false; sortOrderMatches = false;
break; break;
......
...@@ -144,7 +144,7 @@ public class LinkedIndex extends BaseIndex { ...@@ -144,7 +144,7 @@ public class LinkedIndex extends BaseIndex {
public double getCost(Session session, int[] masks, public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return 100 + getCostRangeIndex(masks, rowCount + return 100 + getCostRangeIndex(masks, rowCount +
Constants.COST_ROW_OFFSET, filters == null ? null : filters[filter], sortOrder); Constants.COST_ROW_OFFSET, filters, filter, sortOrder);
} }
@Override @Override
......
...@@ -58,7 +58,7 @@ public class MetaIndex extends BaseIndex { ...@@ -58,7 +58,7 @@ public class MetaIndex extends BaseIndex {
return 10 * MetaTable.ROW_COUNT_APPROXIMATION; return 10 * MetaTable.ROW_COUNT_APPROXIMATION;
} }
return getCostRangeIndex(masks, MetaTable.ROW_COUNT_APPROXIMATION, return getCostRangeIndex(masks, MetaTable.ROW_COUNT_APPROXIMATION,
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} }
@Override @Override
......
...@@ -220,7 +220,7 @@ public class PageBtreeIndex extends PageIndex { ...@@ -220,7 +220,7 @@ public class PageBtreeIndex extends PageIndex {
public double getCost(Session session, int[] masks, public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return 10 * getCostRangeIndex(masks, tableData.getRowCount(session), return 10 * getCostRangeIndex(masks, tableData.getRowCount(session),
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} }
@Override @Override
......
...@@ -99,7 +99,7 @@ public class PageDelegateIndex extends PageIndex { ...@@ -99,7 +99,7 @@ public class PageDelegateIndex extends PageIndex {
public double getCost(Session session, int[] masks, public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return 10 * getCostRangeIndex(masks, mainIndex.getRowCount(session), return 10 * getCostRangeIndex(masks, mainIndex.getRowCount(session),
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} }
@Override @Override
......
...@@ -180,7 +180,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex { ...@@ -180,7 +180,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
@Override @Override
protected long getCostRangeIndex(int[] masks, long rowCount, protected long getCostRangeIndex(int[] masks, long rowCount,
TableFilter filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return getCostRangeIndex(masks, rowCount, columns); return getCostRangeIndex(masks, rowCount, columns);
} }
...@@ -211,7 +211,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex { ...@@ -211,7 +211,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
public double getCost(Session session, int[] masks, public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return getCostRangeIndex(masks, table.getRowCountApproximation(), return getCostRangeIndex(masks, table.getRowCountApproximation(),
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} }
@Override @Override
......
...@@ -321,7 +321,7 @@ public class TreeIndex extends BaseIndex { ...@@ -321,7 +321,7 @@ public class TreeIndex extends BaseIndex {
public double getCost(Session session, int[] masks, TableFilter[] filters, int filter, public double getCost(Session session, int[] masks, TableFilter[] filters, int filter,
SortOrder sortOrder) { SortOrder sortOrder) {
return getCostRangeIndex(masks, tableData.getRowCountApproximation(), return getCostRangeIndex(masks, tableData.getRowCountApproximation(),
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} }
@Override @Override
......
...@@ -91,7 +91,7 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex { ...@@ -91,7 +91,7 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
public double getCost(Session session, int[] masks, public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return 10 * getCostRangeIndex(masks, mainIndex.getRowCountApproximation(), return 10 * getCostRangeIndex(masks, mainIndex.getRowCountApproximation(),
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} }
@Override @Override
......
...@@ -355,7 +355,7 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -355,7 +355,7 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
try { try {
return 10 * getCostRangeIndex(masks, dataMap.sizeAsLongMax(), return 10 * getCostRangeIndex(masks, dataMap.sizeAsLongMax(),
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
throw DbException.get(ErrorCode.OBJECT_CLOSED, e); throw DbException.get(ErrorCode.OBJECT_CLOSED, e);
} }
......
...@@ -240,12 +240,12 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex { ...@@ -240,12 +240,12 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
public double getCost(Session session, int[] masks, public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return getCostRangeIndex(masks, table.getRowCountApproximation(), return getCostRangeIndex(masks, table.getRowCountApproximation(),
filters == null ? null : filters[filter], sortOrder); filters, filter, sortOrder);
} }
@Override @Override
protected long getCostRangeIndex(int[] masks, long rowCount, protected long getCostRangeIndex(int[] masks, long rowCount,
TableFilter filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return SpatialTreeIndex.getCostRangeIndex(masks, rowCount, columns); return SpatialTreeIndex.getCostRangeIndex(masks, rowCount, columns);
} }
......
...@@ -1206,8 +1206,7 @@ public class TestTableEngines extends TestBase { ...@@ -1206,8 +1206,7 @@ public class TestTableEngines extends TestBase {
@Override @Override
public double getCost(Session session, int[] masks, public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder) { TableFilter[] filters, int filter, SortOrder sortOrder) {
return getCostRangeIndex(masks, set.size(), filters == null ? return getCostRangeIndex(masks, set.size(), filters, filter, sortOrder);
null : filters[filter], sortOrder);
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论