internal static List <SelectExpression> Gather(Expression source) { RedundantSubqueryGatherer gatherer = new RedundantSubqueryGatherer(); gatherer.Visit(source); return(gatherer.redundant); }
protected override Expression VisitSelect(SelectExpression select) { select = (SelectExpression)base.VisitSelect(select); List <SelectExpression> selectsToRemove = RedundantSubqueryGatherer.Gather(select.From); if (selectsToRemove != null) { select = SubqueryRemover.Remove(select, selectsToRemove); } return(select); }
public static List <DbSelectExpression> Gather(Expression source) { var gatherer = new RedundantSubqueryGatherer(); if (gatherer != null) { gatherer.Visit(source); } return(gatherer.redundant); }
protected override Expression VisitProjection(ProjectionExpression proj) { proj = (ProjectionExpression)base.VisitProjection(proj); if (proj.Source.From is SelectExpression) { List <SelectExpression> redundant = RedundantSubqueryGatherer.Gather(proj.Source); if (redundant != null) { proj = SubqueryRemover.Remove(proj, redundant); } } return(proj); }
protected override Expression VisitProjection(ProjectionExpression proj) { proj = (ProjectionExpression)base.VisitProjection(proj); if (proj.Select.From is SelectExpression) { List <SelectExpression> selectsToRemove = RedundantSubqueryGatherer.Gather(proj.Select); if (selectsToRemove != null) { proj = SubqueryRemover.Remove(proj, selectsToRemove); } } return(proj); }
protected override Expression VisitSelect(DbSelectExpression select) { select = base.VisitSelect(select) as DbSelectExpression; var redundant = RedundantSubqueryGatherer.Gather(select.From); if (redundant != null) { select = DbSubqueryRemover.Remove(select, redundant); } return(select); }
protected override Expression VisitSelect(SelectExpression select) { select = (SelectExpression)base.VisitSelect(select); // first remove all purely redundant subqueries List <SelectExpression> redundant = RedundantSubqueryGatherer.Gather(select.From); if (redundant != null) { select = SubqueryRemover.Remove(select, redundant); } return(select); }
protected override Expression VisitProjection(DbProjectionExpression proj) { proj = base.VisitProjection(proj) as DbProjectionExpression; if (proj.Select.From is DbSelectExpression) { var redundant = RedundantSubqueryGatherer.Gather(proj.Select); if (redundant != null) { proj = DbSubqueryRemover.Remove(proj, redundant); } } return(proj); }
protected override Expression VisitSelect(SelectExpression select) { select = (SelectExpression)base.VisitSelect(select); // first remove all purely redundant subqueries List <SelectExpression> redundant = new RedundantSubqueryGatherer().Gather(select.From); if (redundant != null) { select = (SelectExpression) new SubqueryRemover().Remove(select, redundant); } // next attempt to merge subqueries // can only merge if subquery is a single select (not a join) SelectExpression fromSelect = select.From as SelectExpression; if (fromSelect != null) { // can only merge if subquery has simple-projection (no renames or complex expressions) if (HasSimpleProjection(fromSelect)) { // remove the redundant subquery select = (SelectExpression) new SubqueryRemover().Remove(select, fromSelect); // merge where expressions Expression where = select.Where; if (fromSelect.Where != null) { if (where != null) { where = Expression.And(fromSelect.Where, where); } else { where = fromSelect.Where; } } if (where != select.Where) { return(new SelectExpression(select.Type, select.Alias, select.Columns, select.From, where));//, select.OrderBy); } } } return(select); }
protected override Expression VisitSelect(SelectExpression select) { select = (SelectExpression)base.VisitSelect(select); // first remove all purely redundant subqueries List <SelectExpression> redundant = RedundantSubqueryGatherer.Gather(select.From, Logger); if (redundant != null) { select = SubqueryRemover.Remove(select, redundant, Logger); } // next attempt to merge subqueries that would have been removed by the above // logic except for the existence of a where clause while (CanMergeWithFrom(select)) { SelectExpression fromSelect = (SelectExpression)select.From; // remove the redundant subquery select = SubqueryRemover.Remove(select, Logger, fromSelect); // merge where expressions Expression where = select.Where; if (fromSelect.Where != null) { if (where != null) { where = Expression.And(fromSelect.Where, where); } else { where = fromSelect.Where; } } if (where != select.Where) { select = new SelectExpression(select.Type, select.Alias, select.Columns, select.From, where, select.OrderBy, select.GroupBy); } } return(select); }
internal static List<SelectExpression> Gather(Expression source) { RedundantSubqueryGatherer gatherer = new RedundantSubqueryGatherer(); gatherer.Visit(source); return gatherer.redundant; }