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);
}
}
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());
}
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;
}
Aggregations