Package com.mckoi.database.interpret
Class Planner
- java.lang.Object
-
- com.mckoi.database.interpret.Planner
-
public class Planner extends java.lang.Object
Various methods for forming query plans on SQL queries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Planner.ExpressionPlan
An abstract class that represents an expression to be added into a plan.private static class
Planner.PlanTableSource
Represents a single table source being planned.private static class
Planner.QuerySelectColumnSet
A container object for the set of SelectColumn objects selected in a query.private static class
Planner.QueryTableSetPlanner
A table set planner that maintains a list of table dependence lists and progressively constructs a plan tree from the bottom up.
-
Field Summary
Fields Modifier and Type Field Description private static TableName
GROUP_BY_FUNCTION_TABLE
The name of the GROUP BY function table.private static java.util.Random
marker_randomizer
Used to generate unique marker names.
-
Constructor Summary
Constructors Constructor Description Planner()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
createRandomeOuterJoinName()
Returns a randomly generated outer join name.private static Expression
filterHavingClause(Expression having_expr, java.util.ArrayList aggregate_list, QueryContext context)
Given a HAVING clause expression, this will generate a new HAVING clause expression with all aggregate expressions put into the given extra function list.static QueryPlanNode
formQueryPlan(DatabaseConnection db, TableSelectExpression expression, TableExpressionFromSet from_set, java.util.ArrayList order_by)
Forms a query plan (QueryPlanNode) from the given TableSelectExpression and TableExpressionFromSet.(package private) static TableExpressionFromSet
generateFromSet(TableSelectExpression select_expression, DatabaseConnection db)
Given a TableExpression, generates a TableExpressionFromSet object.static QueryPlanNode
planForOrderBy(QueryPlanNode plan, java.util.ArrayList order_by, TableExpressionFromSet from_set, java.util.ArrayList s_col_list)
Plans an ORDER BY set.private static void
prepareSearchExpression(DatabaseConnection db, TableExpressionFromSet from_set, SearchExpression expression)
Prepares the given SearchExpression object.private static void
substituteAliasedVariable(Variable v, java.util.ArrayList s_col_list)
private static void
substituteAliasedVariables(Expression expression, java.util.ArrayList s_col_list)
Substitutes any aliased variables in the given expression with the function name equivalent.
-
-
-
Field Detail
-
GROUP_BY_FUNCTION_TABLE
private static TableName GROUP_BY_FUNCTION_TABLE
The name of the GROUP BY function table.
-
marker_randomizer
private static java.util.Random marker_randomizer
Used to generate unique marker names.
-
-
Method Detail
-
createRandomeOuterJoinName
private static java.lang.String createRandomeOuterJoinName()
Returns a randomly generated outer join name.
-
prepareSearchExpression
private static void prepareSearchExpression(DatabaseConnection db, TableExpressionFromSet from_set, SearchExpression expression) throws DatabaseException
Prepares the given SearchExpression object. This goes through each element of the Expression. If the element is a variable it is qualified. If the element is a TableSelectExpression it's converted to a SelectQueriable object and prepared.- Throws:
DatabaseException
-
filterHavingClause
private static Expression filterHavingClause(Expression having_expr, java.util.ArrayList aggregate_list, QueryContext context)
Given a HAVING clause expression, this will generate a new HAVING clause expression with all aggregate expressions put into the given extra function list.
-
generateFromSet
static TableExpressionFromSet generateFromSet(TableSelectExpression select_expression, DatabaseConnection db)
Given a TableExpression, generates a TableExpressionFromSet object. This object is used to help qualify variable references. This
-
formQueryPlan
public static QueryPlanNode formQueryPlan(DatabaseConnection db, TableSelectExpression expression, TableExpressionFromSet from_set, java.util.ArrayList order_by) throws DatabaseException
Forms a query plan (QueryPlanNode) from the given TableSelectExpression and TableExpressionFromSet. The TableSelectExpression describes the SELECT query (or sub-query), and the TableExpressionFromSet is used to resolve expression references.The 'order_by' argument is a list of ByColumn objects that represent an optional ORDER BY clause. If this is null or the list is empty, no ordering is done.
- Throws:
DatabaseException
-
planForOrderBy
public static QueryPlanNode planForOrderBy(QueryPlanNode plan, java.util.ArrayList order_by, TableExpressionFromSet from_set, java.util.ArrayList s_col_list) throws DatabaseException
Plans an ORDER BY set. This is given its own function because we may want to plan this at the end of a number of composite functions.NOTE: s_col_list is optional.
- Throws:
DatabaseException
-
substituteAliasedVariables
private static void substituteAliasedVariables(Expression expression, java.util.ArrayList s_col_list)
Substitutes any aliased variables in the given expression with the function name equivalent. For example, if we have a 'SELECT 3 + 4 Bah' then resolving on variable Bah will be subsituted to the function column that represents the result of 3 + 4.
-
substituteAliasedVariable
private static void substituteAliasedVariable(Variable v, java.util.ArrayList s_col_list)
-
-