|
|||||||||
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.ResultSetNode
public abstract class ResultSetNode
A ResultSetNode represents a result set, that is, a set of rows. It is analogous to a ResultSet in the LanguageModuleExternalInterface. In fact, code generation for a a ResultSetNode will create a "new" call to a constructor for a ResultSet.
Field Summary | |
---|---|
(package private) CostEstimate |
costEstimate
|
(package private) boolean |
cursorTargetTable
|
(package private) CostEstimate |
finalCostEstimate
|
(package private) boolean |
insertSource
|
(package private) Optimizer |
optimizer
|
(package private) JBitSet |
referencedTableMap
|
(package private) ResultColumnList |
resultColumns
|
(package private) int |
resultSetNumber
|
(package private) CostEstimate |
scratchCostEstimate
|
(package private) boolean |
statementResultSet
|
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode |
---|
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired |
Constructor Summary | |
---|---|
ResultSetNode()
|
Method Summary | |
---|---|
(package private) void |
acceptChildren(Visitor v)
Accept the visitor for all visitable children of this node. |
ResultSetNode |
addNewPredicate(Predicate predicate)
Add a new predicate to the list. |
(package private) void |
adjustForSortElimination()
Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort. |
(package private) void |
adjustForSortElimination(RequiredRowOrdering rowOrdering)
Same goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed. |
void |
assignResultSetNumber()
Assign the next resultSetNumber to the resultSetNumber in this ResultSetNode. |
void |
bindExpressions(FromList fromListParam)
Bind the expressions in this ResultSetNode. |
void |
bindExpressionsWithTables(FromList fromListParam)
Bind the expressions in this ResultSetNode if it has tables. |
ResultSetNode |
bindNonVTITables(DataDictionary dataDictionary,
FromList fromListParam)
Bind the non VTI tables in this ResultSetNode. |
void |
bindResultColumns(FromList fromListParam)
Bind the result columns of this ResultSetNode when there is no base table to bind them to. |
void |
bindResultColumns(TableDescriptor targetTableDescriptor,
FromVTI targetVTI,
ResultColumnList targetColumnList,
DMLStatementNode statement,
FromList fromListParam)
Bind the result columns for this ResultSetNode to a base table. |
void |
bindTargetExpressions(FromList fromListParam)
Bind the expressions in the target list. |
void |
bindUntypedNullsToResultColumns(ResultColumnList rcl)
Bind untyped nulls to the types in the given ResultColumnList. |
ResultSetNode |
bindVTITables(FromList fromListParam)
Bind the VTI tables in this ResultSetNode. |
ResultSetNode |
changeAccessPath()
The optimizer's decision on the access path for a result set may require the generation of extra result sets. |
(package private) boolean |
columnTypesAndLengthsMatch()
|
ResultSetNode |
considerMaterialization(JBitSet outerTables)
Consider materialization for this ResultSet tree if it is valid and cost effective (It is not valid if incorrect results would be returned.) |
private ResultColumn |
createGeneratedColumn(TableDescriptor targetTD,
ColumnDescriptor colDesc)
Create a ResultColumn for a column with a generation clause. |
(package private) abstract void |
decrementLevel(int decrement)
Decrement (query block) level (0-based) for all of the tables in this ResultSet tree. |
void |
disablePrivilegeCollection()
Triggers, constraints and views get executed with their definer's privileges and they can exist in the system only if their definers' still have all the privileges to creeate them. |
(package private) ResultSetNode |
enhanceRCLForInsert(InsertNode target,
boolean inOrder,
int[] colMap)
This ResultSet is the source for an Insert. |
ResultSetNode |
ensurePredicateList(int numTables)
Ensure that the top of the RSN tree has a PredicateList. |
void |
fillInReferencedTableMap(JBitSet passedMap)
Fill the referencedTableMap with this ResultSetNode. |
boolean |
flattenableInFromSubquery(FromList fromList)
Evaluate whether or not the subquery in a FromSubquery is flattenable. |
void |
generateNormalizationResultSet(ActivationClassBuilder acb,
MethodBuilder mb,
int resultSetNumber,
ResultDescription resultDescription)
Generate the code for a NormalizeResultSet. |
private ResultSetNode |
generateProjectRestrictForInsert(InsertNode target,
int[] colMap)
Generate a ProjectRestrictNode to put on top of this node if it's the source for an insert, and the RCL needs reordering and/or addition of columns in order to match the target RCL. |
void |
generateResultSet(ExpressionClassBuilder acb,
MethodBuilder mb)
General logic shared by Core compilation and by the Replication Filter compiler. |
private ResultColumn |
genNewRCForInsert(TableDescriptor targetTD,
FromVTI targetVTI,
int columnNumber,
DataDictionary dataDictionary)
Generate the RC/expression for an unspecified column in an insert. |
ResultSetNode |
genProjectRestrict()
Put a ProjectRestrictNode on top of this ResultSetNode. |
protected ResultSetNode |
genProjectRestrict(int numTables)
Put a ProjectRestrictNode on top of each FromTable in the FromList. |
(package private) ResultSetNode |
genProjectRestrictForReordering()
Get a parent ProjectRestrictNode above us. |
ResultColumnList |
getAllResultColumns(TableName allTableName)
Expand "*" into a ResultColumnList with all of the columns in the table's result list. |
CostEstimate |
getCostEstimate()
Get the CostEstimate for this ResultSetNode. |
(package private) FromTable |
getCursorTargetTable()
return the target table of an updatable cursor result set. |
CostEstimate |
getFinalCostEstimate()
Get the final CostEstimate for this ResultSetNode. |
FromList |
getFromList()
Get the FromList. |
protected FromTable |
getFromTableByName(java.lang.String name,
java.lang.String schemaName,
boolean exactMatch)
Determine whether or not the specified name is an exposed name in the current query block. |
ResultColumn |
getMatchingColumn(ColumnReference columnReference)
Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference. |
protected CostEstimate |
getNewCostEstimate()
Get a cost estimate to use for this ResultSetNode. |
protected Optimizer |
getOptimizer(OptimizableList optList,
OptimizablePredicateList predList,
DataDictionary dataDictionary,
RequiredRowOrdering requiredRowOrdering)
Get an optimizer to use for this ResultSetNode. |
protected OptimizerImpl |
getOptimizerImpl()
Get the optimizer for this result set. |
(package private) ResultColumnList |
getRCLForInsert(InsertNode target,
int[] colMap)
Generate an RCL that can replace the original RCL of this node to match the RCL of the target for the insert. |
JBitSet |
getReferencedTableMap()
Get the referencedTableMap for this ResultSetNode |
ResultColumnList |
getResultColumns()
Get the resultColumns for this ResultSetNode |
int |
getResultSetNumber()
Get the resultSetNumber in this ResultSetNode. |
boolean |
isNotExists()
Return whether or not the underlying ResultSet tree is for a NOT EXISTS join. |
boolean |
isOneRowResultSet()
Return whether or not the underlying ResultSet tree will return a single row, at most. |
(package private) boolean |
isOrderedOn(ColumnReference[] crs,
boolean permuteOrdering,
java.util.Vector fbtVector)
Return whether or not the underlying ResultSet tree is ordered on the specified columns. |
(package private) boolean |
isPossibleDistinctScan(java.util.Set distinctColumns)
Is it possible to do a distinct scan on this ResultSet tree. |
(package private) boolean |
isUpdatableCursor(DataDictionary dd)
Determine if this result set is updatable or not, for a cursor (i.e., is it a cursor-updatable select). |
JBitSet |
LOJgetReferencedTables(int numTables)
|
ResultDescription |
makeResultDescription()
Make a ResultDescription for use in a ResultSet. |
(package private) ResultColumnDescriptor[] |
makeResultDescriptors()
|
boolean |
markAsCursorTargetTable()
Mark this ResultSetNode as the target table of an updatable cursor. |
(package private) void |
markForDistinctScan()
Mark the underlying scan as a distinct scan. |
void |
markStatementResultSet()
This method is overridden to allow a resultset node to know if it is the one controlling the statement -- i.e., it is the outermost result set node for the statement. |
ResultSetNode |
modifyAccessPaths()
Modify the access paths according to the decisions the optimizer made. |
ResultSetNode |
modifyAccessPaths(PredicateList predList)
Modify the access paths according to the decisions the optimizer made. |
(package private) void |
notCursorTargetTable()
Mark this ResultSetNode as *not* the target table of an updatable cursor. |
(package private) void |
notFlattenableJoin()
Mark this node and its children as not being a flattenable join. |
protected static int |
numDistinctAggregates(java.util.Vector aggregateVector)
Count the number of distinct aggregates in the list. |
ResultSetNode |
optimize(DataDictionary dataDictionary,
PredicateList predicates,
double outerRows)
Optimize a ResultSetNode. |
ValueNode |
parseDefault(java.lang.String defaultText)
Parse a default and turn it into a query tree. |
boolean |
performMaterialization(JBitSet outerTables)
Return whether or not to materialize this ResultSet tree. |
ResultSetNode |
preprocess(int numTables,
GroupByList gbl,
FromList fromList)
Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode. |
void |
printSubNodes(int depth)
Prints the sub-nodes of this object. |
(package private) void |
projectResultColumns()
Find the unreferenced result columns and project them out. |
(package private) void |
pushOffsetFetchFirst(ValueNode offset,
ValueNode fetchFirst)
Push down the offset and fetch first parameters, if any. |
(package private) void |
pushOrderByList(OrderByList orderByList)
Push the order by list down from the cursor node into its child result set so that the optimizer has all of the information that it needs to consider sort avoidance. |
boolean |
referencesTarget(java.lang.String name,
boolean baseTable)
Search to see if a query references the specifed table name. |
void |
rejectParameters()
Check for (and reject) ? |
void |
rejectXMLValues()
Check for (and reject) XML values directly under the ResultColumns. |
void |
renameGeneratedResultNames()
Rename generated result column names as '1', '2' etc... |
(package private) void |
replaceOrForbidDefaults(TableDescriptor ttd,
ResultColumnList tcl,
boolean allowDefaults)
Replace any DEFAULTs with the associated tree for the default if allowed, or flag (when inside top level set operator nodes). |
(package private) boolean |
returnsAtMostOneRow()
Return whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics. |
void |
setInsertSource()
Remember that this node is the source result set for an INSERT. |
void |
setReferencedTableMap(JBitSet newRTM)
Set the referencedTableMap in this ResultSetNode |
void |
setResultColumns(ResultColumnList newRCL)
Set the resultColumns in this ResultSetNode |
ResultSetNode |
setResultToBooleanTrueNode(boolean onlyConvertAlls)
Set the result column for the subquery to a boolean true, Useful for transformations such as changing: where exists (select ... from ...) |
(package private) void |
setTableConstructorTypes(ResultColumnList typeColumns)
Set the type of each parameter in the result column list for this table constructor. |
(package private) boolean |
subqueryReferencesTarget(java.lang.String name,
boolean baseTable)
Return whether or not this ResultSetNode contains a subquery with a reference to the specified target. |
java.lang.String |
toString()
Convert this object to a String. |
int |
updateTargetLockMode()
Get the lock mode for the target of an update statement (a delete or update). |
void |
verifySelectStarSubquery(FromList outerFromList,
int subqueryType)
Verify that a SELECT * is valid for this type of subquery. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
int resultSetNumber
JBitSet referencedTableMap
ResultColumnList resultColumns
boolean statementResultSet
boolean cursorTargetTable
boolean insertSource
CostEstimate costEstimate
CostEstimate scratchCostEstimate
Optimizer optimizer
CostEstimate finalCostEstimate
Constructor Detail |
---|
public ResultSetNode()
Method Detail |
---|
public java.lang.String toString()
toString
in class QueryTreeNode
public void printSubNodes(int depth)
printSubNodes
in class QueryTreeNode
depth
- The depth of this node in the treepublic int getResultSetNumber()
public CostEstimate getCostEstimate()
public CostEstimate getFinalCostEstimate() throws StandardException
StandardException
public void assignResultSetNumber() throws StandardException
StandardException
- Thrown on errorpublic ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) throws StandardException
dataDictionary
- The DataDictionary to use for bindingfromListParam
- FromList to use/append to.
StandardException
- Thrown on errorpublic ResultSetNode bindVTITables(FromList fromListParam) throws StandardException
fromListParam
- FromList to use/append to.
StandardException
- Thrown on errorpublic void bindExpressions(FromList fromListParam) throws StandardException
fromListParam
- FromList to use/append to.
StandardException
- Thrown on errorpublic void bindExpressionsWithTables(FromList fromListParam) throws StandardException
fromListParam
- FromList to use/append to.
StandardException
- Thrown on errorpublic void bindTargetExpressions(FromList fromListParam) throws StandardException
StandardException
- Thrown on errorvoid setTableConstructorTypes(ResultColumnList typeColumns) throws StandardException
typeColumns
- The ResultColumnList containing the desired result
types.
StandardException
- Thrown on errorpublic void setInsertSource()
public void verifySelectStarSubquery(FromList outerFromList, int subqueryType) throws StandardException
outerFromList
- The FromList from the outer query block(s)subqueryType
- The subquery type
StandardException
- Thrown on errorpublic ResultColumnList getAllResultColumns(TableName allTableName) throws StandardException
allTableName
- The qualifier on the "*"
null
if
allTableName
is non-null and doesn't match a table name in
this result set
StandardException
- Thrown on errorpublic ResultColumn getMatchingColumn(ColumnReference columnReference) throws StandardException
columnReference
- The columnReference whose name we're looking
for in the given table.
StandardException
- Thrown on errorpublic ResultSetNode setResultToBooleanTrueNode(boolean onlyConvertAlls) throws StandardException
onlyConvertAlls
- Boolean, whether or not to just convert *'s
StandardException
- Thrown on errorpublic FromList getFromList() throws StandardException
StandardException
- Thrown on errorpublic void disablePrivilegeCollection()
QueryTreeNode
disablePrivilegeCollection
in class QueryTreeNode
QueryTreeNode.disablePrivilegeCollection()
public void bindResultColumns(FromList fromListParam) throws StandardException
fromListParam
- FromList to use/append to.
StandardException
- Thrown on errorpublic void bindResultColumns(TableDescriptor targetTableDescriptor, FromVTI targetVTI, ResultColumnList targetColumnList, DMLStatementNode statement, FromList fromListParam) throws StandardException
targetTableDescriptor
- The TableDescriptor for the table being
updated or inserted intotargetColumnList
- For INSERT statements, the user
does not have to supply column
names (for example, "insert into t
values (1,2,3)". When this
parameter is null, it means that
the user did not supply column
names, and so the binding should
be done based on order. When it
is not null, it means do the binding
by name, not position.statement
- Calling DMLStatementNode (Insert or Update)fromListParam
- FromList to use/append to.
StandardException
- Thrown on errorpublic void bindUntypedNullsToResultColumns(ResultColumnList rcl) throws StandardException
rcl
- The ResultColumnList with the types to bind nulls to
StandardException
- Thrown on errorpublic ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException
numTables
- The number of tables in the DML Statementgbl
- The group by list, if anyfromList
- The from list, if any
StandardException
- Thrown on errorvoid projectResultColumns() throws StandardException
StandardException
public ResultSetNode ensurePredicateList(int numTables) throws StandardException
numTables
- The number of tables in the query.
StandardException
- Thrown on errorpublic ResultSetNode addNewPredicate(Predicate predicate) throws StandardException
predicate
- The predicate to add
StandardException
- Thrown on errorpublic boolean flattenableInFromSubquery(FromList fromList)
fromList
- The outer from list
ResultSetNode genProjectRestrictForReordering() throws StandardException
StandardException
- Thrown on errorpublic ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicates, double outerRows) throws StandardException
dataDictionary
- The DataDictionary to use for optimizationpredicates
- The PredicateList to apply.outerRows
- The number of outer joining rows
StandardException
- Thrown on errorpublic ResultSetNode modifyAccessPaths() throws StandardException
StandardException
- Thrown on errorpublic ResultSetNode modifyAccessPaths(PredicateList predList) throws StandardException
predList
- A list of optimizable predicates that should
be pushed to this ResultSetNode, as determined by optimizer.
StandardException
- Thrown on errorResultColumnDescriptor[] makeResultDescriptors()
boolean columnTypesAndLengthsMatch() throws StandardException
StandardException
public void setResultColumns(ResultColumnList newRCL)
newRCL
- The new ResultColumnList for this ResultSetNodepublic ResultColumnList getResultColumns()
public void setReferencedTableMap(JBitSet newRTM)
newRTM
- The new referencedTableMap for this ResultSetNodepublic JBitSet getReferencedTableMap()
public void fillInReferencedTableMap(JBitSet passedMap)
passedMap
- The table map to fill in.public void rejectParameters() throws StandardException
StandardException
- Thrown if a ? parameter found
directly under a ResultColumnpublic void rejectXMLValues() throws StandardException
StandardException
- Thrown if an XML value found
directly under a ResultColumnpublic void renameGeneratedResultNames() throws StandardException
StandardException
public void markStatementResultSet()
ResultSetNode enhanceRCLForInsert(InsertNode target, boolean inOrder, int[] colMap) throws StandardException
target
- the target node for the insertinOrder
- are source cols in same order as target cols?colMap
- int array representation of correspondence between
RCLs - colmap[i] = -1 -> missing in current RCL
colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
StandardException
- Thrown on errorResultColumnList getRCLForInsert(InsertNode target, int[] colMap) throws StandardException
target
- the target node for the insertcolMap
- int array representation of correspondence between
RCLs - colmap[i] = -1 -> missing in current RCL
colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
StandardException
private ResultColumn genNewRCForInsert(TableDescriptor targetTD, FromVTI targetVTI, int columnNumber, DataDictionary dataDictionary) throws StandardException
targetTD
- Target TableDescriptor if the target is not a VTI, null if a VTI.targetVTI
- Target description if it is a VTI, null if not a VTIcolumnNumber
- The column numberdataDictionary
- The DataDictionary
StandardException
- Thrown on errorprivate ResultSetNode generateProjectRestrictForInsert(InsertNode target, int[] colMap) throws StandardException
target
- the target node for the insertcolMap
- int array representation of correspondence between
RCLs - colmap[i] = -1 -> missing in current RCL
colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
StandardException
private ResultColumn createGeneratedColumn(TableDescriptor targetTD, ColumnDescriptor colDesc) throws StandardException
StandardException
public ValueNode parseDefault(java.lang.String defaultText) throws StandardException
defaultText
- Text of Default.
StandardException
- Thrown on failurepublic ResultDescription makeResultDescription()
boolean isUpdatableCursor(DataDictionary dd) throws StandardException
StandardException
- Thrown on errorFromTable getCursorTargetTable()
public boolean markAsCursorTargetTable()
void notCursorTargetTable()
public ResultSetNode genProjectRestrict() throws StandardException
StandardException
- Thrown on errorprotected ResultSetNode genProjectRestrict(int numTables) throws StandardException
numTables
- Number of tables in the DML Statement
StandardException
- Thrown on errorpublic void generateNormalizationResultSet(ActivationClassBuilder acb, MethodBuilder mb, int resultSetNumber, ResultDescription resultDescription) throws StandardException
acb
- The ActivationClassBuildermb
- The method to put the generated code inresultSetNumber
- The result set number for the NRSresultDescription
- The ERD for the ResultSet
StandardException
- Thrown on errorpublic ResultSetNode changeAccessPath() throws StandardException
StandardException
- Thrown on errorpublic boolean referencesTarget(java.lang.String name, boolean baseTable) throws StandardException
name
- Table name (String) to search for.baseTable
- Whether or not name is for a base table
StandardException
- Thrown on errorboolean subqueryReferencesTarget(java.lang.String name, boolean baseTable) throws StandardException
name
- The table name.
StandardException
- Thrown on errorpublic boolean isOneRowResultSet() throws StandardException
StandardException
- Thrown on errorpublic boolean isNotExists()
protected Optimizer getOptimizer(OptimizableList optList, OptimizablePredicateList predList, DataDictionary dataDictionary, RequiredRowOrdering requiredRowOrdering) throws StandardException
StandardException
- Thrown on errorprotected OptimizerImpl getOptimizerImpl()
protected CostEstimate getNewCostEstimate() throws StandardException
StandardException
- Thrown on errorvoid acceptChildren(Visitor v) throws StandardException
acceptChildren
in class QueryTreeNode
v
- the visitor
StandardException
- on errorpublic ResultSetNode considerMaterialization(JBitSet outerTables) throws StandardException
StandardException
- Thrown on errorpublic boolean performMaterialization(JBitSet outerTables) throws StandardException
StandardException
- Thrown on errorprotected FromTable getFromTableByName(java.lang.String name, java.lang.String schemaName, boolean exactMatch) throws StandardException
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.
StandardException
- Thrown on errorabstract void decrementLevel(int decrement)
decrement
- The amount to decrement by.void pushOrderByList(OrderByList orderByList)
orderByList
- The order by listvoid pushOffsetFetchFirst(ValueNode offset, ValueNode fetchFirst)
offset
- the OFFSET, if anyfetchFirst
- the OFFSET FIRST, if anypublic void generateResultSet(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
acb
- The ExpressionClassBuilder for the class being builtmb
- The method the expression will go into
StandardException
- Thrown on errorpublic int updateTargetLockMode()
TransactionController
void notFlattenableJoin()
boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, java.util.Vector fbtVector) throws StandardException
crs
- The specified ColumnReference[]permuteOrdering
- Whether or not the order of the CRs in the array can be permutedfbtVector
- Vector that is to be filled with the FromBaseTable
StandardException
- Thrown on errorboolean returnsAtMostOneRow()
void replaceOrForbidDefaults(TableDescriptor ttd, ResultColumnList tcl, boolean allowDefaults) throws StandardException
ttd
- The TableDescriptor for the target table.tcl
- The RCL for the target table.allowDefaults
- true if allowed
StandardException
- Thrown on errorboolean isPossibleDistinctScan(java.util.Set distinctColumns)
distinctColumns
- the set of distinct columns
void markForDistinctScan()
void adjustForSortElimination()
void adjustForSortElimination(RequiredRowOrdering rowOrdering) throws StandardException
StandardException
protected static final int numDistinctAggregates(java.util.Vector aggregateVector)
public JBitSet LOJgetReferencedTables(int numTables) throws StandardException
StandardException
|
Built on Thu 2012-03-29 21:53:33+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |