Search in sources :

Example 11 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class Optimizer method calculateBruteForceSome.

private void calculateBruteForceSome() {
    int bruteForce = getMaxBruteForceFilters(filters.length);
    TableFilter[] list = new TableFilter[filters.length];
    Permutations<TableFilter> p = Permutations.create(filters, list, bruteForce);
    for (int x = 0; !canStop(x) && p.next(); x++) {
        // find out what filters are not used yet
        for (TableFilter f : filters) {
            f.setUsed(false);
        }
        for (int i = 0; i < bruteForce; i++) {
            list[i].setUsed(true);
        }
        // fill the remaining elements with the unused elements (greedy)
        for (int i = bruteForce; i < filters.length; i++) {
            double costPart = -1.0;
            int bestPart = -1;
            for (int j = 0; j < filters.length; j++) {
                if (!filters[j].isUsed()) {
                    if (i == filters.length - 1) {
                        bestPart = j;
                        break;
                    }
                    list[i] = filters[j];
                    Plan part = new Plan(list, i + 1, condition);
                    double costNow = part.calculateCost(session);
                    if (costPart < 0 || costNow < costPart) {
                        costPart = costNow;
                        bestPart = j;
                    }
                }
            }
            filters[bestPart].setUsed(true);
            list[i] = filters[bestPart];
        }
        testPlan(list);
    }
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Plan(com.wplatform.ddal.dbobject.table.Plan)

Example 12 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class UpdateExecutor method executeUpdate.

@Override
public int executeUpdate() {
    TableFilter tableFilter = prepared.getTableFilter();
    TableMate table = castTableMate(tableFilter.getTable());
    List<Column> columns = prepared.getColumns();
    Map<Column, Expression> valueMap = prepared.getExpressionMap();
    table.check();
    session.getUser().checkRight(table, Right.UPDATE);
    Row updateRow = table.getTemplateRow();
    for (int i = 0, size = columns.size(); i < size; i++) {
        Column c = columns.get(i);
        Expression e = valueMap.get(c);
        int index = c.getColumnId();
        if (e != null) {
            // e can be null (DEFAULT)
            e = e.optimize(session);
            try {
                Value v = c.convert(e.getValue(session));
                updateRow.setValue(index, v);
            } catch (DbException ex) {
                ex.addSQL("evaluate expression " + e.getSQL());
                throw ex;
            }
        }
    }
    return updateRow(table, updateRow, tableFilter.getIndexConditions());
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Column(com.wplatform.ddal.dbobject.table.Column) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value) TableMate(com.wplatform.ddal.dbobject.table.TableMate) Row(com.wplatform.ddal.result.Row) SearchRow(com.wplatform.ddal.result.SearchRow) DbException(com.wplatform.ddal.message.DbException)

Example 13 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class DeleteExecutor method doTranslate.

@Override
protected List<Value> doTranslate(TableNode node, SearchRow row, StatementBuilder buff) {
    ArrayList<Value> params = New.arrayList();
    TableFilter tableFilter = prepared.getTableFilter();
    String forTable = node.getCompositeObjectName();
    Expression condition = prepared.getCondition();
    Expression limitExpr = prepared.getLimitExpr();
    buff.append("DELETE FROM ");
    buff.append(identifier(forTable));
    if (condition != null) {
        condition.exportParameters(tableFilter, params);
        buff.append(" WHERE ").append(StringUtils.unEnclose(condition.getSQL()));
    }
    if (limitExpr != null) {
        limitExpr.exportParameters(tableFilter, params);
        buff.append(" LIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL()));
    }
    return params;
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value)

Aggregations

TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)13 Expression (com.wplatform.ddal.command.expression.Expression)4 Column (com.wplatform.ddal.dbobject.table.Column)3 Value (com.wplatform.ddal.value.Value)3 TableMate (com.wplatform.ddal.dbobject.table.TableMate)2 Index (com.wplatform.ddal.dbobject.index.Index)1 IndexCondition (com.wplatform.ddal.dbobject.index.IndexCondition)1 Plan (com.wplatform.ddal.dbobject.table.Plan)1 PlanItem (com.wplatform.ddal.dbobject.table.PlanItem)1 Table (com.wplatform.ddal.dbobject.table.Table)1 Database (com.wplatform.ddal.engine.Database)1 DbException (com.wplatform.ddal.message.DbException)1 Row (com.wplatform.ddal.result.Row)1 SearchRow (com.wplatform.ddal.result.SearchRow)1 BitField (com.wplatform.ddal.util.BitField)1 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)1