Search in sources :

Example 1 with ObjectStatisticsImpl

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;
}
Also used : StatisticsColumnLocalDataViewWalker(org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnLocalDataViewWalker) F(org.apache.ignite.internal.util.typedef.F) List(java.util.List) ObjectStatisticsImpl(org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl) Map(java.util.Map) IgniteStatisticsRepository(org.apache.ignite.internal.processors.query.stat.IgniteStatisticsRepository) StatisticsColumnPartitionDataViewWalker(org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnPartitionDataViewWalker) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ColumnStatistics(org.apache.ignite.internal.processors.query.stat.ColumnStatistics) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) ColumnStatistics(org.apache.ignite.internal.processors.query.stat.ColumnStatistics) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) ArrayList(java.util.ArrayList) ObjectStatisticsImpl(org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl) Map(java.util.Map)

Example 2 with ObjectStatisticsImpl

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;
}
Also used : TableFilter(org.h2.table.TableFilter) Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) IndexCondition(org.h2.index.IndexCondition) ObjectStatisticsImpl(org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl)

Aggregations

ObjectStatisticsImpl (org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 StatisticsColumnLocalDataViewWalker (org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnLocalDataViewWalker)1 StatisticsColumnPartitionDataViewWalker (org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnPartitionDataViewWalker)1 ColumnStatistics (org.apache.ignite.internal.processors.query.stat.ColumnStatistics)1 IgniteStatisticsRepository (org.apache.ignite.internal.processors.query.stat.IgniteStatisticsRepository)1 StatisticsKey (org.apache.ignite.internal.processors.query.stat.StatisticsKey)1 F (org.apache.ignite.internal.util.typedef.F)1 IndexCondition (org.h2.index.IndexCondition)1 Column (org.h2.table.Column)1 IndexColumn (org.h2.table.IndexColumn)1 TableFilter (org.h2.table.TableFilter)1