387 var preparedColumns = columns.Prepare(context);
404 PrepareJoins(tablePlanner, queryExpression, queryFrom, ref whereClause);
414 var extraAggregateFunctions =
new List<SqlExpression>();
415 if (havingClause != null)
416 havingClause =
FilterHaving(havingClause, extraAggregateFunctions, context);
419 ObjectName[] groupByList;
420 IList<SqlExpression> groupByFunctions;
421 var gsz =
ResolveGroupBy(queryExpression, queryFrom, context, out groupByList, out groupByFunctions);
433 if (queryFrom.SourceCount == 0)
438 var node = tablePlanner.PlanSearchExpression(whereClause);
441 string[] defFunNames;
442 var fsz =
MakeupFunctions(preparedColumns, extraAggregateFunctions, out defFunList, out defFunNames);
444 var groupInfo =
new GroupInfo {
445 Columns = preparedColumns,
447 FunctionNames = defFunNames,
448 FunctionExpressions = defFunList,
450 GroupByNames = groupByList,
451 GroupByExpressions = groupByFunctions.ToArray(),
452 GroupMax = groupmaxColumn
458 var selectColumns = preparedColumns.SelectedColumns.ToList();
459 int sz = selectColumns.Count;
462 if (havingClause != null) {
465 var havingExpr = havingClause;
470 var source = tablePlanner.SinglePlan;
471 source.UpdatePlan(node);
472 node = tablePlanner.PlanSearchExpression(havingExpr);
476 IQueryPlanNode rightComposite = null;
479 var compositeFrom = QueryExpressionFrom.Create(context, compositeExpr);
482 rightComposite =
PlanQuery(context, compositeExpr, compositeFrom, null, null);
486 ObjectName[] aliases = null;
487 if (doSubsetColumn) {
489 var subsetVars =
new ObjectName[sz];
490 aliases =
new ObjectName[sz];
491 for (
int i = 0; i < sz; ++i) {
499 node =
new DistinctNode(node, subsetVars);
505 if (rightComposite == null && sortColumns != null)
506 node =
PlanForOrderBy(node, sortColumns, queryFrom, selectColumns);
509 node =
new SubsetNode(node, subsetVars, aliases);
512 if (rightComposite == null && sortColumns != null)
513 node =
PlanForOrderBy(node, sortColumns, queryFrom, selectColumns);
517 if (rightComposite != null) {
522 if (sortColumns != null)
523 node =
PlanForOrderBy(node, sortColumns, queryFrom, selectColumns);
526 if (!(node is SubsetNode) && aliases != null) {
527 node =
new SubsetNode(node, aliases, aliases);
532 node =
new LimitNode(node, limit.Offset, limit.Count);
QueryTablePlanner CreateTablePlanner(IRequest context, QueryExpressionFrom queryFrom)
void PrepareJoins(QueryTablePlanner tablePlanner, SqlQueryExpression queryExpression, QueryExpressionFrom queryFrom, ref SqlExpression searchExpression)
SqlExpression PrepareSearchExpression(IRequest context, QueryExpressionFrom queryFrom, SqlExpression expression)
IEnumerable< SelectColumn > SelectColumns
QuerySelectColumns BuildSelectColumns(SqlQueryExpression expression, QueryExpressionFrom queryFrom)
SqlExpression FilterHaving(SqlExpression havingExpression, IList< SqlExpression > aggregates, IRequest context)
SqlQueryExpression NextComposite
int ResolveGroupBy(SqlQueryExpression queryExpression, QueryExpressionFrom queryFrom, IRequest context, out ObjectName[] columnNames, out IList< SqlExpression > expressions)
static int MakeupFunctions(PreparedQuerySelectColumns columnSet, IList< SqlExpression > aggregateFunctions, out SqlExpression[] defFunList, out string[] defFunNames)
IQueryPlanNode PlanGroup(IQueryPlanNode node, GroupInfo groupInfo)
CompositeFunction CompositeFunction
IQueryPlanNode EvaluateToSingle(PreparedQuerySelectColumns columns)
static IList< SortColumn > ResolveOrderByRefs(PreparedQuerySelectColumns columnSet, IEnumerable< SortColumn > orderBy)
static SqlExpression ReplaceAliasedVariables(SqlExpression expression, IList< SelectColumn > selectedColumns)
Represents a column selected to be in the output of a select statement.
ObjectName InternalName
The name of this column used internally to reference it.
static IQueryPlanNode PlanForOrderBy(IQueryPlanNode plan, IList< SortColumn > orderBy, QueryExpressionFrom queryFrom, IList< SelectColumn > selectedColumns)
ObjectName ResolveGroupMax(SqlQueryExpression queryExpression, QueryExpressionFrom queryFrom)
Defines the base class for instances that represent SQL expression tree nodes.
IQueryPlanNode PlanQuery(QueryInfo queryInfo)
ObjectName ResolvedName
The fully resolved name that this column is given in the resulting table.
SqlExpression HavingExpression
SqlExpression WhereExpression