Package org.h2.command.query
Class SelectUnion
- java.lang.Object
-
- org.h2.command.Prepared
-
- org.h2.command.query.Query
-
- org.h2.command.query.SelectUnion
-
public class SelectUnion extends Query
Represents a union SELECT statement.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
SelectUnion.LazyResultUnion
Lazy execution for this union.static class
SelectUnion.UnionType
-
Nested classes/interfaces inherited from class org.h2.command.query.Query
Query.OffsetFetch
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
isForUpdate
(package private) Query
left
The left hand side of the union (the first subquery).(package private) Query
right
The right hand side of the union (the second subquery).private SelectUnion.UnionType
unionType
-
Fields inherited from class org.h2.command.query.Query
checkInit, distinct, expressionArray, expressions, fetchExpr, fetchPercent, isPrepared, offsetExpr, orderList, randomAccessResult, resultColumnCount, sort, visibleColumnCount, withTies
-
Fields inherited from class org.h2.command.Prepared
create, parameters, prepareAlways, session, sqlStatement, sqlTokens
-
-
Constructor Summary
Constructors Constructor Description SelectUnion(SessionLocal session, SelectUnion.UnionType unionType, Query query, Query right)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addGlobalCondition(Parameter param, int columnId, int comparisonType)
Add a condition to the query.boolean
allowGlobalConditions()
Check whether adding condition to the query is allowed.private Value[]
convert(Value[] values, int columnCount)
private LocalResult
createLocalResult(int columnCount)
void
fireBeforeSelectTriggers()
Call the before triggers on all tables.double
getCost()
Calculate the cost to execute this query.LocalResult
getEmptyResult()
Query
getLeft()
java.lang.String
getPlanSQL(int sqlFlags)
Get the SQL statement with the execution plan.Query
getRight()
java.util.HashSet<Table>
getTables()
Get all tables that are involved in this query.SelectUnion.UnionType
getUnionType()
void
init()
Initialize the query.boolean
isConstantQuery()
Check if this query will always return the same value and has no side effects.boolean
isEverything(ExpressionVisitor visitor)
Check if this expression and all sub-expressions can fulfill a criteria.boolean
isUnion()
Check if this is a UNION query.void
mapColumns(ColumnResolver resolver, int level)
Map the columns to the given column resolver.void
prepare()
Prepare this statement.protected ResultInterface
queryWithoutCache(long maxRows, ResultTarget target)
Execute the query without checking the cache.void
setEvaluatable(TableFilter tableFilter, boolean b)
Change the evaluatable flag.void
setForUpdate(boolean forUpdate)
Set the 'for update' flag.void
updateAggregate(SessionLocal s, int stage)
Update all aggregate function values.-
Methods inherited from class org.h2.command.query.Query
addParameter, appendEndOfQueryToSQL, cleanupOrder, collectDependencies, convertToDistinct, disableCache, exists, finishResult, getColumnCount, getCostAsExpression, getExpressions, getFetch, getIfSingleRow, getMaxDataModificationId, getOffset, getOffsetFetch, getRowDataType, getType, hasOrder, initExpression, initOrder, isAnyDistinct, isFetchPercent, isNeverLazy, isQuery, isRandomAccessResult, isReadOnly, isStandardDistinct, isTransactional, isWithTies, prepareOrder, query, query, queryMeta, setDistinctIfPossible, setFetch, setFetchPercent, setNeverLazy, setOffset, setOrder, setRandomAccessResult, setWithTies, toTable
-
Methods inherited from class org.h2.command.Prepared
checkCanceled, checkParameters, getCteCleanups, getCurrentRowNumber, getObjectId, getParameters, getPersistedObjectId, getSession, getSimpleSQL, getSQL, getSQLTokens, isCacheable, needRecompile, setCommand, setCteCleanups, setCurrentRowNumber, setParameterList, setPersistedObjectId, setPrepareAlways, setRow, setSession, setSQL, toString, update
-
-
-
-
Field Detail
-
unionType
private final SelectUnion.UnionType unionType
-
left
final Query left
The left hand side of the union (the first subquery).
-
right
final Query right
The right hand side of the union (the second subquery).
-
isForUpdate
private boolean isForUpdate
-
-
Constructor Detail
-
SelectUnion
public SelectUnion(SessionLocal session, SelectUnion.UnionType unionType, Query query, Query right)
-
-
Method Detail
-
isUnion
public boolean isUnion()
Description copied from class:Query
Check if this is a UNION query.
-
getUnionType
public SelectUnion.UnionType getUnionType()
-
getLeft
public Query getLeft()
-
getRight
public Query getRight()
-
getEmptyResult
public LocalResult getEmptyResult()
-
queryWithoutCache
protected ResultInterface queryWithoutCache(long maxRows, ResultTarget target)
Description copied from class:Query
Execute 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:
queryWithoutCache
in classQuery
- Parameters:
maxRows
- the limit as specified in the JDBC method calltarget
- the target to write results to- Returns:
- the result
-
createLocalResult
private LocalResult createLocalResult(int columnCount)
-
init
public void init()
Description copied from class:Query
Initialize the query.
-
prepare
public void prepare()
Description copied from class:Prepared
Prepare this statement.
-
getCost
public double getCost()
Description copied from class:Query
Calculate the cost to execute this query.
-
getTables
public java.util.HashSet<Table> getTables()
Description copied from class:Query
Get all tables that are involved in this query.
-
setForUpdate
public void setForUpdate(boolean forUpdate)
Description copied from class:Query
Set the 'for update' flag.- Specified by:
setForUpdate
in classQuery
- Parameters:
forUpdate
- the new setting
-
mapColumns
public void mapColumns(ColumnResolver resolver, int level)
Description copied from class:Query
Map the columns to the given column resolver.- Specified by:
mapColumns
in classQuery
- Parameters:
resolver
- the resolverlevel
- the subquery level (0 is the top level query, 1 is the first subquery level)
-
setEvaluatable
public void setEvaluatable(TableFilter tableFilter, boolean b)
Description copied from class:Query
Change the evaluatable flag. This is used when building the execution plan.- Specified by:
setEvaluatable
in classQuery
- Parameters:
tableFilter
- the table filterb
- the new value
-
addGlobalCondition
public void addGlobalCondition(Parameter param, int columnId, int comparisonType)
Description copied from class:Query
Add a condition to the query. This is used for views.- Specified by:
addGlobalCondition
in classQuery
- Parameters:
param
- the parametercolumnId
- the column index (0 meaning the first column)comparisonType
- the comparison type
-
getPlanSQL
public java.lang.String getPlanSQL(int sqlFlags)
Description copied from class:Prepared
Get the SQL statement with the execution plan.- Overrides:
getPlanSQL
in classPrepared
- Parameters:
sqlFlags
- formatting flags- Returns:
- the execution plan
-
isEverything
public boolean isEverything(ExpressionVisitor visitor)
Description copied from class:Query
Check if this expression and all sub-expressions can fulfill a criteria. If any part returns false, the result is false.- Specified by:
isEverything
in classQuery
- Parameters:
visitor
- the visitor- Returns:
- if the criteria can be fulfilled
-
updateAggregate
public void updateAggregate(SessionLocal s, int stage)
Description copied from class:Query
Update all aggregate function values.- Specified by:
updateAggregate
in classQuery
- Parameters:
s
- the sessionstage
- select stage
-
fireBeforeSelectTriggers
public void fireBeforeSelectTriggers()
Description copied from class:Query
Call the before triggers on all tables.- Specified by:
fireBeforeSelectTriggers
in classQuery
-
allowGlobalConditions
public boolean allowGlobalConditions()
Description copied from class:Query
Check 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:
allowGlobalConditions
in classQuery
- Returns:
- true if adding global conditions is allowed
-
isConstantQuery
public boolean isConstantQuery()
Description copied from class:Query
Check if this query will always return the same value and has no side effects.- Overrides:
isConstantQuery
in classQuery
- Returns:
- if this query will always return the same value and has no side effects.
-
-