Package org.h2.command.query
Class Select
java.lang.Object
org.h2.command.Prepared
org.h2.command.query.Query
org.h2.command.query.Select
This class represents a simple SELECT statement.
For each select statement, visibleColumnCount <= distinctColumnCount <= expressionCount. The expression list count could include ORDER BY and GROUP BY expressions that are not in the select list.
The call sequence is init(), mapColumns() if it's a subquery, prepare().
-
Field Summary
Fields inherited from class org.h2.command.Prepared
create, parameters, prepareAlways, session, sqlStatement, sqlTokens -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCondition(Expression cond) Add a condition to the list of conditions.voidaddGlobalCondition(Parameter param, int columnId, int comparisonType) Add a condition to the query.voidaddTableFilter(TableFilter filter, boolean isTop) Add a table to the query.booleanAdds a named window definition.booleanCheck whether adding condition to the query is allowed.voidCall the before triggers on all tables.doublegetCost()Calculate the cost to execute this query.Returns FOR UPDATE clause, if any.getGroupDataIfCurrent(boolean window) Get the group data if there is currently a group-by active.If this query is determined as a single-row query, returns a replacement expression.Returns parent select, or null.getPlanSQL(StringBuilder builder, int sqlFlags) Appends the SQL statement with the execution plan.Get all tables that are involved in this query.Returns a window with specified name, or null.voidinit()Initialize the query.booleanbooleanbooleanCheck if this query will always return the same value and has no side effects.booleanisEverything(ExpressionVisitor visitor) Check if this expression and all sub-expressions can fulfill a criteria.booleanChecks if this query is a group query.booleanChecks if window stage of group window query is performed.booleanCheck if this is an aggregate query with direct lookup, for example a query of the type SELECT COUNT(*) FROM TEST or SELECT MAX(ID) FROM TEST.booleanisUnion()Check if this is a UNION query.booleanChecks if this query contains window functions.voidmapColumns(ColumnResolver resolver, int level, boolean outer) Map the columns to the given column resolver.voidvoidprotected ResultInterfacequeryWithoutCache(long maxRows, ResultTarget target) Execute the query without checking the cache.voidSet the distinct flag.voidsetDistinct(Expression[] distinctExpressions) Set the DISTINCT ON expressions.voidsetEvaluatable(TableFilter tableFilter, boolean b) Change the evaluatable flag.voidConvert this SELECT to an explicit table (TABLE tableName).voidsetExpressions(ArrayList<Expression> expressions) voidSet the FOR UPDATE clause.voidsetGroupBy(ArrayList<Expression> group) voidSet when SELECT statement contains (non-window) aggregate functions, GROUP BY clause or HAVING clause.voidsetHaving(Expression having) voidsetQualify(Expression qualify) voidSets a wildcard expression as in "SELECT * FROM TEST".voidCalled if this query contains window functions.voidupdateAggregate(SessionLocal s, int stage) Update all aggregate function values.Methods inherited from class org.h2.command.query.Query
collectDependencies, disableCache, exists, getColumnCount, getCostAsExpression, getExpressions, getFetch, getMaxDataModificationId, getOffset, getOuterQueryScope, getRowDataType, getType, hasOrder, invalidateCachedResult, isFetchPercent, isInPredicateResult, isNeverLazy, isQuery, isReadOnly, isRetryable, isStandardDistinct, isTransactional, isWithTies, prepare, query, query, queryMeta, setDistinctIfPossible, setFetch, setFetchPercent, setInPredicateResult, setInPredicateResultSortTypes, setNeverLazy, setOffset, setOrder, setOuterQueryScope, setWithClause, setWithTies, toTable, writeWithListMethods inherited from class org.h2.command.Prepared
checkCanceled, checkParameters, getCurrentRowNumber, getDatabase, getObjectId, getParameters, getPersistedObjectId, getPlanSQL, getSession, getSimpleSQL, getSQL, getSQLTokens, isWithParamValues, needRecompile, setCommand, setCurrentRowNumber, setParameterList, setPersistedObjectId, setPrepareAlways, setRow, setSession, setSQL, setWithParamValues, toString, update
-
Constructor Details
-
Select
-
-
Method Details
-
isUnion
public boolean isUnion()Description copied from class:QueryCheck if this is a UNION query. -
addTableFilter
Add a table to the query.- Parameters:
filter- the table to addisTop- if the table can be the first table in the query plan
-
setExpressions
-
setExplicitTable
public void setExplicitTable()Convert this SELECT to an explicit table (TABLE tableName). -
setWildcard
public void setWildcard()Sets a wildcard expression as in "SELECT * FROM TEST". -
setGroupQuery
public void setGroupQuery()Set when SELECT statement contains (non-window) aggregate functions, GROUP BY clause or HAVING clause. -
setWindowQuery
public void setWindowQuery()Called if this query contains window functions. -
setGroupBy
-
getGroupBy
-
getGroupDataIfCurrent
Get the group data if there is currently a group-by active.- Parameters:
window- is this a window function- Returns:
- the grouped data
-
setDistinct
public void setDistinct()Set the distinct flag. -
setDistinct
Set the DISTINCT ON expressions.- Parameters:
distinctExpressions- array of expressions
-
isAnyDistinct
public boolean isAnyDistinct()- Overrides:
isAnyDistinctin classQuery- Returns:
- whether this query is a
DISTINCTorDISTINCT ON (...)query
-
addWindow
Adds a named window definition.- Parameters:
name- namewindow- window definition- Returns:
- true if a new definition was added, false if old definition was replaced
-
getWindow
Returns a window with specified name, or null.- Parameters:
name- name of the window- Returns:
- the window with specified name, or null
-
addCondition
Add a condition to the list of conditions.- Parameters:
cond- the condition to add
-
getCondition
-
queryWithoutCache
Description copied from class:QueryExecute the query without checking the cache. If a target is specified, the results are written to it, and the method returns null. If no target is specified, a new LocalResult is created and returned.- Specified by:
queryWithoutCachein classQuery- Parameters:
maxRows- the limit as specified in the JDBC method calltarget- the target to write results to- Returns:
- the result
-
init
public void init()Description copied from class:QueryInitialize the query. -
prepareExpressions
public void prepareExpressions()- Specified by:
prepareExpressionsin classQuery
-
preparePlan
public void preparePlan()- Specified by:
preparePlanin classQuery
-
getCost
public double getCost()Description copied from class:QueryCalculate the cost to execute this query. -
getTables
Description copied from class:QueryGet all tables that are involved in this query. -
fireBeforeSelectTriggers
public void fireBeforeSelectTriggers()Description copied from class:QueryCall the before triggers on all tables.- Specified by:
fireBeforeSelectTriggersin classQuery
-
getPlanSQL
Description copied from class:PreparedAppends the SQL statement with the execution plan.- Overrides:
getPlanSQLin classPrepared- Parameters:
builder- string buildersqlFlags- formatting flags- Returns:
- the execution plan
-
setHaving
-
getHaving
-
setQualify
-
getQualify
-
getTopTableFilter
-
getForUpdate
Description copied from class:QueryReturns FOR UPDATE clause, if any.- Overrides:
getForUpdatein classQuery- Returns:
- FOR UPDATE clause or
null
-
setForUpdate
Description copied from class:QuerySet the FOR UPDATE clause.- Specified by:
setForUpdatein classQuery- Parameters:
b- the new FOR UPDATE clause
-
mapColumns
Description copied from class:QueryMap the columns to the given column resolver.- Specified by:
mapColumnsin classQuery- Parameters:
resolver- the resolverlevel- the subquery level (0 is the top level query, 1 is the first subquery level)outer- whether this method was called from the outer query
-
setEvaluatable
Description copied from class:QueryChange the evaluatable flag. This is used when building the execution plan.- Specified by:
setEvaluatablein classQuery- Parameters:
tableFilter- the table filterb- the new value
-
isQuickAggregateQuery
public boolean isQuickAggregateQuery()Check if this is an aggregate query with direct lookup, for example a query of the type SELECT COUNT(*) FROM TEST or SELECT MAX(ID) FROM TEST.- Returns:
- true if a direct lookup is possible
-
isGroupQuery
public boolean isGroupQuery()Checks if this query is a group query.- Returns:
- whether this query is a group query.
-
isWindowQuery
public boolean isWindowQuery()Checks if this query contains window functions.- Returns:
- whether this query contains window functions
-
isGroupWindowStage2
public boolean isGroupWindowStage2()Checks if window stage of group window query is performed. If true, column resolver may not be used.- Returns:
- true if window stage of group window query is performed
-
addGlobalCondition
Description copied from class:QueryAdd a condition to the query. This is used for views.- Specified by:
addGlobalConditionin classQuery- Parameters:
param- the parametercolumnId- the column index (0 meaning the first column)comparisonType- the comparison type
-
updateAggregate
Description copied from class:QueryUpdate all aggregate function values.- Specified by:
updateAggregatein classQuery- Parameters:
s- the sessionstage- select stage
-
isEverything
Description copied from class:QueryCheck if this expression and all sub-expressions can fulfill a criteria. If any part returns false, the result is false.- Specified by:
isEverythingin classQuery- Parameters:
visitor- the visitor- Returns:
- if the criteria can be fulfilled
-
isCacheable
public boolean isCacheable()- Overrides:
isCacheablein classPrepared
-
allowGlobalConditions
public boolean allowGlobalConditions()Description copied from class:QueryCheck whether adding condition to the query is allowed. This is not allowed for views that have an order by and a limit, as it would affect the returned results.- Specified by:
allowGlobalConditionsin classQuery- Returns:
- true if adding global conditions is allowed
-
getSortOrder
-
getParentSelect
Returns parent select, or null.- Returns:
- parent select, or null
-
isConstantQuery
public boolean isConstantQuery()Description copied from class:QueryCheck if this query will always return the same value and has no side effects.- Overrides:
isConstantQueryin classQuery- Returns:
- if this query will always return the same value and has no side effects.
-
getIfSingleRow
Description copied from class:QueryIf this query is determined as a single-row query, returns a replacement expression.- Overrides:
getIfSingleRowin classQuery- Returns:
- the expression, or
null
-