Search in sources :

Example 46 with TableFilter

use of org.h2.table.TableFilter in project h2database by h2database.

the class Aggregate method getMinMaxColumnIndex.

private Index getMinMaxColumnIndex() {
    if (on instanceof ExpressionColumn) {
        ExpressionColumn col = (ExpressionColumn) on;
        Column column = col.getColumn();
        TableFilter filter = col.getTableFilter();
        if (filter != null) {
            Table table = filter.getTable();
            return table.getIndexForColumn(column, true, false);
        }
    }
    return null;
}
Also used : Table(org.h2.table.Table) Column(org.h2.table.Column) TableFilter(org.h2.table.TableFilter)

Example 47 with TableFilter

use of org.h2.table.TableFilter in project h2database by h2database.

the class TableView method getBestPlanItem.

@Override
public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) {
    final CacheKey cacheKey = new CacheKey(masks, this);
    Map<Object, ViewIndex> indexCache = session.getViewIndexCache(topQuery != null);
    ViewIndex i = indexCache.get(cacheKey);
    if (i == null || i.isExpired()) {
        i = new ViewIndex(this, index, session, masks, filters, filter, sortOrder);
        indexCache.put(cacheKey, i);
    }
    PlanItem item = new PlanItem();
    item.cost = i.getCost(session, masks, filters, filter, sortOrder, allColumnsSet);
    item.setIndex(i);
    return item;
}
Also used : DbObject(org.h2.engine.DbObject) ViewIndex(org.h2.index.ViewIndex)

Example 48 with TableFilter

use of org.h2.table.TableFilter in project h2database by h2database.

the class Plan method calculateCost.

/**
 * Calculate the cost of this query plan.
 *
 * @param session the session
 * @return the cost
 */
public double calculateCost(Session session) {
    Trace t = session.getTrace();
    if (t.isDebugEnabled()) {
        t.debug("Plan       : calculate cost for plan {0}", Arrays.toString(allFilters));
    }
    double cost = 1;
    boolean invalidPlan = false;
    final HashSet<Column> allColumnsSet = ExpressionVisitor.allColumnsForTableFilters(allFilters);
    for (int i = 0; i < allFilters.length; i++) {
        TableFilter tableFilter = allFilters[i];
        if (t.isDebugEnabled()) {
            t.debug("Plan       :   for table filter {0}", tableFilter);
        }
        PlanItem item = tableFilter.getBestPlanItem(session, allFilters, i, allColumnsSet);
        planItems.put(tableFilter, item);
        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();
        if (on != null) {
            if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
                invalidPlan = true;
                break;
            }
        }
    }
    if (invalidPlan) {
        cost = Double.POSITIVE_INFINITY;
    }
    if (t.isDebugEnabled()) {
        session.getTrace().debug("Plan       : plan cost {0}", cost);
    }
    for (TableFilter f : allFilters) {
        setEvaluatable(f, false);
    }
    return cost;
}
Also used : Trace(org.h2.message.Trace) Expression(org.h2.expression.Expression)

Example 49 with TableFilter

use of org.h2.table.TableFilter in project h2database by h2database.

the class Table method getBestPlanItem.

/**
 * Get the best plan for the given search mask.
 *
 * @param session the session
 * @param masks per-column comparison bit masks, null means 'always false',
 *              see constants in IndexCondition
 * @param filters all joined table filters
 * @param filter the current table filter index
 * @param sortOrder the sort order
 * @param allColumnsSet the set of all columns
 * @return the plan item
 */
public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) {
    PlanItem item = new PlanItem();
    item.setIndex(getScanIndex(session));
    item.cost = item.getIndex().getCost(session, null, filters, filter, null, allColumnsSet);
    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();
    IndexHints indexHints = getIndexHints(filters, filter);
    if (indexes != null && masks != null) {
        for (int i = 1, size = indexes.size(); i < size; i++) {
            Index index = indexes.get(i);
            if (isIndexExcludedByHints(indexHints, index)) {
                continue;
            }
            double cost = index.getCost(session, masks, filters, filter, sortOrder, allColumnsSet);
            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);
            }
        }
    }
    return item;
}
Also used : Trace(org.h2.message.Trace) Index(org.h2.index.Index) Constraint(org.h2.constraint.Constraint)

Example 50 with TableFilter

use of org.h2.table.TableFilter in project h2database by h2database.

the class Parser method parseUpdate.

private Update parseUpdate() {
    Update command = new Update(session);
    currentPrepared = command;
    int start = lastParseIndex;
    TableFilter filter = readSimpleTableFilter(0, null);
    command.setTableFilter(filter);
    parseUpdateSetClause(command, filter, start);
    return command;
}
Also used : TableFilter(org.h2.table.TableFilter) Update(org.h2.command.dml.Update) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Aggregations

TableFilter (org.h2.table.TableFilter)39 IndexColumn (org.h2.table.IndexColumn)21 Column (org.h2.table.Column)20 Expression (org.h2.expression.Expression)18 ValueExpression (org.h2.expression.ValueExpression)14 ExpressionColumn (org.h2.expression.ExpressionColumn)12 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)11 Table (org.h2.table.Table)11 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)9 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)9 Select (org.h2.command.dml.Select)9 ValueString (org.h2.value.ValueString)9 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)6 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)6 CreateTable (org.h2.command.ddl.CreateTable)6 DropTable (org.h2.command.ddl.DropTable)6 Query (org.h2.command.dml.Query)6 IndexCondition (org.h2.index.IndexCondition)6 ArrayList (java.util.ArrayList)5 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)5