| java.lang.Object org.apache.derby.impl.sql.compile.QueryTreeNode org.apache.derby.impl.sql.compile.ValueNode org.apache.derby.impl.sql.compile.SubqueryNode
SubqueryNode | public class SubqueryNode extends ValueNode (Code) | | 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:
where x in (SELECT expression FROM z)
has to be treated specially if expression has an aggregate.
We change it to:
where x = (SELECT true FROM (SELECT MAX(x) FROM z) WHERE SQLCOL1 = y)
author: Jeff Lichtman |
Method Summary | |
public Visitable | accept(Visitor v) Accept a visitor, and call v.visit()
on child nodes as necessary. | public ValueNode | bindExpression(FromList fromList, SubqueryList subqueryList, Vector aggregateVector) Bind this expression. | public boolean | categorize(JBitSet referencedTabs, boolean simplePredsOnly) Categorize this predicate. | public ValueNode | changeToCNF(boolean underTopAndNode) Finish putting an expression into conjunctive normal
form. | ValueNode | eliminateNots(boolean underNotNode) Eliminate NotNodes in the current query block. | public void | generateExpression(ExpressionClassBuilder expressionBuilder, MethodBuilder mbex) Do code generation for this subquery. | protected int | getOrderableVariantType() Return the variant type for the underlying expression. | public int | getPointOfAttachment() Get the ResultSet # for the point of attachment for this SubqueryNode. | boolean | getPreprocessed() Get whether or not this SubqueryNode has already been
preprocessed. | public ResultSetNode | getResultSet() Return the resultSet for this SubqueryNode. | public int | getSubqueryType() Return the type of this subquery. | public boolean | getUnderTopAndNode() Return whether or not this subquery is immediately under a top level
AndNode. | public boolean | hasCorrelatedCRs() Check to see if this subquery has correlated
column references. | public void | init(Object resultSet, Object subqueryType, Object leftOperand) Initializer. | protected boolean | isEquivalent(ValueNode o) | boolean | isMaterializable() | public void | modifyAccessPaths() Make any changes to the access paths, as decided by the optimizer. | public void | optimize(DataDictionary dataDictionary, double outerRows) Optimize this SubqueryNode. | public ValueNode | preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) Preprocess an expression tree. | public void | printSubNodes(int depth) Prints the sub-nodes of this object. | public ValueNode | remapColumnReferencesToExpressions() Remap all ColumnReferences in this tree to be clones of the
underlying expression. | void | setParentComparisonOperator(BinaryComparisonOperatorNode parent) Set the parent BCON. | public void | setPointOfAttachment(int pointOfAttachment) Set the point of attachment of this subquery. | public void | setSubqueryType(int subqueryType) Set the type of this subquery. | public String | toString() Convert this object to a String. |
EQ_ALL_SUBQUERY | final public static int EQ_ALL_SUBQUERY(Code) | | |
EQ_ANY_SUBQUERY | final public static int EQ_ANY_SUBQUERY(Code) | | |
EXISTS_SUBQUERY | final public static int EXISTS_SUBQUERY(Code) | | |
EXPRESSION_SUBQUERY | final public static int EXPRESSION_SUBQUERY(Code) | | |
FROM_SUBQUERY | final public static int FROM_SUBQUERY(Code) | | |
GE_ALL_SUBQUERY | final public static int GE_ALL_SUBQUERY(Code) | | |
GE_ANY_SUBQUERY | final public static int GE_ANY_SUBQUERY(Code) | | |
GT_ALL_SUBQUERY | final public static int GT_ALL_SUBQUERY(Code) | | |
GT_ANY_SUBQUERY | final public static int GT_ANY_SUBQUERY(Code) | | |
IN_SUBQUERY | final public static int IN_SUBQUERY(Code) | | |
LE_ALL_SUBQUERY | final public static int LE_ALL_SUBQUERY(Code) | | |
LE_ANY_SUBQUERY | final public static int LE_ANY_SUBQUERY(Code) | | |
LT_ALL_SUBQUERY | final public static int LT_ALL_SUBQUERY(Code) | | |
LT_ANY_SUBQUERY | final public static int LT_ANY_SUBQUERY(Code) | | |
NE_ALL_SUBQUERY | final public static int NE_ALL_SUBQUERY(Code) | | |
NE_ANY_SUBQUERY | final public static int NE_ANY_SUBQUERY(Code) | | |
NOTIMPLEMENTED_SUBQUERY | final public static int NOTIMPLEMENTED_SUBQUERY(Code) | | |
NOT_EXISTS_SUBQUERY | final public static int NOT_EXISTS_SUBQUERY(Code) | | |
NOT_IN_SUBQUERY | final public static int NOT_IN_SUBQUERY(Code) | | |
distinctExpression | boolean distinctExpression(Code) | | |
preprocessed | boolean preprocessed(Code) | | |
pushedNewPredicate | boolean pushedNewPredicate(Code) | | |
subqueryType | int subqueryType(Code) | | |
underTopAndNode | boolean underTopAndNode(Code) | | |
bindExpression | public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, Vector aggregateVector) throws StandardException(Code) | | Bind this expression. This means binding the sub-expressions,
as well as figuring out what the return type is for this expression.
Parameters: fromList - The FROM list for the query thisexpression is in, for binding columns.NOTE: fromList will be null if the subquery appearsin a VALUES clause. Parameters: subqueryList - The subquery list being built as we find SubqueryNodes Parameters: aggregateVector - The aggregate vector being built as we find AggregateNodes The new top of the expression tree. exception: StandardException - Thrown on error |
categorize | public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) throws StandardException(Code) | | Categorize this predicate. Initially, this means
building a bit map of the referenced tables for each predicate.
If the source of this ColumnReference (at the next underlying level)
is not a ColumnReference or a VirtualColumnNode then this predicate
will not be pushed down.
For example, in:
select * from (select 1 from s) a (x) where x = 1
we will not push down x = 1.
NOTE: It would be easy to handle the case of a constant, but if the
inner SELECT returns an arbitrary expression, then we would have to copy
that tree into the pushed predicate, and that tree could contain
subqueries and method calls.
RESOLVE - revisit this issue once we have views.
Parameters: referencedTabs - JBitSet with bit map of referenced FromTables boolean Whether or not source.expression is a ColumnReferenceor a VirtualColumnNode. exception: StandardException - Thrown on error |
changeToCNF | public ValueNode changeToCNF(boolean underTopAndNode) throws StandardException(Code) | | Finish putting an expression into conjunctive normal
form. An expression tree in conjunctive normal form meets
the following criteria:
o If the expression tree is not null,
the top level will be a chain of AndNodes terminating
in a true BooleanConstantNode.
o The left child of an AndNode will never be an AndNode.
o Any right-linked chain that includes an AndNode will
be entirely composed of AndNodes terminated by a true BooleanConstantNode.
o The left child of an OrNode will never be an OrNode.
o Any right-linked chain that includes an OrNode will
be entirely composed of OrNodes terminated by a false BooleanConstantNode.
o ValueNodes other than AndNodes and OrNodes are considered
leaf nodes for purposes of expression normalization.
In other words, we won't do any normalization under
those nodes.
In addition, we track whether or not we are under a top level AndNode.
SubqueryNodes need to know this for subquery flattening.
Parameters: underTopAndNode - Whether or not we are under a top level AndNode. The modified expression exception: StandardException - Thrown on error |
eliminateNots | ValueNode eliminateNots(boolean underNotNode) throws StandardException(Code) | | Eliminate NotNodes in the current query block. We traverse the tree,
inverting ANDs and ORs and eliminating NOTs as we go. We stop at
ComparisonOperators and boolean expressions. We invert
ComparisonOperators and replace boolean expressions with
boolean expression = false.
NOTE: Since we do not recurse under ComparisonOperators, there
still could be NotNodes left in the tree.
Parameters: underNotNode - Whether or not we are under a NotNode. The modified expression exception: StandardException - Thrown on error |
getOrderableVariantType | protected int getOrderableVariantType() throws StandardException(Code) | | Return the variant type for the underlying expression.
The variant type can be:
VARIANT - variant within a scan
(method calls and non-static field access)
SCAN_INVARIANT - invariant within a scan
(column references from outer tables)
QUERY_INVARIANT - invariant within the life of a query
(constant expressions)
The variant type for the underlying expression. exception: StandardException - Thrown on error |
getPointOfAttachment | public int getPointOfAttachment()(Code) | | Get the ResultSet # for the point of attachment for this SubqueryNode.
int The ResultSet # for the point of attachment |
getPreprocessed | boolean getPreprocessed()(Code) | | Get whether or not this SubqueryNode has already been
preprocessed.
Whether or not this SubqueryNode has already beenpreprocessed. |
getResultSet | public ResultSetNode getResultSet()(Code) | | Return the resultSet for this SubqueryNode.
ResultSetNode underlying this SubqueryNode. |
getSubqueryType | public int getSubqueryType()(Code) | | Return the type of this subquery.
int Type of this subquery. |
getUnderTopAndNode | public boolean getUnderTopAndNode()(Code) | | Return whether or not this subquery is immediately under a top level
AndNode.
boolean Whether or not this subquery is immediately under atop level AndNode. |
hasCorrelatedCRs | public boolean hasCorrelatedCRs() throws StandardException(Code) | | Check to see if this subquery has correlated
column references. Only useful results if
called AFTER binding (after CRs have been bound).
whether the subquery has correlated columnreferences. exception: StandardException - Thrown on error |
init | public void init(Object resultSet, Object subqueryType, Object leftOperand)(Code) | | Initializer.
Parameters: resultSet - The ResultSetNode for the subquery Parameters: subqueryType - The type of the subquery Parameters: leftOperand - The left operand, if any, of the subquery |
optimize | public void optimize(DataDictionary dataDictionary, double outerRows) throws StandardException(Code) | | Optimize this SubqueryNode.
Parameters: dataDictionary - The DataDictionary to use for optimization Parameters: outerRows - The optimizer's estimate of the number oftimes this subquery will be executed. exception: StandardException - Thrown on error |
preprocess | public ValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException(Code) | | Preprocess an expression tree. We do a number of transformations
here (including subqueries, IN lists, LIKE and BETWEEN) plus
subquery flattening.
NOTE: This is done before the outer ResultSetNode is preprocessed.
Parameters: numTables - Number of tables in the DML Statement Parameters: outerFromList - FromList from outer query block Parameters: outerSubqueryList - SubqueryList from outer query block Parameters: outerPredicateList - PredicateList from outer query block The modified expression exception: StandardException - Thrown on error |
printSubNodes | public void printSubNodes(int depth)(Code) | | Prints the sub-nodes of this object. See QueryTreeNode.java for
how tree printing is supposed to work.
Parameters: depth - The depth of this node in the tree |
remapColumnReferencesToExpressions | public ValueNode remapColumnReferencesToExpressions() throws StandardException(Code) | | Remap all ColumnReferences in this tree to be clones of the
underlying expression.
ValueNode The remapped expression tree. exception: StandardException - Thrown on error |
setParentComparisonOperator | void setParentComparisonOperator(BinaryComparisonOperatorNode parent)(Code) | | Set the parent BCON. Useful when considering flattening
expression subqueries.
Parameters: parent - The parent BCON. |
setPointOfAttachment | public void setPointOfAttachment(int pointOfAttachment) throws StandardException(Code) | | Set the point of attachment of this subquery.
Parameters: pointOfAttachment - The point of attachment of this subquery. exception: StandardException - Thrown on error |
setSubqueryType | public void setSubqueryType(int subqueryType)(Code) | | Set the type of this subquery.
Parameters: subqueryType - of this subquery. |
toString | public String toString()(Code) | | Convert this object to a String. See comments in QueryTreeNode.java
for how this should be done for tree printing.
This object as a String |
Methods inherited from org.apache.derby.impl.sql.compile.ValueNode | public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, Vector aggregateVector) throws StandardException(Code)(Java Doc) public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, Vector aggregateVector, boolean forQueryRewrite) throws StandardException(Code)(Java Doc) public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) throws StandardException(Code)(Java Doc) public ValueNode changeToCNF(boolean underTopAndNode) throws StandardException(Code)(Java Doc) public ValueNode checkIsBoolean() throws StandardException(Code)(Java Doc) public void checkReliability(String fragmentType, int fragmentBitMask) throws StandardException(Code)(Java Doc) public void checkReliability(int fragmentBitMask, String fragmentType) throws StandardException(Code)(Java Doc) void checkTopPredicatesForEqualsConditions(int tableNumber, boolean[] eqOuterCols, int[] tableNumbers, JBitSet[] tableColMap, boolean resultColTable) throws StandardException(Code)(Java Doc) public boolean constantExpression(PredicateList whereClause)(Code)(Java Doc) public void copyFields(ValueNode oldVN) throws StandardException(Code)(Java Doc) ValueNode eliminateNots(boolean underNotNode) throws StandardException(Code)(Java Doc) public ValueNode genEqualsFalseTree() throws StandardException(Code)(Java Doc) public ValueNode genIsNullTree() throws StandardException(Code)(Java Doc) public ValueNode genSQLJavaSQLTree() throws StandardException(Code)(Java Doc) final protected void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException(Code)(Java Doc) public void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException(Code)(Java Doc) public void generateFilter(ExpressionClassBuilder ecb, MethodBuilder mb) throws StandardException(Code)(Java Doc) public int getClause()(Code)(Java Doc) public ValueNode getClone() throws StandardException(Code)(Java Doc) public String getColumnName()(Code)(Java Doc) Object getConstantValueAsObject() throws StandardException(Code)(Java Doc) final protected DataValueFactory getDataValueFactory()(Code)(Java Doc) protected int getOrderableVariantType() throws StandardException(Code)(Java Doc) public String getSchemaName() throws StandardException(Code)(Java Doc) public ResultColumn getSourceResultColumn()(Code)(Java Doc) public String getTableName()(Code)(Java Doc) JBitSet getTablesReferenced() throws StandardException(Code)(Java Doc) boolean getTransformed()(Code)(Java Doc) public TypeCompiler getTypeCompiler() throws StandardException(Code)(Java Doc) public TypeId getTypeId() throws StandardException(Code)(Java Doc) public DataTypeDescriptor getTypeServices() throws StandardException(Code)(Java Doc) public void init(Object typeId, Object precision, Object scale, Object isNullable, Object maximumWidth) throws StandardException(Code)(Java Doc) public boolean isBinaryEqualsOperatorNode()(Code)(Java Doc) boolean isBooleanFalse()(Code)(Java Doc) boolean isBooleanTrue()(Code)(Java Doc) public boolean isCloneable()(Code)(Java Doc) public boolean isConstantExpression()(Code)(Java Doc) abstract protected boolean isEquivalent(ValueNode other) throws StandardException(Code)(Java Doc) public boolean isParameterNode()(Code)(Java Doc) public boolean isRelationalOperator()(Code)(Java Doc) final protected boolean isSameNodeType(ValueNode other)(Code)(Java Doc) public boolean optimizableEqualityNode(Optimizable optTable, int columnNumber, boolean isNullOkay) throws StandardException(Code)(Java Doc) public ValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException(Code)(Java Doc) public ValueNode putAndsOnTop() throws StandardException(Code)(Java Doc) public ValueNode remapColumnReferencesToExpressions() throws StandardException(Code)(Java Doc) public boolean requiresTypeFromContext()(Code)(Java Doc) public double selectivity(Optimizable optTable) throws StandardException(Code)(Java Doc) public void setClause(int clause)(Code)(Java Doc) void setTransformed()(Code)(Java Doc) public void setType(DataTypeDescriptor dataTypeServices) throws StandardException(Code)(Java Doc) public String toString()(Code)(Java Doc) public boolean updatableByCursor()(Code)(Java Doc) public boolean verifyChangeToCNF()(Code)(Java Doc) boolean verifyEliminateNots()(Code)(Java Doc) public boolean verifyPutAndsOnTop()(Code)(Java Doc)
|
Methods inherited from org.apache.derby.impl.sql.compile.QueryTreeNode | public Visitable accept(Visitor v) throws StandardException(Code)(Java Doc) public QueryTreeNode bind() throws StandardException(Code)(Java Doc) public DataValueDescriptor convertDefaultNode(DataTypeDescriptor typeDescriptor) throws StandardException(Code)(Java Doc) protected static void debugFlush()(Code)(Java Doc) public static void debugPrint(String outputString)(Code)(Java Doc) public void disablePrivilegeCollection()(Code)(Java Doc) public String executeSchemaName()(Code)(Java Doc) public String executeStatementName()(Code)(Java Doc) public static String formatNodeString(String nodeString, int depth)(Code)(Java Doc) public boolean foundString(String[] list, String search)(Code)(Java Doc) public GeneratedClass generate(ByteArray ignored) throws StandardException(Code)(Java Doc) protected void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException(Code)(Java Doc) void generateAuthorizeCheck(ActivationClassBuilder acb, MethodBuilder mb, int sqlOperation)(Code)(Java Doc) public int getBeginOffset()(Code)(Java Doc) final protected ClassFactory getClassFactory()(Code)(Java Doc) final protected CompilerContext getCompilerContext()(Code)(Java Doc) final public ContextManager getContextManager()(Code)(Java Doc) public Object getCursorInfo() throws StandardException(Code)(Java Doc) final public DataDictionary getDataDictionary()(Code)(Java Doc) final public DependencyManager getDependencyManager()(Code)(Java Doc) public int getEndOffset()(Code)(Java Doc) final public ExecutionFactory getExecutionFactory()(Code)(Java Doc) final public GenericConstantActionFactory getGenericConstantActionFactory()(Code)(Java Doc) protected int getIntProperty(String value, String key) throws StandardException(Code)(Java Doc) final protected LanguageConnectionContext getLanguageConnectionContext()(Code)(Java Doc) final public NodeFactory getNodeFactory()(Code)(Java Doc) protected int getNodeType()(Code)(Java Doc) public ConstantNode getNullNode(TypeId typeId, ContextManager cm) throws StandardException(Code)(Java Doc) public DataTypeDescriptor[] getParameterTypes() throws StandardException(Code)(Java Doc) public long getRowEstimate()(Code)(Java Doc) public String getSPSName()(Code)(Java Doc) final SchemaDescriptor getSchemaDescriptor(String schemaName) throws StandardException(Code)(Java Doc) final SchemaDescriptor getSchemaDescriptor(String schemaName, boolean raiseError) throws StandardException(Code)(Java Doc) protected int getStatementType()(Code)(Java Doc) final protected TableDescriptor getTableDescriptor(String tableName, SchemaDescriptor schema) throws StandardException(Code)(Java Doc) final protected TypeCompiler getTypeCompiler(TypeId typeId)(Code)(Java Doc) public void init(Object arg1) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) throws StandardException(Code)(Java Doc) public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) throws StandardException(Code)(Java Doc) public boolean isAtomic() throws StandardException(Code)(Java Doc) protected boolean isInstanceOf(int nodeType)(Code)(Java Doc) public boolean isPrivilegeCollectionRequired()(Code)(Java Doc) final boolean isSessionSchema(SchemaDescriptor sd)(Code)(Java Doc) final boolean isSessionSchema(String schemaName)(Code)(Java Doc) public ConstantAction makeConstantAction() throws StandardException(Code)(Java Doc) public ResultDescription makeResultDescription() throws StandardException(Code)(Java Doc) public TableName makeTableName(String schemaName, String flatName) throws StandardException(Code)(Java Doc) public boolean needsSavepoint()(Code)(Java Doc) protected String nodeHeader()(Code)(Java Doc) public QueryTreeNode optimize() throws StandardException(Code)(Java Doc) public static QueryTreeNode parseQueryText(CompilerContext compilerContext, String queryText, Object[] paramDefaults, LanguageConnectionContext lcc) throws StandardException(Code)(Java Doc) public void printLabel(int depth, String label)(Code)(Java Doc) public void printSubNodes(int depth)(Code)(Java Doc) public boolean referencesSessionSchema() throws StandardException(Code)(Java Doc) public TableName resolveTableToSynonym(TableName tabName) throws StandardException(Code)(Java Doc) public void setBeginOffset(int beginOffset)(Code)(Java Doc) public void setContextManager(ContextManager cm)(Code)(Java Doc) public void setEndOffset(int endOffset)(Code)(Java Doc) public void setNodeType(int nodeType)(Code)(Java Doc) public void setRefActionInfo(long fkIndexConglomId, int[] fkColArray, String parentResultSetId, boolean dependentScan)(Code)(Java Doc) public String toString()(Code)(Java Doc) public void treePrint()(Code)(Java Doc) public void treePrint(int depth)(Code)(Java Doc) String verifyClassExist(String javaClassName, boolean convertCase) throws StandardException(Code)(Java Doc)
|
|
|