Class FromSubquery
java.lang.Object
org.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.ResultSetNode
org.apache.derby.impl.sql.compile.FromTable
org.apache.derby.impl.sql.compile.FromSubquery
- All Implemented Interfaces:
Optimizable
,Visitable
A FromSubquery represents a subquery in the FROM list of a DML statement.
The current implementation of this class is only
sufficient for Insert's need to push a new
select on top of the one the user specified,
to make the selected structure match that
of the insert target table.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
ResultSetNode.QueryExpressionClauses
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ValueNode
private boolean
private ValueNode
private OrderByList
private SchemaDescriptor
DERBY-3270: If this subquery represents an expanded view, this holds the current compilation schema at view definition time.(package private) ResultSetNode
Fields inherited from class org.apache.derby.impl.sql.compile.FromTable
ADD_PLAN, bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, LOAD_PLAN, loadFactor, maxCapacity, origTableName, REMOVE_PLAN, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategy
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
Constructor Summary
ConstructorsConstructorDescriptionFromSubquery
(ResultSetNode subquery, OrderByList orderByList, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, String correlationName, ResultColumnList derivedRCL, Properties tableProperties, ContextManager cm) Constructor for a table in a FROM list. -
Method Summary
Modifier and TypeMethodDescription(package private) void
Accept the visitor for all visitable children of this node.(package private) void
bindExpressions
(FromList fromListParam) Bind the expressions in this FromSubquery.(package private) ResultSetNode
bindNonVTITables
(DataDictionary dataDictionary, FromList fromListParam) Bind this subquery that appears in the FROM list.(package private) void
bindUntypedNullsToResultColumns
(ResultColumnList bindingRCL) Bind any untyped null nodes to the types in the given ResultColumnList.(package private) ResultSetNode
bindVTITables
(FromList fromListParam) Bind this subquery that appears in the FROM list.(package private) void
decrementLevel
(int decrement) Decrement (query block) level (0-based) for this FromTable.(package private) ResultSetNode
extractSubquery
(int numTables) Extract out and return the subquery, with a PRN on top.(package private) FromList
flatten
(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause) Flatten this FSqry into the outer query block.(package private) ResultColumnList
getAllResultColumns
(TableName allTableName) Expand a "*" into a ResultColumnList with all of the result columns from the subquery.(package private) String
Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.(package private) FromTable
getFromTableByName
(String name, String schemaName, boolean exactMatch) Determine whether or not the specified name is an exposed name in the current query block.(package private) ResultColumn
getMatchingColumn
(ColumnReference columnReference) Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.(package private) ResultSetNode
Return the "subquery" from this node.(package private) ResultSetNode
preprocess
(int numTables, GroupByList gbl, FromList fromList) Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode.(package private) void
printSubNodes
(int depth) Prints the sub-nodes of this object.boolean
Return true if the node references SESSION schema tables (temporary or permanent)(package private) boolean
referencesTarget
(String name, boolean baseTable) Search to see if a query references the specifed table name.(package private) void
Check for (and reject) ?(package private) void
Associate this subquery with the original compilation schema of a view.Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
assignCostEstimate, canBeOrdered, columnsAreUpdatable, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, feasibleJoinStrategy, fillInReferencedTableMap, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getFinalCostEstimate, getLevel, getMergeTableID, getName, getNumColumnsReturned, getOrigTableName, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasLargeObjectColumns, hasTableNumber, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isJoinColumnForRightOuterJoin, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, modifyAccessPath, needsSpecialRCLBinding, nextAccessPath, optimizeIt, optimizeSubqueries, pullOptPredicates, pushExpressions, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimateCost, setHashKeyColumns, setLevel, setMergeTableID, setOrigTableName, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, toString, transformOuterJoins, uniqueJoin, updateBestPlanMap, verifyProperties
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, adjustForSortElimination, adjustForSortElimination, assignResultSetNumber, bindExpressionsWithTables, bindResultColumns, bindResultColumns, bindTargetExpressions, changeAccessPath, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getCandidateFinalCostEstimate, getCostEstimate, getCursorTargetTable, getFromList, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, getScratchCostEstimate, isCursorTargetTable, isInsertSource, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isStatementResultSet, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, optimize, parseDefault, performMaterialization, printQueryExpressionSuffixClauses, projectResultColumns, pushOffsetFetchFirst, pushOrderByList, pushQueryExpressionSuffix, rejectXMLValues, renameGeneratedResultNames, replaceOrForbidDefaults, returnsAtMostOneRow, setCandidateFinalCostEstimate, setCostEstimate, setCursorTargetTable, setInsertSource, setOptimizer, setReferencedTableMap, setResultColumns, setResultSetNumber, setResultToBooleanTrueNode, setScratchCostEstimate, setTableConstructorTypes, subqueryReferencesTarget, updateTargetLockMode, verifySelectStarSubquery
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generate, 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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.derby.iapi.sql.compile.Optimizable
getDataDictionary, getOptimizerTracer, getReferencedTableMap, getResultSetNumber, optimizerTracingIsOn
Methods inherited from interface org.apache.derby.iapi.sql.compile.Visitable
accept, addTag, taggedWith
-
Field Details
-
subquery
ResultSetNode subquery -
orderByList
-
offset
-
fetchFirst
-
hasJDBClimitClause
private boolean hasJDBClimitClause -
origCompilationSchema
DERBY-3270: If this subquery represents an expanded view, this holds the current compilation schema at view definition time.
-
-
Constructor Details
-
FromSubquery
FromSubquery(ResultSetNode subquery, OrderByList orderByList, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, String correlationName, ResultColumnList derivedRCL, Properties tableProperties, ContextManager cm) Constructor for a table in a FROM list.- Parameters:
subquery
- The subqueryorderByList
- ORDER BY list if any, or nulloffset
- OFFSET if any, or nullfetchFirst
- FETCH FIRST if any, or nullhasJDBClimitClause
- True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntaxcorrelationName
- The correlation namederivedRCL
- The derived column listtableProperties
- Properties list associated with the tablecm
- The context manager
-
-
Method Details
-
printSubNodes
void printSubNodes(int depth) Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.- Overrides:
printSubNodes
in classResultSetNode
- Parameters:
depth
- The depth of this node in the tree
-
getSubquery
ResultSetNode getSubquery()Return the "subquery" from this node.- Returns:
- ResultSetNode The "subquery" from this node.
-
getFromTableByName
FromTable getFromTableByName(String name, String schemaName, boolean exactMatch) throws StandardException Determine whether or not the specified name is an exposed name in the current query block.- Overrides:
getFromTableByName
in classFromTable
- Parameters:
name
- The specified name to search for as an exposed name.schemaName
- Schema name, if non-null.exactMatch
- Whether or not we need an exact match on specified schema and table names or match on table id.- Returns:
- The FromTable, if any, with the exposed name.
- Throws:
StandardException
- Thrown on error
-
bindNonVTITables
ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) throws StandardException Bind this subquery that appears in the FROM list.- Overrides:
bindNonVTITables
in classResultSetNode
- Parameters:
dataDictionary
- The DataDictionary to use for bindingfromListParam
- FromList to use/append to.- Returns:
- ResultSetNode The bound FromSubquery.
- Throws:
StandardException
- Thrown on error
-
bindVTITables
Bind this subquery that appears in the FROM list.- Overrides:
bindVTITables
in classResultSetNode
- Parameters:
fromListParam
- FromList to use/append to.- Returns:
- ResultSetNode The bound FromSubquery.
- Throws:
StandardException
- Thrown on error
-
rejectParameters
Check for (and reject) ? parameters directly under the ResultColumns. This is done for SELECT statements. For FromSubquery, we simply pass the check through to the subquery.- Overrides:
rejectParameters
in classResultSetNode
- Throws:
StandardException
- Thrown if a ? parameter found directly under a ResultColumn
-
bindExpressions
Bind the expressions in this FromSubquery. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.- Overrides:
bindExpressions
in classResultSetNode
- Parameters:
fromListParam
- FromList to use/append to.- Throws:
StandardException
- Thrown on error
-
getMatchingColumn
Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.- Overrides:
getMatchingColumn
in classResultSetNode
- Parameters:
columnReference
- The columnReference whose name we're looking for in the given table.- Returns:
- A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
- Throws:
StandardException
- Thrown on error
-
preprocess
ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode. o Putting the WHERE and HAVING clauses in conjunctive normal form (CNF). o Converting the WHERE and HAVING clauses into PredicateLists and classifying them. o Ensuring that a ProjectRestrictNode is generated on top of every FromBaseTable and generated in place of every FromSubquery. o Pushing single table predicates down to the new ProjectRestrictNodes.- Overrides:
preprocess
in classResultSetNode
- Parameters:
numTables
- The number of tables in the DML Statementgbl
- The group by list, if anyfromList
- The from list, if any- Returns:
- ResultSetNode at top of preprocessed tree.
- Throws:
StandardException
- Thrown on error
-
extractSubquery
Extract out and return the subquery, with a PRN on top. (See FromSubquery.preprocess() for more details.)- Parameters:
numTables
- The number of tables in the DML Statement- Returns:
- ResultSetNode at top of extracted tree.
- Throws:
StandardException
- Thrown on error
-
flatten
FromList flatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause) throws StandardException Flatten this FSqry into the outer query block. The steps in flattening are: o Mark all ResultColumns as redundant, so that they are "skipped over" at generate(). o Append the wherePredicates to the outer list. o Return the fromList so that the caller will merge the 2 lists RESOLVE - FSqrys with subqueries are currently not flattenable. Some of them can be flattened, however. We need to merge the subquery list when we relax this restriction. NOTE: This method returns NULL when flattening RowResultSetNodes (the node for a VALUES clause). The reason is that no reference is left to the RowResultSetNode after flattening is done - the expressions point directly to the ValueNodes in the RowResultSetNode's ResultColumnList.- Overrides:
flatten
in classFromTable
- Parameters:
rcl
- The RCL from the outer queryouterPList
- PredicateList to append wherePredicates to.sql
- The SubqueryList from the outer querygbl
- The group by list, if anyhavingClause
- The HAVING clause, if any- Returns:
- FromList The fromList from the underlying SelectNode.
- Throws:
StandardException
- Thrown on error
-
getExposedName
String getExposedName()Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.- Overrides:
getExposedName
in classFromTable
- Returns:
- The exposed name for this table.
-
getAllResultColumns
Expand a "*" into a ResultColumnList with all of the result columns from the subquery.- Overrides:
getAllResultColumns
in classResultSetNode
- Parameters:
allTableName
- The qualifier on the "*"- Returns:
- ResultColumnList The expanded list, or
null
ifallTableName
is non-null and doesn't match a table name in this result set - Throws:
StandardException
- Thrown on error
-
referencesTarget
Search to see if a query references the specifed table name.- Overrides:
referencesTarget
in classResultSetNode
- Parameters:
name
- Table name (String) to search for.baseTable
- Whether or not name is for a base table- Returns:
- true if found, else false
- Throws:
StandardException
- Thrown on error
-
referencesSessionSchema
Return true if the node references SESSION schema tables (temporary or permanent)- Overrides:
referencesSessionSchema
in classQueryTreeNode
- Returns:
- true if references SESSION schema tables, else false
- Throws:
StandardException
- Thrown on error
-
bindUntypedNullsToResultColumns
Bind any untyped null nodes to the types in the given ResultColumnList.- Overrides:
bindUntypedNullsToResultColumns
in classResultSetNode
- Parameters:
bindingRCL
- The ResultColumnList with the types to bind to.- Throws:
StandardException
- Thrown on error
-
decrementLevel
void decrementLevel(int decrement) Decrement (query block) level (0-based) for this FromTable. This is useful when flattening a subquery.- Overrides:
decrementLevel
in classFromTable
- Parameters:
decrement
- The amount to decrement by.
-
setOrigCompilationSchema
Associate this subquery with the original compilation schema of a view.- Parameters:
sd
- schema descriptor of the original compilation schema of the view.
-
acceptChildren
Description copied from class:ResultSetNode
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classFromTable
- Parameters:
v
- the visitor- Throws:
StandardException
- on error- See Also:
-