|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.ValueNode
org.apache.derby.impl.sql.compile.SubqueryNode
A SubqueryNode represents a subquery. Subqueries return values to their outer queries. An quantified subquery is one that appears under a quantified operator (like IN or EXISTS) - quantified subqueries can return more than one value per invocation. An expression subquery is one that is not directly under a quantified operator - expression subqueries are allowed to return at most one value per invocation (returning no value is considered to be equivalent to returning NULL). There are a large number of subquery types. Because of the large number of types, and the large amount of shared code, we have decided to have 1 SubqueryNode without any subclasses. The subquery type (and operator) is encoded in the subqueryType field. The query optimizer is responsible for optimizing subqueries, and also for transforming them so that code can be generated for them. The optimizer may eliminate some subqueries by transforming them into joins, or it may change the internal form of a subquery (for example, transforming 'where x in (select y from z where ...)' into 'where (select true from z where x = y and ...)'). Note that aggregates present some additional issues. A transformation such as:
Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode |
clause, dataTypeServices, IN_HAVING_CLAUSE, IN_SELECT_LIST, IN_UNKNOWN_CLAUSE, IN_WHERE_CLAUSE, transformed |
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode |
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset |
Constructor Summary | |
SubqueryNode()
|
Method Summary | |
Visitable |
accept(Visitor v)
Accept a visitor, and call v.visit() on child nodes as necessary. |
ValueNode |
bindExpression(FromList fromList,
SubqueryList subqueryList,
java.util.Vector aggregateVector)
Bind this expression. |
private boolean |
canAllBeFlattened()
Can NOT IN, ALL be falttened to NOT EXISTS join? |
boolean |
categorize(JBitSet referencedTabs,
boolean simplePredsOnly)
Categorize this predicate. |
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. |
void |
generateExpression(ExpressionClassBuilder expressionBuilder,
MethodBuilder mbex)
Do code generation for this subquery. |
private LocalField |
generateMaterialization(ActivationClassBuilder acb,
MethodBuilder mbsq,
java.lang.String type)
|
private BinaryComparisonOperatorNode |
getNewJoinCondition(ValueNode leftOperand,
ValueNode rightOperand)
Build a new join condition between the leftOperand and the rightOperand. |
protected int |
getOrderableVariantType()
Return the variant type for the underlying expression. |
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. |
ResultSetNode |
getResultSet()
Return the resultSet for this SubqueryNode. |
int |
getSubqueryType()
Return the type of this subquery. |
private BooleanConstantNode |
getTrueNode()
|
boolean |
getUnderTopAndNode()
Return whether or not this subquery is immediately under a top level AndNode. |
boolean |
hasCorrelatedCRs()
Check to see if this subquery has correlated column references. |
void |
init(java.lang.Object resultSet,
java.lang.Object subqueryType,
java.lang.Object leftOperand)
Initializer. |
private boolean |
isALL()
|
private boolean |
isANY()
|
private boolean |
isEXISTS()
|
private boolean |
isIN()
|
private boolean |
isInvariant()
Check to see if we have a Variant value below us. |
(package private) boolean |
isMaterializable()
|
private boolean |
isNOT_EXISTS()
|
private boolean |
isNOT_IN()
|
void |
modifyAccessPaths()
Make any changes to the access paths, as decided by the optimizer. |
void |
optimize(DataDictionary dataDictionary,
double outerRows)
Optimize this SubqueryNode. |
ValueNode |
preprocess(int numTables,
FromList outerFromList,
SubqueryList outerSubqueryList,
PredicateList outerPredicateList)
Preprocess an expression tree. |
void |
printSubNodes(int depth)
Prints the sub-nodes of this object. |
private UnaryComparisonOperatorNode |
pushNewPredicate(int numTables)
Transform: expresion QuantifiedOperator (select x from ...) |
ValueNode |
remapColumnReferencesToExpressions()
Remap all ColumnReferences in this tree to be clones of the underlying expression. |
private void |
setDataTypeServices(ResultColumnList resultColumns)
|
(package private) void |
setParentComparisonOperator(BinaryComparisonOperatorNode parent)
Set the parent BCON. |
void |
setPointOfAttachment(int pointOfAttachment)
Set the point of attachment of this subquery. |
void |
setSubqueryType(int subqueryType)
Set the type of this subquery. |
private boolean |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
ResultSetNode resultSet
int subqueryType
boolean underTopAndNode
boolean preprocessed
boolean distinctExpression
ValueNode leftOperand
boolean pushedNewPredicate
BinaryComparisonOperatorNode parentComparisonOperator
private BooleanConstantNode trueNode
private int subqueryNumber
private int pointOfAttachment
private boolean foundCorrelation
private boolean doneCorrelationCheck
private boolean foundVariant
private boolean doneInvariantCheck
public static final int NOTIMPLEMENTED_SUBQUERY
public static final int FROM_SUBQUERY
public static final int IN_SUBQUERY
public static final int NOT_IN_SUBQUERY
public static final int EQ_ANY_SUBQUERY
public static final int EQ_ALL_SUBQUERY
public static final int NE_ANY_SUBQUERY
public static final int NE_ALL_SUBQUERY
public static final int GT_ANY_SUBQUERY
public static final int GT_ALL_SUBQUERY
public static final int GE_ANY_SUBQUERY
public static final int GE_ALL_SUBQUERY
public static final int LT_ANY_SUBQUERY
public static final int LT_ALL_SUBQUERY
public static final int LE_ANY_SUBQUERY
public static final int LE_ALL_SUBQUERY
public static final int EXISTS_SUBQUERY
public static final int NOT_EXISTS_SUBQUERY
public static final int EXPRESSION_SUBQUERY
Constructor Detail |
public SubqueryNode()
Method Detail |
public void init(java.lang.Object resultSet, java.lang.Object subqueryType, java.lang.Object leftOperand)
init
in class QueryTreeNode
resultSet
- The ResultSetNode for the subquerysubqueryType
- The type of the subqueryleftOperand
- The left operand, if any, of the subquerypublic java.lang.String toString()
toString
in class ValueNode
public void printSubNodes(int depth)
printSubNodes
in class QueryTreeNode
depth
- The depth of this node in the tree
public ResultSetNode getResultSet()
public int getSubqueryType()
public void setSubqueryType(int subqueryType)
public void setPointOfAttachment(int pointOfAttachment) throws StandardException
pointOfAttachment
- The point of attachment of this subquery.
StandardException
- Thrown on errorpublic boolean getUnderTopAndNode()
public int getPointOfAttachment()
boolean getPreprocessed()
void setParentComparisonOperator(BinaryComparisonOperatorNode parent)
parent
- The parent BCON.
public ValueNode remapColumnReferencesToExpressions() throws StandardException
remapColumnReferencesToExpressions
in class ValueNode
StandardException
- Thrown on errorpublic ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector) 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 SubqueryNodesaggregateVector
- The aggregate vector being built as we find AggregateNodes
StandardException
- Thrown on errorpublic ValueNode 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 block
StandardException
- Thrown on errorprivate boolean singleFromBaseTable(FromList fromList)
fromList
- The from list from the subquery
private boolean canAllBeFlattened()
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 block
StandardException
- 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 join
StandardException
- Thrown on errorprivate boolean isInvariant() throws StandardException
StandardException
- Thrown on errorpublic boolean hasCorrelatedCRs() throws StandardException
StandardException
- Thrown on errorprivate UnaryComparisonOperatorNode pushNewPredicate(int numTables) throws StandardException
numTables
- Number of tables in DML Statement
StandardException
- 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 errorpublic ValueNode changeToCNF(boolean underTopAndNode) throws StandardException
changeToCNF
in class ValueNode
underTopAndNode
- Whether or not we are under a top level AndNode.
StandardException
- Thrown on errorpublic boolean 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 map
StandardException
- Thrown on errorboolean isMaterializable() throws StandardException
StandardException
public 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 errorpublic void modifyAccessPaths() throws StandardException
StandardException
- Thrown on errorprotected int getOrderableVariantType() throws StandardException
getOrderableVariantType
in class ValueNode
StandardException
- Thrown on errorpublic void 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 into
StandardException
- Thrown on errorprivate LocalField generateMaterialization(ActivationClassBuilder acb, MethodBuilder mbsq, java.lang.String type)
private BooleanConstantNode getTrueNode() throws StandardException
StandardException
public Visitable accept(Visitor v) throws StandardException
accept
in interface Visitable
accept
in class QueryTreeNode
v
- the visitor
StandardException
- 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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |