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 ResultSetNode
ResultSetNode.QueryExpressionClauses -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ValueNodeprivate booleanprivate ValueNodeprivate OrderByListprivate SchemaDescriptorDERBY-3270: If this subquery represents an expanded view, this holds the current compilation schema at view definition time.(package private) ResultSetNodeFields inherited from class FromTable
ADD_PLAN, bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, LOAD_PLAN, loadFactor, maxCapacity, origTableName, REMOVE_PLAN, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategyFields inherited from class 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) voidAccept the visitor for all visitable children of this node.(package private) voidbindExpressions(FromList fromListParam) Bind the expressions in this FromSubquery.(package private) ResultSetNodebindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) Bind this subquery that appears in the FROM list.(package private) voidbindUntypedNullsToResultColumns(ResultColumnList bindingRCL) Bind any untyped null nodes to the types in the given ResultColumnList.(package private) ResultSetNodebindVTITables(FromList fromListParam) Bind this subquery that appears in the FROM list.(package private) voiddecrementLevel(int decrement) Decrement (query block) level (0-based) for this FromTable.(package private) ResultSetNodeextractSubquery(int numTables) Extract out and return the subquery, with a PRN on top.(package private) FromListflatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause) Flatten this FSqry into the outer query block.(package private) ResultColumnListgetAllResultColumns(TableName allTableName) Expand a "*" into a ResultColumnList with all of the result columns from the subquery.(package private) StringGet 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) FromTablegetFromTableByName(String name, String schemaName, boolean exactMatch) Determine whether or not the specified name is an exposed name in the current query block.(package private) ResultColumngetMatchingColumn(ColumnReference columnReference) Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.(package private) ResultSetNodeReturn the "subquery" from this node.(package private) ResultSetNodepreprocess(int numTables, GroupByList gbl, FromList fromList) Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode.(package private) voidprintSubNodes(int depth) Prints the sub-nodes of this object.booleanReturn true if the node references SESSION schema tables (temporary or permanent)(package private) booleanreferencesTarget(String name, boolean baseTable) Search to see if a query references the specifed table name.(package private) voidCheck for (and reject) ?(package private) voidAssociate this subquery with the original compilation schema of a view.Methods inherited from class 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, verifyPropertiesMethods inherited from class 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, verifySelectStarSubqueryMethods inherited from class 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, verifyClassExistMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Optimizable
getDataDictionary, getOptimizerTracer, getReferencedTableMap, getResultSetNumber, optimizerTracingIsOnMethods inherited from interface 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:
printSubNodesin 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:
getFromTableByNamein 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:
bindNonVTITablesin 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:
bindVTITablesin 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:
rejectParametersin 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:
bindExpressionsin 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:
getMatchingColumnin 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:
preprocessin 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:
flattenin 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:
getExposedNamein classFromTable- Returns:
- The exposed name for this table.
-
getAllResultColumns
Expand a "*" into a ResultColumnList with all of the result columns from the subquery.- Overrides:
getAllResultColumnsin classResultSetNode- Parameters:
allTableName- The qualifier on the "*"- Returns:
- ResultColumnList The expanded list, or
nullifallTableNameis 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:
referencesTargetin 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:
referencesSessionSchemain 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:
bindUntypedNullsToResultColumnsin 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:
decrementLevelin 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:ResultSetNodeAccept the visitor for all visitable children of this node.- Overrides:
acceptChildrenin classFromTable- Parameters:
v- the visitor- Throws:
StandardException- on error- See Also:
-