private boolean getKeyExpressionCombinations(Pair<Expression, Expression> combination, StatementContext context, SelectStatement select, TableRef table, JoinType type, final List<Expression> joinExpressions, final List<Expression> hashExpressions) throws SQLException { if ((type != JoinType.Inner && type != JoinType.Semi) || this.noChildParentJoinOptimization) return false; Scan scanCopy = ScanUtil.newScan(context.getScan()); StatementContext contextCopy = new StatementContext(statement, context.getResolver(), scanCopy, new SequenceManager(statement)); contextCopy.setCurrentTable(table); List<Expression> lhsCombination = Lists.<Expression> newArrayList(); boolean complete = WhereOptimizer.getKeyExpressionCombination(lhsCombination, contextCopy, select, joinExpressions); if (lhsCombination.isEmpty()) return false; List<Expression> rhsCombination = Lists.newArrayListWithExpectedSize(lhsCombination.size()); for (int i = 0; i < lhsCombination.size(); i++) { Expression lhs = lhsCombination.get(i); for (int j = 0; j < joinExpressions.size(); j++) { if (lhs == joinExpressions.get(j)) { rhsCombination.add(hashExpressions.get(j)); break; } } } if (lhsCombination.size() == 1) { combination.setFirst(lhsCombination.get(0)); combination.setSecond(rhsCombination.get(0)); } else { combination.setFirst(new RowValueConstructorExpression(lhsCombination, false)); combination.setSecond(new RowValueConstructorExpression(rhsCombination, false)); } return type == JoinType.Semi && complete; }
protected QueryPlan compileSingleQuery(StatementContext context, SelectStatement select, List<Object> binds, boolean asSubquery, boolean allowPageFilter) throws SQLException{ SelectStatement innerSelect = select.getInnerSelectStatement(); if (innerSelect == null) { return compileSingleFlatQuery(context, select, binds, asSubquery, allowPageFilter, null, null, true); } QueryPlan innerPlan = compileSubquery(innerSelect, false); TupleProjector tupleProjector = new TupleProjector(innerPlan.getProjector()); innerPlan = new TupleProjectionPlan(innerPlan, tupleProjector, null); // Replace the original resolver and table with those having compiled type info. TableRef tableRef = context.getResolver().getTables().get(0); ColumnResolver resolver = FromCompiler.getResolverForCompiledDerivedTable(statement.getConnection(), tableRef, innerPlan.getProjector()); context.setResolver(resolver); tableRef = resolver.getTables().get(0); context.setCurrentTable(tableRef); boolean isInRowKeyOrder = innerPlan.getGroupBy() == GroupBy.EMPTY_GROUP_BY && innerPlan.getOrderBy() == OrderBy.EMPTY_ORDER_BY; return compileSingleFlatQuery(context, select, binds, asSubquery, allowPageFilter, innerPlan, tupleProjector, isInRowKeyOrder); }
SelectStatement subquery = table.getAsSubquery(orderBy); if (!table.isSubselect()) { context.setCurrentTable(table.getTableRef()); PTable projectedTable = table.createProjectedTable(!projectPKColumns, context); TupleProjector projector = new TupleProjector(projectedTable); context.setCurrentTable(bestPlan.getContext().getCurrentTable()); return bestPlan;
TupleProjector tupleProjector; if (!table.isSubselect()) { context.setCurrentTable(table.getTableRef()); initialProjectedTable = table.createProjectedTable(!projectPKColumns, context); tableRef = table.getTableRef(); context.setCurrentTable(tableRef); PTable projectedTable = initialProjectedTable; int count = joinSpecs.size(); TupleProjector tupleProjector; if (!rhsTable.isSubselect()) { context.setCurrentTable(rhsTable.getTableRef()); rhsProjTable = rhsTable.createProjectedTable(!projectPKColumns, context); rhsTableRef = rhsTable.getTableRef(); context.setCurrentTable(rhsTableRef); context.setResolver(FromCompiler.getResolverForProjectedTable(rhsProjTable, context.getConnection(), rhs.getUdfParseNodes())); ImmutableBytesPtr[] joinIds = new ImmutableBytesPtr[]{new ImmutableBytesPtr(emptyByteArray)}; TableRef tableRef = resolver.getTables().get(0); StatementContext subCtx = new StatementContext(statement, resolver, ScanUtil.newScan(originalScan), new SequenceManager(statement)); subCtx.setCurrentTable(tableRef); QueryPlan innerPlan = new SortMergeJoinPlan(subCtx, joinTable.getStatement(), tableRef, type == JoinType.Right ? JoinType.Left : type, lhsPlan, rhsPlan, lhsKeyExpressions, rhsKeyExpressions, projectedTable, lhsProjTable, needsMerge ? rhsProjTable : null, fieldPosition, lastJoinSpec.isSingleValueOnly()); context.setCurrentTable(tableRef); context.setResolver(resolver); TableNode from = NODE_FACTORY.namedTable(tableRef.getTableAlias(), NODE_FACTORY.table(tableRef.getTable().getSchemaName().getString(), tableRef.getTable().getTableName().getString()));
private boolean getKeyExpressionCombinations(Pair<Expression, Expression> combination, StatementContext context, SelectStatement select, TableRef table, JoinType type, final List<Expression> joinExpressions, final List<Expression> hashExpressions) throws SQLException { if ((type != JoinType.Inner && type != JoinType.Semi) || this.noChildParentJoinOptimization) return false; Scan scanCopy = ScanUtil.newScan(context.getScan()); StatementContext contextCopy = new StatementContext(statement, context.getResolver(), scanCopy, new SequenceManager(statement)); contextCopy.setCurrentTable(table); List<Expression> lhsCombination = Lists.<Expression> newArrayList(); boolean complete = WhereOptimizer.getKeyExpressionCombination(lhsCombination, contextCopy, select, joinExpressions); if (lhsCombination.isEmpty()) return false; List<Expression> rhsCombination = Lists.newArrayListWithExpectedSize(lhsCombination.size()); for (int i = 0; i < lhsCombination.size(); i++) { Expression lhs = lhsCombination.get(i); for (int j = 0; j < joinExpressions.size(); j++) { if (lhs == joinExpressions.get(j)) { rhsCombination.add(hashExpressions.get(j)); break; } } } if (lhsCombination.size() == 1) { combination.setFirst(lhsCombination.get(0)); combination.setSecond(rhsCombination.get(0)); } else { combination.setFirst(new RowValueConstructorExpression(lhsCombination, false)); combination.setSecond(new RowValueConstructorExpression(rhsCombination, false)); } return type == JoinType.Semi && complete; }
private boolean getKeyExpressionCombinations(Pair<Expression, Expression> combination, StatementContext context, SelectStatement select, TableRef table, JoinType type, final List<Expression> joinExpressions, final List<Expression> hashExpressions) throws SQLException { if ((type != JoinType.Inner && type != JoinType.Semi) || this.noChildParentJoinOptimization) return false; Scan scanCopy = ScanUtil.newScan(context.getScan()); StatementContext contextCopy = new StatementContext(statement, context.getResolver(), scanCopy, new SequenceManager(statement)); contextCopy.setCurrentTable(table); List<Expression> lhsCombination = Lists.<Expression> newArrayList(); boolean complete = WhereOptimizer.getKeyExpressionCombination(lhsCombination, contextCopy, select, joinExpressions); if (lhsCombination.isEmpty()) return false; List<Expression> rhsCombination = Lists.newArrayListWithExpectedSize(lhsCombination.size()); for (int i = 0; i < lhsCombination.size(); i++) { Expression lhs = lhsCombination.get(i); for (int j = 0; j < joinExpressions.size(); j++) { if (lhs == joinExpressions.get(j)) { rhsCombination.add(hashExpressions.get(j)); break; } } } if (lhsCombination.size() == 1) { combination.setFirst(lhsCombination.get(0)); combination.setSecond(rhsCombination.get(0)); } else { combination.setFirst(new RowValueConstructorExpression(lhsCombination, false)); combination.setSecond(new RowValueConstructorExpression(rhsCombination, false)); } return type == JoinType.Semi && complete; }
protected QueryPlan compileSingleQuery(StatementContext context, SelectStatement select, List<Object> binds, boolean asSubquery, boolean allowPageFilter) throws SQLException{ SelectStatement innerSelect = select.getInnerSelectStatement(); if (innerSelect == null) { return compileSingleFlatQuery(context, select, binds, asSubquery, allowPageFilter, null, null, true); } QueryPlan innerPlan = compileSubquery(innerSelect, false); TupleProjector tupleProjector = new TupleProjector(innerPlan.getProjector()); innerPlan = new TupleProjectionPlan(innerPlan, tupleProjector, null); // Replace the original resolver and table with those having compiled type info. TableRef tableRef = context.getResolver().getTables().get(0); ColumnResolver resolver = FromCompiler.getResolverForCompiledDerivedTable(statement.getConnection(), tableRef, innerPlan.getProjector()); context.setResolver(resolver); tableRef = resolver.getTables().get(0); context.setCurrentTable(tableRef); boolean isInRowKeyOrder = innerPlan.getGroupBy() == GroupBy.EMPTY_GROUP_BY && innerPlan.getOrderBy() == OrderBy.EMPTY_ORDER_BY; return compileSingleFlatQuery(context, select, binds, asSubquery, allowPageFilter, innerPlan, tupleProjector, isInRowKeyOrder); }
protected QueryPlan compileSingleQuery(StatementContext context, SelectStatement select, List<Object> binds, boolean asSubquery, boolean allowPageFilter) throws SQLException{ SelectStatement innerSelect = select.getInnerSelectStatement(); if (innerSelect == null) { return compileSingleFlatQuery(context, select, binds, asSubquery, allowPageFilter, null, null, true); } QueryPlan innerPlan = compileSubquery(innerSelect, false); TupleProjector tupleProjector = new TupleProjector(innerPlan.getProjector()); innerPlan = new TupleProjectionPlan(innerPlan, tupleProjector, null); // Replace the original resolver and table with those having compiled type info. TableRef tableRef = context.getResolver().getTables().get(0); ColumnResolver resolver = FromCompiler.getResolverForCompiledDerivedTable(statement.getConnection(), tableRef, innerPlan.getProjector()); context.setResolver(resolver); tableRef = resolver.getTables().get(0); context.setCurrentTable(tableRef); boolean isInRowKeyOrder = innerPlan.getGroupBy() == GroupBy.EMPTY_GROUP_BY && innerPlan.getOrderBy() == OrderBy.EMPTY_ORDER_BY; return compileSingleFlatQuery(context, select, binds, asSubquery, allowPageFilter, innerPlan, tupleProjector, isInRowKeyOrder); }
SelectStatement subquery = table.getAsSubquery(orderBy); if (!table.isSubselect()) { context.setCurrentTable(table.getTableRef()); PTable projectedTable = table.createProjectedTable(!projectPKColumns, context); TupleProjector projector = new TupleProjector(projectedTable); context.setCurrentTable(bestPlan.getContext().getCurrentTable()); return bestPlan;
SelectStatement subquery = table.getAsSubquery(orderBy); if (!table.isSubselect()) { context.setCurrentTable(table.getTableRef()); PTable projectedTable = table.createProjectedTable(!projectPKColumns, context); TupleProjector projector = new TupleProjector(projectedTable); context.setCurrentTable(bestPlan.getContext().getCurrentTable()); return bestPlan;
TupleProjector tupleProjector; if (!table.isSubselect()) { context.setCurrentTable(table.getTableRef()); initialProjectedTable = table.createProjectedTable(!projectPKColumns, context); tableRef = table.getTableRef(); context.setCurrentTable(tableRef); PTable projectedTable = initialProjectedTable; int count = joinSpecs.size(); TupleProjector tupleProjector; if (!rhsTable.isSubselect()) { context.setCurrentTable(rhsTable.getTableRef()); rhsProjTable = rhsTable.createProjectedTable(!projectPKColumns, context); rhsTableRef = rhsTable.getTableRef(); context.setCurrentTable(rhsTableRef); context.setResolver(FromCompiler.getResolverForProjectedTable(rhsProjTable, context.getConnection(), rhs.getUdfParseNodes())); ImmutableBytesPtr[] joinIds = new ImmutableBytesPtr[]{new ImmutableBytesPtr(emptyByteArray)}; TableRef tableRef = resolver.getTables().get(0); StatementContext subCtx = new StatementContext(statement, resolver, ScanUtil.newScan(originalScan), new SequenceManager(statement)); subCtx.setCurrentTable(tableRef); QueryPlan innerPlan = new SortMergeJoinPlan(subCtx, joinTable.getStatement(), tableRef, type == JoinType.Right ? JoinType.Left : type, lhsPlan, rhsPlan, lhsKeyExpressions, rhsKeyExpressions, projectedTable, lhsProjTable, needsMerge ? rhsProjTable : null, fieldPosition, lastJoinSpec.isSingleValueOnly()); context.setCurrentTable(tableRef); context.setResolver(resolver); TableNode from = NODE_FACTORY.namedTable(tableRef.getTableAlias(), NODE_FACTORY.table(tableRef.getTable().getSchemaName().getString(), tableRef.getTable().getTableName().getString()));
TupleProjector tupleProjector; if (!table.isSubselect()) { context.setCurrentTable(table.getTableRef()); initialProjectedTable = table.createProjectedTable(!projectPKColumns, context); tableRef = table.getTableRef(); context.setCurrentTable(tableRef); PTable projectedTable = initialProjectedTable; int count = joinSpecs.size(); TupleProjector tupleProjector; if (!rhsTable.isSubselect()) { context.setCurrentTable(rhsTable.getTableRef()); rhsProjTable = rhsTable.createProjectedTable(!projectPKColumns, context); rhsTableRef = rhsTable.getTableRef(); context.setCurrentTable(rhsTableRef); context.setResolver(FromCompiler.getResolverForProjectedTable(rhsProjTable, context.getConnection(), rhs.getUdfParseNodes())); ImmutableBytesPtr[] joinIds = new ImmutableBytesPtr[]{new ImmutableBytesPtr(emptyByteArray)}; TableRef tableRef = resolver.getTables().get(0); StatementContext subCtx = new StatementContext(statement, resolver, ScanUtil.newScan(originalScan), new SequenceManager(statement)); subCtx.setCurrentTable(tableRef); QueryPlan innerPlan = new SortMergeJoinPlan(subCtx, joinTable.getStatement(), tableRef, type == JoinType.Right ? JoinType.Left : type, lhsPlan, rhsPlan, lhsKeyExpressions, rhsKeyExpressions, projectedTable, lhsProjTable, needsMerge ? rhsProjTable : null, fieldPosition, lastJoinSpec.isSingleValueOnly()); context.setCurrentTable(tableRef); context.setResolver(resolver); TableNode from = NODE_FACTORY.namedTable(tableRef.getTableAlias(), NODE_FACTORY.table(tableRef.getTable().getSchemaName().getString(), tableRef.getTable().getTableName().getString()));