private void parseJoinTableFilter(TableFilter top, final Select command) { top = readJoin(top, command, false, top.isJoinOuter()); command.addTableFilter(top, true); boolean isOuter = false; while (true) { TableFilter n = top.getNestedJoin(); if (n != null) { n.visit(new TableFilterVisitor() { @Override public void accept(TableFilter f) { TableFilter join = top.getJoin(); if (join == null) { break; isOuter = isOuter | join.isJoinOuter(); if (isOuter) { command.addTableFilter(join, false); } else { Expression on = join.getJoinCondition(); if (on != null) { command.addCondition(on); join.removeJoinCondition(); top.removeJoin(); command.addTableFilter(join, true);
public ConditionExtractor(TableFilter filter) { this.session = filter.getSession(); this.table = filter.getTable(); this.indexConditions = filter.getIndexConditions(); this.doExtract(); }
StringBuilder buff = new StringBuilder(); if (isJoin) { if (filter.isJoinOuter()) { buff.append("LEFT OUTER JOIN "); } else { if (filter.getNestedJoin() != null) { StringBuffer buffNested = new StringBuffer(); TableFilter n = filter.getNestedJoin(); do { buffNested.append(getPlanSQL(n, n != filter.getNestedJoin(), nodeMapping)); buffNested.append('\n'); n = n.getJoin(); } while (n != null); String nested = buffNested.toString(); if (filter.getJoinCondition() == null) { buff.append(StringUtils.unEnclose(filter.getJoinCondition().getSQL())); if (filter.getTableAlias() != null) { buff.append(' ').append(Parser.quoteIdentifier(filter.getTableAlias())); if (filter.getJoinCondition() == null) { buff.append(StringUtils.unEnclose(filter.getJoinCondition().getSQL()));
private void setEvaluatable(TableFilter f, boolean evaluateable) { for (; f != null; f = f.getJoin()) { f.setEvaluatable(f, evaluateable); TableFilter n = f.getNestedJoin(); if (n != null) { setEvaluatable(n, evaluateable); } } }
private TableFilter getNested(TableFilter n) { String joinTable = Constants.PREFIX_JOIN + parseIndex; TableFilter top = new TableFilter(session, getDualTable(true), joinTable, rightsChecked, currentSelect); top.addJoin(n, false, true, null); return top; }
private void setEvaluatableRecursive(TableFilter f) { for (; f != null; f = f.getJoin()) { f.setEvaluatable(f, true); if (condition != null) { condition.setEvaluatable(f, true); TableFilter n = f.getNestedJoin(); if (n != null) { setEvaluatableRecursive(n); Expression on = f.getJoinCondition(); if (on != null) { if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) { if (!f.isJoinOuter() && !f.isJoinOuterIndirect()) { f.removeJoinCondition(); addCondition(on); if (f.isJoinOuter()) { f.removeJoinCondition(); on = f.getFilterCondition(); if (on != null) { if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) { f.removeFilterCondition(); addCondition(on);
private void setEvaluatable(TableFilter join) { if (session.getDatabase().getSettings().nestedJoins) { setEvaluatable(true); return; } // this table filter is now evaluatable - in all sub-joins do { Expression e = join.getJoinCondition(); if (e != null) { e.setEvaluatable(this, true); } TableFilter n = join.getNestedJoin(); if (n != null) { setEvaluatable(n); } join = join.getJoin(); } while (join != null); }
protected static ArrayList<TableFilter> filterNotTableMate(TableFilter f) { ArrayList<TableFilter> result = New.arrayList(); do { if (f.isFromTableMate()) { result.add(f); } TableFilter n = f.getNestedJoin(); if (n != null) { result.addAll(filterNotTableMate(n)); } f = f.getJoin(); } while (f != null); return result; }
@Override public SQLTranslated translate(Column[] searchColumns, TableFilter filter, ObjectNode node) { // can not use the field sqlStatement because the parameter // indexes may be incorrect: ? may be in fact ?2 for a subquery // but indexes may be set manually as well if (node instanceof GroupObjectNode) { return translate(searchColumns, filter, (GroupObjectNode) node); } List<Value> params = New.arrayList(10); StatementBuilder buff = new StatementBuilder("SELECT"); int visibleColumnCount = searchColumns.length; for (int i = 0; i < visibleColumnCount; i++) { buff.appendExceptFirst(","); buff.append(' '); buff.append(identifier(searchColumns[i].getName())); } buff.append(" FROM "); buff.append(identifier(node.getCompositeObjectName())); buff.append(" AS "); buff.append(filter.getTableAlias()); Expression condition = filter.getFilterCondition(); if (condition != null) { buff.append(" WHERE ").append(StringUtils.unEnclose(condition.getPreparedSQL(filter.getSession(), params))); } return SQLTranslated.build().sql(buff.toString()).sqlParams(params); }
newTop.addJoin(top, true, false, on); } else { newTop.addJoin(top, true, false, on); top.addJoin(join, true, false, on); last = join; } else if (readIf("FULL")) { top.addJoin(join, false, false, on); } else { top.addJoin(join, fromOuter, false, on); top.addJoin(join, false, false, on); } else { top.addJoin(join, fromOuter, false, on); TableFilter join = readTableFilter(fromOuter); if (nestedJoins) { top.addJoin(join, false, false, null); } else { top.addJoin(join, fromOuter, false, null); joined = true; TableFilter join = readTableFilter(fromOuter); Column[] tableCols = last.getTable().getColumns(); Column[] joinCols = join.getTable().getColumns(); String tableSchema = last.getTable().getSchema().getName(); String joinSchema = join.getTable().getSchema().getName(); Expression on = null;
topTableFilter.startQuery(session); topTableFilter.reset(); boolean exclusive = isForUpdate && !isForUpdateMvcc; if (isForUpdateMvcc) { } else if (distinct) { throw DbException.getUnsupportedException("MVCC=TRUE && FOR UPDATE && DISTINCT"); } else if (topTableFilter.getJoin() != null) { throw DbException.getUnsupportedException("MVCC=TRUE && FOR UPDATE && JOIN"); topTableFilter.lock(session, exclusive, exclusive); ResultTarget to = result != null ? result : target; if (limitRows != 0) {
private int expandColumnList(TableFilter filter, int index) { Table t = filter.getTable(); String alias = filter.getTableAlias(); Column[] columns = t.getColumns(); for (Column c : columns) { if (filter.isNaturalJoinColumn(c)) { continue; } ExpressionColumn ec = new ExpressionColumn(session.getDatabase(), null, alias, c.getName()); expressions.add(index++, ec); } return index; }
/** * Remove all index conditions that can not be used. */ public void removeUnusableIndexConditions() { for (int i = 0; i < allFilters.length; i++) { TableFilter f = allFilters[i]; setEvaluatable(f, true); if (i < allFilters.length - 1 || f.getSession().getDatabase().getSettings().earlyFilter) { // the last table doesn't need the optimization, // otherwise the expression is calculated twice unnecessarily // (not that bad but not optimal) f.optimizeFullCondition(false); } f.removeUnusableIndexConditions(); } for (TableFilter f : allFilters) { setEvaluatable(f, false); } }
columnName = readColumnIdentifier(); if (!equalsToken(schema, filter.getTable().getSchema() .getName())) { throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schema); if (!equalsToken(tableAlias, filter.getTableAlias())) { throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableAlias); return filter.getRowIdColumn(); return filter.getTable().getColumn(columnName);
if (!f.isJoinOuter() && !f.isJoinOuterIndirect()) { condition.createIndexConditions(session, f);
TableFilter n = nestedJoin; do { buffNested.append(n.getPlanSQL(n != nestedJoin)); buffNested.append('\n'); n = n.getJoin(); } while (n != null); String nested = buffNested.toString();
private boolean isNestedJoinTable(TableFilter f) { return f.getTable() instanceof RangeTable && StringUtils.startsWith(f.getTableAlias(), Constants.PREFIX_JOIN); }
leftCol.mapColumns(f, 0); rightCol.mapColumns(f, 0); f = f.getJoin(); if (idx >= 0) { filters.remove(idx); leftFilter.addJoin(rightFilter, true, false, r); } else { rightFilter.mapAndAddFilter(r);
private ArrayList<IndexCondition> getIndexConditions(TableFilter filter) { ArrayList<IndexCondition> indexConditions = filter.getIndexConditions(); if(joinCond.isEmpty()) { return indexConditions; } ArrayList<IndexCondition> original = New.arrayList(indexConditions); ArrayList<IndexCondition> result; try { for (Expression cond : joinCond) { //add to indexConditions cond.createIndexConditions(filter.getSession(), filter); } result = New.arrayList(indexConditions); return result; } finally { indexConditions.clear(); indexConditions.addAll(original); } }
TableFilter filter = null; for (TableFilter f : filters) { if (db.equalsIdentifiers(tableAlias, f.getTableAlias())) { if (schemaName == null || db.equalsIdentifiers(schemaName, f.getSchemaName())) { filter = f; break;