use of org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl in project ignite by apache.
the class ColumnLocalDataViewSupplier method columnLocalStatisticsViewSupplier.
/**
* Statistics column local node data view filterable supplier.
*
* @param filter Filter.
* @return Iterable with statistics column local node data views.
*/
public Iterable<StatisticsColumnLocalDataView> columnLocalStatisticsViewSupplier(Map<String, Object> filter) {
String type = (String) filter.get(StatisticsColumnPartitionDataViewWalker.TYPE_FILTER);
if (type != null && !StatisticsColumnConfigurationView.TABLE_TYPE.equalsIgnoreCase(type))
return Collections.emptyList();
String schema = (String) filter.get(StatisticsColumnLocalDataViewWalker.SCHEMA_FILTER);
String name = (String) filter.get(StatisticsColumnLocalDataViewWalker.NAME_FILTER);
String column = (String) filter.get(StatisticsColumnPartitionDataViewWalker.COLUMN_FILTER);
Map<StatisticsKey, ObjectStatisticsImpl> locStatsMap;
if (!F.isEmpty(schema) && !F.isEmpty(name)) {
StatisticsKey key = new StatisticsKey(schema, name);
ObjectStatisticsImpl objLocStat = repo.getLocalStatistics(key);
if (objLocStat == null)
return Collections.emptyList();
locStatsMap = Collections.singletonMap(key, objLocStat);
} else
locStatsMap = repo.localStatisticsMap().entrySet().stream().filter(e -> F.isEmpty(schema) || schema.equals(e.getKey().schema())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
List<StatisticsColumnLocalDataView> res = new ArrayList<>();
for (Map.Entry<StatisticsKey, ObjectStatisticsImpl> localStatsEntry : locStatsMap.entrySet()) {
StatisticsKey key = localStatsEntry.getKey();
ObjectStatisticsImpl stat = localStatsEntry.getValue();
if (column == null) {
for (Map.Entry<String, ColumnStatistics> colStat : localStatsEntry.getValue().columnsStatistics().entrySet()) {
StatisticsColumnLocalDataView colStatView = new StatisticsColumnLocalDataView(key, colStat.getKey(), stat);
res.add(colStatView);
}
} else {
ColumnStatistics colStat = localStatsEntry.getValue().columnStatistics(column);
if (colStat != null) {
StatisticsColumnLocalDataView colStatView = new StatisticsColumnLocalDataView(key, column, stat);
res.add(colStatView);
}
}
}
return res;
}
use of org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl in project ignite by apache.
the class H2IndexCostedBase method getCostRangeIndex.
/**
* Get cost range.
*
* @param ses Session.
* @param masks Condition masks.
* @param rowCount Total row count.
* @param filters Filters array.
* @param filter Filter array index.
* @param sortOrder Sort order.
* @param isScanIndex Flag if current index is a scan index.
* @param allColumnsSet All columns to select.
* @return The cost.
*/
public long getCostRangeIndex(Session ses, int[] masks, long rowCount, TableFilter[] filters, int filter, SortOrder sortOrder, boolean isScanIndex, HashSet<Column> allColumnsSet) {
ObjectStatisticsImpl locTblStats = (ObjectStatisticsImpl) tbl.tableStatistics();
if (locTblStats != null)
rowCount = locTblStats.rowCount();
// Small increment to account statistics outdates.
rowCount += 1000;
TableFilter tableFilter = (filters == null) ? null : filters[filter];
long rowsCost = rowCost(ses, tableFilter, masks, rowCount, locTblStats);
// If the ORDER BY clause matches the ordering of this index,
// it will be cheaper than another index, so adjust the cost
// accordingly.
long sortingCost = sortingCost(rowCount, filters, filter, sortOrder, isScanIndex);
boolean skipColumnsIntersection = false;
if (filters != null && tableFilter != null && columns != null) {
skipColumnsIntersection = true;
ArrayList<IndexCondition> idxConds = tableFilter.getIndexConditions();
// Only pk with _key used.
if (F.isEmpty(idxConds))
skipColumnsIntersection = false;
for (IndexCondition cond : idxConds) {
if (cond.getColumn() == columns[0]) {
skipColumnsIntersection = false;
break;
}
}
}
// 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
// (scan index), make that one slightly lower cost.
boolean needsToReadFromScanIndex = true;
if (!isScanIndex && allColumnsSet != null && !skipColumnsIntersection && !allColumnsSet.isEmpty()) {
boolean foundAllColumnsWeNeed = true;
for (Column c : allColumnsSet) {
boolean found = false;
for (Column c2 : columns) {
if (c == c2) {
found = true;
break;
}
}
if (!found) {
foundAllColumnsWeNeed = false;
break;
}
}
if (foundAllColumnsWeNeed)
needsToReadFromScanIndex = false;
}
long rc;
if (isScanIndex)
rc = rowsCost + sortingCost + 20;
else if (needsToReadFromScanIndex)
rc = rowsCost + rowsCost + sortingCost + 20;
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 (the more columns we have in index - the higher cost).
// This is faster because a smaller index will fit into fewer data
// blocks.
rc = rowsCost + sortingCost + columns.length;
return rc;
}
Aggregations