Visitable
class SubqueryNode extends ValueNode
Modifier and Type | Field | Description |
---|---|---|
(package private) boolean |
distinctExpression |
|
private boolean |
doneCorrelationCheck |
|
private boolean |
doneInvariantCheck |
|
(package private) static int |
EQ_ALL_SUBQUERY |
|
(package private) static int |
EQ_ANY_SUBQUERY |
|
(package private) static int |
EXISTS_SUBQUERY |
|
(package private) static int |
EXPRESSION_SUBQUERY |
|
private ValueNode |
fetchFirst |
|
private boolean |
foundCorrelation |
|
private boolean |
foundVariant |
|
(package private) static int |
FROM_SUBQUERY |
|
(package private) static int |
GE_ALL_SUBQUERY |
|
(package private) static int |
GE_ANY_SUBQUERY |
|
(package private) static int |
GT_ALL_SUBQUERY |
|
(package private) static int |
GT_ANY_SUBQUERY |
|
private boolean |
hasJDBClimitClause |
|
(package private) boolean |
havingSubquery |
is this subquery part of a having clause.
|
(package private) static int |
IN_SUBQUERY |
|
(package private) static int |
LE_ALL_SUBQUERY |
|
(package private) static int |
LE_ANY_SUBQUERY |
|
(package private) ValueNode |
leftOperand |
|
(package private) static int |
LT_ALL_SUBQUERY |
|
(package private) static int |
LT_ANY_SUBQUERY |
|
(package private) static int |
NE_ALL_SUBQUERY |
|
(package private) static int |
NE_ANY_SUBQUERY |
|
(package private) static int |
NOT_EXISTS_SUBQUERY |
|
(package private) static int |
NOT_IN_SUBQUERY |
|
(package private) static int |
NOTIMPLEMENTED_SUBQUERY |
|
private ValueNode |
offset |
|
private OrderByList |
orderByList |
|
(package private) BinaryComparisonOperatorNode |
parentComparisonOperator |
|
private int |
pointOfAttachment |
|
(package private) boolean |
preprocessed |
|
(package private) boolean |
pushedNewPredicate |
|
(package private) ResultSetNode |
resultSet |
|
private int |
subqueryNumber |
|
(package private) int |
subqueryType |
|
private BooleanConstantNode |
trueNode |
|
(package private) boolean |
underTopAndNode |
|
(package private) boolean |
whereSubquery |
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
transformed
Constructor | Description |
---|---|
SubqueryNode(ResultSetNode resultSet,
int subqueryType,
ValueNode leftOperand,
OrderByList orderCols,
ValueNode offset,
ValueNode fetchFirst,
boolean hasJDBClimitClause,
ContextManager cm) |
Constructor.
|
Modifier and Type | Method | Description |
---|---|---|
(package private) void |
acceptChildren(Visitor v) |
Accept the visitor for all visitable children of this node.
|
(package private) ValueNode |
bindExpression(FromList fromList,
SubqueryList subqueryList,
java.util.List<AggregateNode> aggregates) |
Bind this expression.
|
private boolean |
canAllBeFlattened() |
Can NOT IN, ALL be falttened to NOT EXISTS join?
|
(package private) boolean |
categorize(JBitSet referencedTabs,
boolean simplePredsOnly) |
Categorize this predicate.
|
(package private) ValueNode |
changeToCNF(boolean underTopAndNode) |
Finish putting an expression into conjunctive normal
form.
|
private void |
changeToCorrespondingExpressionType() |
Convert this IN/ANY subquery, which is known to return at most 1 row,
to an equivalent expression subquery.
|
(package private) ValueNode |
eliminateNots(boolean underNotNode) |
Eliminate NotNodes in the current query block.
|
private ValueNode |
flattenToExistsJoin(int numTables,
FromList outerFromList,
SubqueryList outerSubqueryList,
PredicateList outerPredicateList,
boolean flattenableNotExists) |
Flatten this subquery into the outer query block
as an exists join.
|
private ValueNode |
flattenToNormalJoin(int numTables,
FromList outerFromList,
SubqueryList outerSubqueryList,
PredicateList outerPredicateList) |
Flatten this subquery into the outer query block.
|
(package private) void |
generateExpression(ExpressionClassBuilder expressionBuilder,
MethodBuilder mbex) |
Do code generation for this subquery.
|
private LocalField |
generateMaterialization(ActivationClassBuilder acb,
MethodBuilder mbsq,
java.lang.String type) |
|
ValueNode |
getFetchFirst() |
Get FETCH FIRST (used to construct FROM_SUBQUERY only), cf.
|
private BinaryComparisonOperatorNode |
getNewJoinCondition(ValueNode leftOperand,
ValueNode rightOperand) |
Build a new join condition between the leftOperand
and the rightOperand.
|
ValueNode |
getOffset() |
Get OFFSET (used to construct FROM_SUBQUERY only), cf.
|
protected int |
getOrderableVariantType() |
Return the variant type for the underlying expression.
|
OrderByList |
getOrderByList() |
Get ORDER BY list (used to construct FROM_SUBQUERY only), cf.
|
(package private) int |
getPointOfAttachment() |
Get the ResultSet # for the point of attachment for this SubqueryNode.
|
(package private) boolean |
getPreprocessed() |
Get whether or not this SubqueryNode has already been
preprocessed.
|
(package private) ResultSetNode |
getResultSet() |
Return the resultSet for this SubqueryNode.
|
private ValueNode |
getRightOperand() |
Get the node that will be the right operand in the join condition if
this ALL/ANY/SOME/(NOT) IN subquery is flattened to a join.
|
(package private) int |
getSubqueryType() |
Return the type of this subquery.
|
private BooleanConstantNode |
getTrueNode() |
|
(package private) boolean |
getUnderTopAndNode() |
Return whether or not this subquery is immediately under a top level
AndNode.
|
(package private) boolean |
hasCorrelatedCRs() |
Check to see if this subquery has correlated
column references.
|
boolean |
hasJDBClimitClause() |
Return true if the offset/fetchFirst clauses were added by JDBC LIMIT escape syntax.
|
private boolean |
isALL() |
|
private boolean |
isANY() |
|
(package private) boolean |
isEquivalent(ValueNode o) |
Tests if this node is equivalent to the specified ValueNode.
|
private boolean |
isEXISTS() |
|
boolean |
isHavingSubquery() |
Is this subquery part of a having clause?
|
private boolean |
isIN() |
|
private boolean |
isInvariant() |
Check to see if we have a Variant value below us.
|
boolean |
isMaterializable() |
|
private boolean |
isNOT_EXISTS() |
|
private boolean |
isNOT_IN() |
|
(package private) boolean |
isWhereExistsAnyInWithWhereSubquery() |
Check whether this is a WHERE EXISTS | ANY | IN subquery with a subquery
in its own WHERE clause.
|
(package private) boolean |
isWhereSubquery() |
Is this subquery part of a whereclause?
|
(package private) void |
modifyAccessPaths() |
Make any changes to the access paths, as decided by the optimizer.
|
(package private) void |
optimize(DataDictionary dataDictionary,
double outerRows) |
Optimize this SubqueryNode.
|
(package private) ValueNode |
preprocess(int numTables,
FromList outerFromList,
SubqueryList outerSubqueryList,
PredicateList outerPredicateList) |
Preprocess an expression tree.
|
(package private) void |
printSubNodes(int depth) |
Prints the sub-nodes of this object.
|
private UnaryComparisonOperatorNode |
pushNewPredicate(int numTables) |
Transform:
expression QuantifiedOperator (select x from ...)
|
boolean |
referencesSessionSchema() |
Return true if the node references SESSION schema tables (temporary or permanent)
|
(package private) ValueNode |
remapColumnReferencesToExpressions() |
Remap all ColumnReferences in this tree to be clones of the
underlying expression.
|
private boolean |
rightOperandFlattenableToNotExists(int numTables,
FromBaseTable fbt) |
Check if the right operand is on a form that makes it possible to
flatten this query to a NOT EXISTS join.
|
private void |
setDataTypeServices(ResultColumnList resultColumns) |
|
void |
setHavingSubquery(boolean havingSubquery) |
Mark this subquery as being part of a having clause.
|
(package private) void |
setParentComparisonOperator(BinaryComparisonOperatorNode parent) |
Set the parent BCON.
|
(package private) void |
setPointOfAttachment(int pointOfAttachment) |
Set the point of attachment of this subquery.
|
(package private) void |
setSubqueryType(int subqueryType) |
Set the type of this subquery.
|
(package private) void |
setWhereSubquery(boolean whereSubquery) |
Mark this subquery as being part of a where clause.
|
private FromBaseTable |
singleFromBaseTable(FromList fromList) |
Does the from list from the subquery contain a
single entry which is a FBT or a PRN/FBT.
|
java.lang.String |
toString() |
Convert this object to a String.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
bindExpression, checkIsBoolean, checkTopPredicatesForEqualsConditions, constantExpression, copyFields, evaluateConstantExpressions, genEqualsFalseTree, generate, genIsNullTree, genSQLJavaSQLTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isCloneable, isConstantExpression, isInListProbeNode, isParameterNode, isRelationalOperator, isSameNodeKind, optimizableEqualityNode, putAndsOnTop, requiresTypeFromContext, selectivity, setCollationInfo, setCollationInfo, setCollationUsingCompilationSchema, setCollationUsingCompilationSchema, setNullability, setTransformed, setType, setType, setType, updatableByCursor, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
ResultSetNode resultSet
int subqueryType
boolean underTopAndNode
boolean preprocessed
boolean distinctExpression
boolean whereSubquery
ValueNode leftOperand
boolean pushedNewPredicate
boolean havingSubquery
BinaryComparisonOperatorNode parentComparisonOperator
private BooleanConstantNode trueNode
private int subqueryNumber
private int pointOfAttachment
private boolean foundCorrelation
private boolean doneCorrelationCheck
private boolean foundVariant
private boolean doneInvariantCheck
private OrderByList orderByList
private ValueNode offset
private ValueNode fetchFirst
private boolean hasJDBClimitClause
static final int NOTIMPLEMENTED_SUBQUERY
static final int FROM_SUBQUERY
static final int IN_SUBQUERY
static final int NOT_IN_SUBQUERY
static final int EQ_ANY_SUBQUERY
static final int EQ_ALL_SUBQUERY
static final int NE_ANY_SUBQUERY
static final int NE_ALL_SUBQUERY
static final int GT_ANY_SUBQUERY
static final int GT_ALL_SUBQUERY
static final int GE_ANY_SUBQUERY
static final int GE_ALL_SUBQUERY
static final int LT_ANY_SUBQUERY
static final int LT_ALL_SUBQUERY
static final int LE_ANY_SUBQUERY
static final int LE_ALL_SUBQUERY
static final int EXISTS_SUBQUERY
static final int NOT_EXISTS_SUBQUERY
static final int EXPRESSION_SUBQUERY
SubqueryNode(ResultSetNode resultSet, int subqueryType, ValueNode leftOperand, OrderByList orderCols, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, ContextManager cm)
resultSet
- The ResultSetNode for the subquerysubqueryType
- The type of the subqueryleftOperand
- The left operand, if any, of the subqueryorderCols
- ORDER BY listoffset
- OFFSET n ROWSfetchFirst
- FETCH FIRST n ROWS ONLYhasJDBClimitClause
- True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntaxcm
- Context Managerpublic java.lang.String toString()
void printSubNodes(int depth)
printSubNodes
in class QueryTreeNode
depth
- The depth of this node in the treeResultSetNode getResultSet()
int getSubqueryType()
void setSubqueryType(int subqueryType)
subqueryType
- of this subquery.void setPointOfAttachment(int pointOfAttachment) throws StandardException
pointOfAttachment
- The point of attachment of this subquery.StandardException
- Thrown on errorboolean getUnderTopAndNode()
int getPointOfAttachment()
boolean getPreprocessed()
void setParentComparisonOperator(BinaryComparisonOperatorNode parent)
parent
- The parent BCON.public boolean referencesSessionSchema() throws StandardException
QueryTreeNode
referencesSessionSchema
in class QueryTreeNode
StandardException
- Thrown on errorValueNode remapColumnReferencesToExpressions() throws StandardException
remapColumnReferencesToExpressions
in class ValueNode
StandardException
- Thrown on errorValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates) throws StandardException
bindExpression
in class ValueNode
fromList
- The FROM list for the query this
expression is in, for binding columns.
NOTE: fromList will be null if the subquery appears
in a VALUES clause.subqueryList
- The subquery list being built as we find SubqueryNodesaggregates
- The aggregate list being built as we find AggregateNodesStandardException
- Thrown on errorValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException
preprocess
in class ValueNode
numTables
- Number of tables in the DML StatementouterFromList
- FromList from outer query blockouterSubqueryList
- SubqueryList from outer query blockouterPredicateList
- PredicateList from outer query blockStandardException
- Thrown on errorprivate FromBaseTable singleFromBaseTable(FromList fromList)
fromList
- The from list from the subqueryFromBaseTable
if the from list from the subquery
contains a single entry which is a FBT or a PRN/FBT, or null
if the subquery does not contain a single FBTprivate boolean rightOperandFlattenableToNotExists(int numTables, FromBaseTable fbt) throws StandardException
Check if the right operand is on a form that makes it possible to flatten this query to a NOT EXISTS join. We don't allow flattening if the right operand doesn't reference the base table of the subquery. (Requirement added as part of DERBY-4001.)
The problem with the right operand not referencing the base table of the subquery, is that the join condition may then be used to filter rows from the right side (outer) table in the NOT EXISTS join. In a NOT EXISTS join, the join condition can only safely be applied to the left side (inner) table of the join. Otherwise, it will filter out all the interesting rows too early.
Take the query below as an example:
SELECT * FROM T1 WHERE X NOT IN (SELECT 1 FROM T2)
Here, the right operand is 1, and the join condition is T1.X=1
.
If flattened, the join condition will be used directly on the outer
table, and hide all rows with X<>1
, although those are the only
rows we're interested in. If the join condition had only been used on
the inner table, the NOT EXISTS join logic would do the correct thing.
If the join condition references the inner table, the condition cannot be used directly on the outer table, so it is safe to flatten the query.
numTables
- the number of tables in this statementfbt
- the only FromBaseTable
in this subquerytrue
if it is OK to flatten this query to a NOT EXISTS
join, false
otherwiseStandardException
private boolean canAllBeFlattened() throws StandardException
StandardException
private ValueNode flattenToNormalJoin(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException
numTables
- Number of tables in the DML StatementouterFromList
- FromList from outer query blockouterSubqueryList
- SubqueryList from outer query blockouterPredicateList
- PredicateList from outer query blockStandardException
- Thrown on errorprivate ValueNode flattenToExistsJoin(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList, boolean flattenableNotExists) throws StandardException
numTables
- Number of tables in the DML StatementouterFromList
- FromList from outer query blockouterSubqueryList
- SubqueryList from outer query blockouterPredicateList
- PredicateList from outer query blockflattenableNotExists
- Is it a flattening into a NOT EXISTS joinStandardException
- Thrown on errorprivate ValueNode getRightOperand()
private boolean isInvariant() throws StandardException
StandardException
- Thrown on errorboolean hasCorrelatedCRs() throws StandardException
StandardException
- Thrown on errorprivate UnaryComparisonOperatorNode pushNewPredicate(int numTables) throws StandardException
numTables
- Number of tables in DML StatementStandardException
- Thrown on errorprivate BinaryComparisonOperatorNode getNewJoinCondition(ValueNode leftOperand, ValueNode rightOperand) throws StandardException
leftOperand
- The left operand for the new condition.rightOperand
- The right operand for the new condition.StandardException
- Thrown on errorValueNode eliminateNots(boolean underNotNode) throws StandardException
eliminateNots
in class ValueNode
underNotNode
- Whether or not we are under a NotNode.StandardException
- Thrown on errorValueNode changeToCNF(boolean underTopAndNode) throws StandardException
changeToCNF
in class ValueNode
underTopAndNode
- Whether or not we are under a top level AndNode.StandardException
- Thrown on errorboolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) throws StandardException
categorize
in class ValueNode
referencedTabs
- JBitSet with bit map of referenced FromTablessimplePredsOnly
- Whether or not to consider method
calls, field references and conditional nodes
when building bit mapStandardException
- Thrown on errorpublic boolean isMaterializable() throws StandardException
StandardException
void optimize(DataDictionary dataDictionary, double outerRows) throws StandardException
dataDictionary
- The DataDictionary to use for optimizationouterRows
- The optimizer's estimate of the number of
times this subquery will be executed.StandardException
- Thrown on errorvoid modifyAccessPaths() throws StandardException
StandardException
- Thrown on errorprotected int getOrderableVariantType() throws StandardException
getOrderableVariantType
in class ValueNode
StandardException
- Thrown on errorvoid generateExpression(ExpressionClassBuilder expressionBuilder, MethodBuilder mbex) throws StandardException
generateExpression
in class ValueNode
expressionBuilder
- The ExpressionClassBuilder for the class being builtmbex
- The method the expression will go intoStandardException
- Thrown on errorprivate LocalField generateMaterialization(ActivationClassBuilder acb, MethodBuilder mbsq, java.lang.String type)
private BooleanConstantNode getTrueNode() throws StandardException
StandardException
void acceptChildren(Visitor v) throws StandardException
acceptChildren
in class QueryTreeNode
v
- the visitorStandardException
- on errorprivate boolean isIN()
private boolean isNOT_IN()
private boolean isANY()
private boolean isALL()
private boolean isEXISTS()
private boolean isNOT_EXISTS()
private void changeToCorrespondingExpressionType() throws StandardException
StandardException
- Thrown on errorprivate void setDataTypeServices(ResultColumnList resultColumns) throws StandardException
StandardException
boolean isEquivalent(ValueNode o)
This method provides basic expression matching facility for the derived class of ValueNode and it is used by the language layer to compare the node structural form of the two expressions for equivalence at bind phase.
Note that it is not comparing the actual row values at runtime to produce a result; hence, when comparing SQL NULLs, they are considered to be equivalent and not unknown.
One usage case of this method in this context is to compare the select column expression against the group by expression to check if they are equivalent. e.g.:
SELECT c1+c2 FROM t1 GROUP BY c1+c2
In general, node equivalence is determined by the derived class of ValueNode. But they generally abide to the rules below:
isEquivalent
in class ValueNode
o
- the node to compare this ValueNode against.true
if the two nodes are equivalent,
false
otherwise.public boolean isHavingSubquery()
public void setHavingSubquery(boolean havingSubquery)
havingSubquery
- boolean isWhereSubquery()
void setWhereSubquery(boolean whereSubquery)
whereSubquery
- boolean isWhereExistsAnyInWithWhereSubquery() throws StandardException
StandardException
public OrderByList getOrderByList()
public ValueNode getOffset()
public ValueNode getFetchFirst()
public boolean hasJDBClimitClause()
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.