Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class FromSubquery

extends FromTable
Class Inheritance
Imports
java.util.Properties, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.CompilerContext, .Visitor, org.apache.derby.iapi.sql.dictionary.DataDictionary, .SchemaDescriptor, org.apache.derby.iapi.util.JBitSet

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.

Field Summary

Modifier and TypeField and Description
private ValueNode
private boolean
private ValueNode
private OrderByList
private SchemaDescriptor
origCompilationSchema

DERBY-3270: If this subquery represents an expanded view, this holds the current compilation schema at view definition time.

pack-priv ResultSetNode
Inherited from org.apache.derby.impl.sql.compile.FromTable:
ADD_PLANbestAccessPathbestCostEstimatebestSortAvoidancePathcorrelationNamecorrTableNamecurrentAccessPathhashKeyColumnsinitialCapacitylevelLOAD_PLANloadFactormaxCapacityorigTableNameREMOVE_PLANtableNumbertablePropertiestrulyTheBestAccessPathuserSpecifiedJoinStrategy

Constructor Summary

AccessConstructor and Description
pack-priv
FromSubquery(ResultSetNode
The subquery
subquery
,
OrderByList
ORDER BY list if any, or null
orderByList
,
ValueNode
OFFSET if any, or null
offset
,
ValueNode
FETCH FIRST if any, or null
fetchFirst
,
boolean
True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntax
hasJDBClimitClause
,
String
The correlation name
correlationName
,
ResultColumnList
The derived column list
derivedRCL
,
Properties
Properties list associated with the table
tableProperties
,
ContextManager
The context manager
cm
)

Constructor for a table in a FROM list.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

Overrides org.apache.derby.impl.sql.compile.FromTable.acceptChildren.

Accept the visitor for all visitable children of this node.

