Search in sources :

Example 1 with SelectUnion

use of org.h2.command.dml.SelectUnion in project ignite by apache.

the class GridSqlQueryParser method collectOptimizedTableFiltersOrder.

/**
     * @param qry Query.
     */
private void collectOptimizedTableFiltersOrder(Query qry) {
    if (qry instanceof SelectUnion) {
        collectOptimizedTableFiltersOrder(((SelectUnion) qry).getLeft());
        collectOptimizedTableFiltersOrder(((SelectUnion) qry).getRight());
    } else {
        Select select = (Select) qry;
        TableFilter filter = select.getTopTableFilter();
        int i = 0;
        do {
            assert0(filter != null, select);
            assert0(filter.getNestedJoin() == null, select);
            // Here all the table filters must have generated unique aliases,
            // thus we can store them in the same map for all the subqueries.
            optimizedTableFilterOrder.put(filter.getTableAlias(), i++);
            Table tbl = filter.getTable();
            // Go down and collect inside of optimized subqueries.
            if (tbl instanceof TableView) {
                ViewIndex viewIdx = (ViewIndex) filter.getIndex();
                collectOptimizedTableFiltersOrder(viewIdx.getQuery());
            }
            filter = filter.getJoin();
        } while (filter != null);
    }
}
Also used : SelectUnion(org.h2.command.dml.SelectUnion) RangeTable(org.h2.table.RangeTable) CreateTable(org.h2.command.ddl.CreateTable) FunctionTable(org.h2.table.FunctionTable) Table(org.h2.table.Table) DropTable(org.h2.command.ddl.DropTable) TableFilter(org.h2.table.TableFilter) ConditionInSelect(org.h2.expression.ConditionInSelect) Select(org.h2.command.dml.Select) ViewIndex(org.h2.index.ViewIndex) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) TableView(org.h2.table.TableView)

Example 2 with SelectUnion

use of org.h2.command.dml.SelectUnion in project ignite by apache.

the class GridH2CollocationModel method buildCollocationModel.

/**
     * @param upper Upper.
     * @param filter Filter.
     * @param qry Query.
     * @param unions Unions.
     * @param validate Query validation flag.
     * @return Built model.
     */
private static GridH2CollocationModel buildCollocationModel(GridH2CollocationModel upper, int filter, Query qry, List<GridH2CollocationModel> unions, boolean validate) {
    if (qry.isUnion()) {
        if (unions == null)
            unions = new ArrayList<>();
        SelectUnion union = (SelectUnion) qry;
        GridH2CollocationModel left = buildCollocationModel(upper, filter, union.getLeft(), unions, validate);
        GridH2CollocationModel right = buildCollocationModel(upper, filter, union.getRight(), unions, validate);
        assert left != null;
        assert right != null;
        return upper != null ? upper : left;
    }
    Select select = (Select) qry;
    List<TableFilter> list = new ArrayList<>();
    for (TableFilter f = select.getTopTableFilter(); f != null; f = f.getJoin()) list.add(f);
    TableFilter[] filters = list.toArray(new TableFilter[list.size()]);
    GridH2CollocationModel cm = createChildModel(upper, filter, unions, true, validate);
    cm.childFilters(filters);
    for (int i = 0; i < filters.length; i++) {
        TableFilter f = filters[i];
        if (f.getTable().isView())
            buildCollocationModel(cm, i, getSubQuery(f), null, validate);
        else if (f.getTable() instanceof GridH2Table)
            createChildModel(cm, i, null, false, validate);
    }
    return upper != null ? upper : cm;
}
Also used : SelectUnion(org.h2.command.dml.SelectUnion) TableFilter(org.h2.table.TableFilter) ArrayList(java.util.ArrayList) Select(org.h2.command.dml.Select)

Aggregations

Select (org.h2.command.dml.Select)2 SelectUnion (org.h2.command.dml.SelectUnion)2 TableFilter (org.h2.table.TableFilter)2 ArrayList (java.util.ArrayList)1 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)1 CreateTable (org.h2.command.ddl.CreateTable)1 DropTable (org.h2.command.ddl.DropTable)1 ConditionInSelect (org.h2.expression.ConditionInSelect)1 ViewIndex (org.h2.index.ViewIndex)1 FunctionTable (org.h2.table.FunctionTable)1 RangeTable (org.h2.table.RangeTable)1 Table (org.h2.table.Table)1 TableView (org.h2.table.TableView)1