pack-priv void
bindExpressions(FromList
FromList to use/append to.
fromListParam
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.bindExpressions.

Bind the expressions in this FromSubquery.

pack-priv ResultSetNode

Returns:

ResultSetNode The bound FromSubquery.
bindNonVTITables
(DataDictionary
The DataDictionary to use for binding
dataDictionary
,
FromList
FromList to use/append to.
fromListParam
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.bindNonVTITables.

Bind this subquery that appears in the FROM list.

pack-priv void
bindUntypedNullsToResultColumns(ResultColumnList
The ResultColumnList with the types to bind to.
bindingRCL
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.bindUntypedNullsToResultColumns.

Bind any untyped null nodes to the types in the given ResultColumnList.

pack-priv ResultSetNode

Returns:

ResultSetNode The bound FromSubquery.
bindVTITables
(FromList
FromList to use/append to.
fromListParam
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.bindVTITables.

Bind this subquery that appears in the FROM list.

pack-priv void
decrementLevel(int
The amount to decrement by.
decrement
)

Overrides org.apache.derby.impl.sql.compile.FromTable.decrementLevel.

Decrement (query block) level (0-based) for this FromTable.

pack-priv ResultSetNode

Returns:

ResultSetNode at top of extracted tree.
extractSubquery
(int
The number of tables in the DML Statement
numTables
)

Extract out and return the subquery, with a PRN on top.

pack-priv FromList

Returns:

FromList The fromList from the underlying SelectNode.
flatten
(ResultColumnList
The RCL from the outer query
rcl
,
PredicateList
PredicateList to append wherePredicates to.
outerPList
,
SubqueryList
The SubqueryList from the outer query
sql
,
GroupByList
The group by list, if any
gbl
,
ValueNode
The HAVING clause, if any
havingClause
)

Overrides org.apache.derby.impl.sql.compile.FromTable.flatten.

Flatten this FSqry into the outer query block.

pack-priv ResultColumnList
getAllResultColumns(TableName
The qualifier on the "*"
allTableName
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getAllResultColumns.

Expand a "*" into a ResultColumnList with all of the result columns from the subquery.

pack-priv String

Returns:

The exposed name for this table.
getExposedName
()

Overrides org.apache.derby.impl.sql.compile.FromTable.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.

pack-priv FromTable

Returns:

The FromTable, if any, with the exposed name.
getFromTableByName
(String
The specified name to search for as an exposed name.
name
,
String
Schema name, if non-null.
schemaName
,
boolean
Whether or not we need an exact match on specified schema and table names or match on table id.
exactMatch
)

Overrides org.apache.derby.impl.sql.compile.FromTable.getFromTableByName.

Determine whether or not the specified name is an exposed name in the current query block.

pack-priv ResultColumn

Returns:

A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
getMatchingColumn
(ColumnReference
The columnReference whose name we're looking for in the given table.
columnReference
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getMatchingColumn.

Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.

pack-priv ResultSetNode

Returns:

ResultSetNode The "subquery" from this node.
getSubquery
()

Return the "subquery" from this node.

pack-priv ResultSetNode

Returns:

ResultSetNode at top of preprocessed tree.
preprocess
(int
The number of tables in the DML Statement
numTables
,
GroupByList
The group by list, if any
gbl
,
FromList
The from list, if any
fromList
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.preprocess.

Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode.

pack-priv void
printSubNodes(int
The depth of this node in the tree
depth
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.printSubNodes.

Prints the sub-nodes of this object.

public boolean

Returns:

true if references SESSION schema tables, else false
referencesSessionSchema
()

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.referencesSessionSchema.

Return true if the node references SESSION schema tables (temporary or permanent)

pack-priv boolean

Returns:

true if found, else false
referencesTarget
(String
Table name (String) to search for.
name
,
boolean
Whether or not name is for a base table
baseTable
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.referencesTarget.

Search to see if a query references the specifed table name.

pack-priv void
pack-priv void
setOrigCompilationSchema(SchemaDescriptor
schema descriptor of the original compilation schema of the view.
sd
)

Associate this subquery with the original compilation schema of a view.

Inherited from org.apache.derby.impl.sql.compile.FromTable:
assignCostEstimatecanBeOrderedcolumnsAreUpdatableconsiderSortAvoidancePathconvertAbsoluteToRelativeColumnPositioncursorTargetTableestimateCostfeasibleJoinStrategyfillInReferencedTableMapforUpdategetBaseTableNamegetBestAccessPathgetBestSortAvoidancePathgetCorrelationNamegetCostEstimategetCurrentAccessPathgetFinalCostEstimategetLevelgetMergeTableIDgetNamegetNumColumnsReturnedgetOrigTableNamegetPropertiesgetResultColumnsForListgetSchemaDescriptorgetSchemaDescriptorgetScratchCostEstimategetTableDescriptorgetTableNamegetTableNumbergetTrulyTheBestAccessPathgetUserSpecifiedJoinStrategyhashKeyColumnshasLargeObjectColumnshasTableNumberinitAccessPathsinitialCapacityisBaseTableisCoveringIndexisFlattenableJoinNodeisJoinColumnForRightOuterJoinisMaterializableisOneRowScanisTargetTablelegalJoinOrderloadFactorLOJ_reorderablemarkUpdatableByCursormaxCapacitymemoryUsageOKmodifyAccessPathneedsSpecialRCLBindingnextAccessPathoptimizeItoptimizeSubqueriespullOptPredicatespushExpressionspushOptPredicaterememberAsBestrememberJoinStrategyAsBestrememberSortAvoidancePathresetJoinStrategiessetCostEstimateCostsetHashKeyColumnssetLevelsetMergeTableIDsetOrigTableNamesetPropertiessetTableNumberstartOptimizingsupportsMultipleInstantiationstellRowOrderingAboutConstantColumnstoStringtransformOuterJoinsuniqueJoinupdateBestPlanMapverifyProperties

Field Detail

fetchFirstback to summary
private ValueNode fetchFirst
hasJDBClimitClauseback to summary
private boolean hasJDBClimitClause
offsetback to summary
private ValueNode offset
orderByListback to summary
private OrderByList orderByList
origCompilationSchemaback to summary
private SchemaDescriptor origCompilationSchema

DERBY-3270: If this subquery represents an expanded view, this holds the current compilation schema at view definition time.

subqueryback to summary
pack-priv ResultSetNode subquery

Constructor Detail

FromSubqueryback to summary
pack-priv 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:ResultSetNode

The subquery

orderByList:OrderByList

ORDER BY list if any, or null

offset:ValueNode

OFFSET if any, or null

fetchFirst:ValueNode

FETCH FIRST if any, or null

hasJDBClimitClause:boolean

True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntax

correlationName:String

The correlation name

derivedRCL:ResultColumnList

The derived column list

tableProperties:Properties

Properties list associated with the table

cm:ContextManager

The context manager

Method Detail

acceptChildrenback to summary
pack-priv void acceptChildren(Visitor v) throws StandardException

Overrides org.apache.derby.impl.sql.compile.FromTable.acceptChildren.

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.acceptChildren.

Accept the visitor for all visitable children of this node.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on error
See Also
QueryTreeNode#acceptChildren
bindExpressionsback to summary
pack-priv void bindExpressions(FromList fromListParam) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.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.

Parameters
fromListParam:FromList

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.bindExpressions.

FromList to use/append to.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
bindNonVTITablesback to summary
pack-priv ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.bindNonVTITables.

Bind this subquery that appears in the FROM list.

Parameters
dataDictionary:DataDictionary

The DataDictionary to use for binding

fromListParam:FromList

FromList to use/append to.

Returns:ResultSetNode

ResultSetNode The bound FromSubquery.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
bindUntypedNullsToResultColumnsback to summary
pack-priv void bindUntypedNullsToResultColumns(ResultColumnList bindingRCL) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.bindUntypedNullsToResultColumns.

Bind any untyped null nodes to the types in the given ResultColumnList.

Parameters
bindingRCL:ResultColumnList

The ResultColumnList with the types to bind to.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
bindVTITablesback to summary
pack-priv ResultSetNode bindVTITables(FromList fromListParam) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.bindVTITables.

Bind this subquery that appears in the FROM list.

Parameters
fromListParam:FromList

FromList to use/append to.

Returns:ResultSetNode

ResultSetNode The bound FromSubquery.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
decrementLevelback to summary
pack-priv void decrementLevel(int decrement)

Overrides org.apache.derby.impl.sql.compile.FromTable.decrementLevel.

Decrement (query block) level (0-based) for this FromTable. This is useful when flattening a subquery.

Parameters
decrement:int

The amount to decrement by.

Annotations
@Override
extractSubqueryback to summary
pack-priv ResultSetNode extractSubquery(int numTables) throws StandardException

Extract out and return the subquery, with a PRN on top. (See FromSubquery.preprocess() for more details.)

Parameters
numTables:int

The number of tables in the DML Statement

Returns:ResultSetNode

ResultSetNode at top of extracted tree.

Exceptions
StandardException:
Thrown on error
flattenback to summary
pack-priv FromList flatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause) throws StandardException

Overrides org.apache.derby.impl.sql.compile.FromTable.flatten.

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.

Parameters
rcl:ResultColumnList

The RCL from the outer query

outerPList:PredicateList

PredicateList to append wherePredicates to.

sql:SubqueryList

The SubqueryList from the outer query

gbl:GroupByList

The group by list, if any

havingClause:ValueNode

The HAVING clause, if any

Returns:FromList

FromList The fromList from the underlying SelectNode.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getAllResultColumnsback to summary
pack-priv ResultColumnList getAllResultColumns(TableName allTableName) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getAllResultColumns.

Expand a "*" into a ResultColumnList with all of the result columns from the subquery.

Parameters
allTableName:TableName

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.getAllResultColumns.

The qualifier on the "*"

Returns:ResultColumnList

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.getAllResultColumns.

ResultColumnList The expanded list, or null if allTableName is non-null and doesn't match a table name in this result set

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getExposedNameback to summary
pack-priv String getExposedName()

Overrides org.apache.derby.impl.sql.compile.FromTable.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.

Returns:String

The exposed name for this table.

Annotations
@Override
getFromTableByNameback to summary
pack-priv FromTable getFromTableByName(String name, String schemaName, boolean exactMatch) throws StandardException

Overrides org.apache.derby.impl.sql.compile.FromTable.getFromTableByName.

Determine whether or not the specified name is an exposed name in the current query block.

Parameters
name:String

The specified name to search for as an exposed name.

schemaName:String

Schema name, if non-null.

exactMatch:boolean

Whether or not we need an exact match on specified schema and table names or match on table id.

Returns:FromTable

The FromTable, if any, with the exposed name.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getMatchingColumnback to summary
pack-priv ResultColumn getMatchingColumn(ColumnReference columnReference) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getMatchingColumn.

Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.

Parameters
columnReference:ColumnReference

The columnReference whose name we're looking for in the given table.

Returns:ResultColumn

A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getSubqueryback to summary
pack-priv ResultSetNode getSubquery()

Return the "subquery" from this node.

Returns:ResultSetNode

ResultSetNode The "subquery" from this node.

preprocessback to summary
pack-priv ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.preprocess.

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.

Parameters
numTables:int

The number of tables in the DML Statement

gbl:GroupByList

The group by list, if any

fromList:FromList

The from list, if any

Returns:ResultSetNode

ResultSetNode at top of preprocessed tree.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
printSubNodesback to summary
pack-priv void printSubNodes(int depth)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.printSubNodes.

Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Parameters
depth:int

The depth of this node in the tree

Annotations
@Override
referencesSessionSchemaback to summary
public boolean referencesSessionSchema() throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.referencesSessionSchema.

Return true if the node references SESSION schema tables (temporary or permanent)

Returns:boolean

true if references SESSION schema tables, else false

Annotations
@Override
Exceptions
StandardException:
Thrown on error
referencesTargetback to summary
pack-priv boolean referencesTarget(String name, boolean baseTable) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.referencesTarget.

Search to see if a query references the specifed table name.

Parameters
name:String

Table name (String) to search for.

baseTable:boolean

Whether or not name is for a base table

Returns:boolean

true if found, else false

Annotations
@Override
Exceptions
StandardException:
Thrown on error
rejectParametersback to summary
pack-priv void rejectParameters() throws StandardException

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.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.

Annotations
@Override
Exceptions
StandardException:
Thrown if a ? parameter found directly under a ResultColumn
setOrigCompilationSchemaback to summary
pack-priv void setOrigCompilationSchema(SchemaDescriptor sd)

Associate this subquery with the original compilation schema of a view.

Parameters
sd:SchemaDescriptor

schema descriptor of the original compilation schema of the view.