org.apache.derby.impl.sql.compile
Class ResultColumnList

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.QueryTreeNodeVector
          extended by org.apache.derby.impl.sql.compile.ResultColumnList
All Implemented Interfaces:
Visitable

public class ResultColumnList
extends QueryTreeNodeVector

A ResultColumnList is the target list of a SELECT, INSERT, or UPDATE.

See Also:
ResultColumn

Nested Class Summary
 class ResultColumnList.ColumnMapping
           
 
Field Summary
protected  long conglomerateId
           
private  boolean countMismatchAllowed
           
protected  boolean forUpdate
           
protected  boolean indexRow
           
private  int initialListSize
           
(package private)  int orderBySelect
           
 
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
ResultColumnList()
           
 
Method Summary
 void addColumn(TableName tableName, java.lang.String columnName, DataTypeDescriptor dts)
          Add a column to the list given a tablename, columnname, and datatype.
 void addRCForRID()
          Add an RC to the end of the list for the RID from an index.
 void addResultColumn(ResultColumn resultColumn)
          Add a ResultColumn (at this point, ResultColumn or AllResultColumn) to the list
 void adjustVirtualColumnIds(int adjust)
          Walk the list and adjust the virtualColumnIds in the ResultColumns by the specified amount.
(package private)  boolean allExpressionsAreColumns(ResultSetNode sourceRS)
          Determine if all of the RC.expressions are columns in the source result set.
(package private)  int allTopCRsFromSameTable()
          Return whether or not all of the RCs in the list whose expressions are ColumnReferences are from the same table.
 void appendResultColumns(ResultColumnList resultColumns, boolean destructiveCopy)
          Append a given ResultColumnList to this one, resetting the virtual column ids in the appended portion.
 void bindExpressions(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind the expressions in this ResultColumnList.
 void bindResultColumnsByName(ResultColumnList fullRCL, FromVTI targetVTI, DMLStatementNode statement)
          Bind the result columns by their names.
 void bindResultColumnsByName(TableDescriptor targetTableDescriptor)
          Bind the result columns by their names.
 FormatableBitSet bindResultColumnsByName(TableDescriptor targetTableDescriptor, DMLStatementNode statement)
          Bind the result columns by their names.
 void bindResultColumnsByPosition(TableDescriptor targetTableDescriptor)
          Bind the result columns by ordinal position.
 void bindResultColumnsToExpressions()
          Bind the result columns to the expressions that live under them.
 void bindUntypedNullsToResultColumns(ResultColumnList bindingRCL)
          Bind any untyped null nodes to the types in the given ResultColumnList.
 ExecRow buildEmptyIndexRow(TableDescriptor td, ConglomerateDescriptor cd, StoreCostController scc, DataDictionary dd)
          Build an empty index row for the given conglomerate.
 ExecRow buildEmptyRow()
          Build an empty row with the size and shape of the ResultColumnList.
 void checkColumnUpdateability(java.lang.String[] ucl, java.lang.String cursorName)
          Verify that all of the columns in the SET clause of a positioned update appear in the cursor's FOR UPDATE OF list.
(package private)  void checkForInvalidDefaults()
          Walk the RCL and check for DEFAULTs.
(package private)  void checkStorableExpressions()
          Verify that all the result columns have expressions that are storable for them.
(package private)  void checkStorableExpressions(ResultColumnList toStore)
          Verify that all the result columns have expressions that are storable for them.
 void clearColumnReferences()
          Clear the column references from the RCL.
 void clearTableNames()
           
private  void collapseVirtualColumnIdGap(int gap)
          Adjust virtualColumnId values due to result column removal This method is called when a duplicate column has been detected and removed from the list.
(package private)  boolean columnTypesAndLengthsMatch()
          Check whether the column lengths and types of the result columns match the expressions under those columns.
(package private)  boolean columnTypesAndLengthsMatch(ResultColumnList otherRCL)
           
private  void commonCodeForUpdatableByCursor(java.util.Vector updateColumns, boolean dealingWithSelectResultColumnList)
          dealingWithSelectResultColumnList true means we are dealing with ResultColumnList for a select sql.
(package private)  ResultColumnList compactColumns(boolean positionedUpdate, boolean always)
          Create a new, compacted RCL based on the referenced RCs in this list.
 boolean containsAllResultColumn()
          Return whether or not this RCL contains an AllResultColumn.
 void copyColumnsToNewList(ResultColumnList targetList, FormatableBitSet copyList)
          Copy the RCs from this list to the supplied target list.
 ResultColumnList copyListAndObjects()
          Create a shallow copy of a ResultColumnList and its ResultColumns.
 void copyOrderBySelect(ResultColumnList src)
           
 void copyReferencedColumnsToNewList(ResultColumnList targetList)
          Copy the referenced RCs from this list to the supplied target list.
(package private)  void copyResultColumnNames(ResultColumnList nameList)
          Copy the result column names from the given ResultColumnList to this ResultColumnList.
 int countReferencedColumns()
          Count the number of RCs in the list that are referenced.
 void createListFromResultSetMetaData(java.sql.ResultSetMetaData rsmd, TableName tableName, java.lang.String javaClassName)
          Generate an RCL to match the contents of a ResultSetMetaData.
private  void decOrderBySelect()
           
 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.
 void doProjection()
          Project out any unreferenced ResultColumns from the list and reset the virtual column ids in the referenced ResultColumns.
 void expandAllsAndNameColumns(FromList fromList)
          Expand any *'s in the ResultColumnList.
 ResultColumnList expandToAll(TableDescriptor td, TableName tableName)
          Expand this ResultColumnList by adding all columns from the given table that are not in this list.
 void exportNames(java.lang.String[] columnNames)
          Export the result column names to the passed in String[].
 ResultColumn findParentResultColumn(ResultColumn childRC)
          Given a ResultColumn at the next deepest level in the tree, search this RCL for its parent ResultColumn.
 ResultColumn findResultColumnForOrderBy(java.lang.String columnName, TableName tableName)
          For order by, get a ResultColumn that matches the specified columnName.
 void forbidOverrides(ResultColumnList sourceRSRCL)
          check if any autoincrement or generated columns exist in the result column list.
private  void genCreateRow(ExpressionClassBuilder acb, LocalField field, java.lang.String rowAllocatorMethod, java.lang.String rowAllocatorType, int numCols)
          Generate the code to create an empty row in the constructor.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Generate the code to place the columns' values into a row variable named "r".
(package private)  void generateCore(ExpressionClassBuilder acb, MethodBuilder mb, boolean genNulls)
          Generate the code to place the columns' values into a row variable named "r".
(package private)  void generateHolder(ExpressionClassBuilder acb, MethodBuilder mb)
          Generates a row with the size and shape of the ResultColumnList.
(package private)  void generateHolder(ExpressionClassBuilder acb, MethodBuilder mb, FormatableBitSet referencedCols, FormatableBitSet propagatedCols)
          Generates a row with the size and shape of the ResultColumnList.
(package private)  MethodBuilder generateHolderMethod(ExpressionClassBuilder acb, FormatableBitSet referencedCols, FormatableBitSet propagatedCols)
           
(package private)  void generateNulls(ActivationClassBuilder acb, MethodBuilder mb)
          Generate the code to place the columns' values into a row variable named "r".
 void genVirtualColumnNodes(ResultSetNode sourceResultSet, ResultColumnList sourceResultColumnList)
          Walk the list and replace ResultColumn.expression with a new VirtualColumnNode.
 void genVirtualColumnNodes(ResultSetNode sourceResultSet, ResultColumnList sourceResultColumnList, boolean markReferenced)
          Walk the list and replace ResultColumn.expression with a new VirtualColumnNode.
 ResultColumn getAtMostOneResultColumn(ColumnReference cr, java.lang.String exposedTableName, boolean considerGeneratedColumns)
          Get a ResultColumn that matches the specified columnName and mark the ResultColumn as being referenced.
 java.lang.String[] getColumnNames()
          Get an array of strings for all the columns in this RCL.
 int[] getColumnPositions(TableDescriptor td)
          Get an array of column positions (1-based) for all the columns in this RCL.
 FormatableBitSet getColumnReferenceMap()
          Get a FormatableBitSet of the columns referenced in this rcl
protected  boolean getCountMismatchAllowed()
          Return whether or not a count mismatch is allowed between this RCL, as a derived column list, and an underlying RCL.
(package private)  ResultColumnList getJoinColumns(ResultColumnList joinColumns)
          Get the join columns from this list.
 ResultColumn getOrderByColumn(int position)
          Get a ResultColumn from a column position (1-based) in the list, null if out of range (for order by).
 ResultColumn getOrderByColumnToBind(java.lang.String columnName, TableName tableName, int tableNumber, OrderByColumn obc)
          For order by column bind, get a ResultColumn that matches the specified columnName.
 int getOrderBySelect()
           
 int getPosition(java.lang.String name, int basis)
          Get the position of first result column with the given name.
(package private)  FormatableBitSet getReferencedFormatableBitSet(boolean positionedUpdate, boolean always, boolean onlyBCNs)
          Generate a FormatableBitSet representing the columns that are referenced in this RCL.
 ResultColumn getResultColumn(int position)
          Get a ResultColumn from a column position (1-based) in the list
 ResultColumn getResultColumn(int tableNumber, int columnNumber, java.lang.String columnName)
          Return a result column, if any found, which contains in its expression/{VCN,CR} chain a result column with the given columnNumber from a FromTable with the given tableNumber.
 ResultColumn getResultColumn(int colNum, ResultSetNode rsn, int[] whichRC)
          Take a column position and a ResultSetNode and find the ResultColumn in this RCL whose source result set is the same as the received RSN and whose column position is the same as the received column position.
 ResultColumn getResultColumn(java.lang.String columnName)
          Get a ResultColumn that matches the specified columnName and mark the ResultColumn as being referenced.
 ResultColumn getResultColumn(java.lang.String columnName, boolean markIfReferenced)
          Get a ResultColumn that matches the specified columnName.
 ResultColumn getResultColumn(java.lang.String columnsTableName, java.lang.String columnName)
          Get a ResultColumn that matches the specified columnName and mark the ResultColumn as being referenced.
(package private)  ResultColumn[] getSortedByPosition()
          Return an array that contains references to the columns in this list sorted by position.
 int[] getStreamStorableColIds(int heapColCount)
          Return an array holding the 0 based heap offsets of the StreamStorable columns in this ResultColumnList.
 int getTotalColumnSize()
          Get the size of all the columns added together.
 boolean hasConsistentTypeInfo()
          Verify that all ResultColumns and their expressions have type information and that the type information between the respective RCs and expressions matches.
 void incOrderBySelect()
           
 boolean isCloneable()
          Return whether or not this RCL can be flattened out of a tree.
 boolean isExactTypeAndLengthMatch(ResultColumnList otherRCL)
          Do the 2 RCLs have the same type & length.
private  ResultColumn makeColumnFromName(java.lang.String columnName)
           
private  ResultColumn makeColumnReferenceFromName(TableName tableName, java.lang.String columnName)
           
 ResultColumnDescriptor[] makeResultDescriptors()
          Make a ResultDescription for use in a ResultSet.
(package private)  ResultColumnList.ColumnMapping mapSourceColumns()
          Map the source columns to these columns.
 void markAllUnreferenced()
          Walk the list and mark all RCs as unreferenced.
(package private)  void markColumnsInSelectListUpdatableByCursor(java.util.Vector updateColumns)
          Mark all the columns in the select sql that this result column list represents as updatable if they match the columns in the given update column list.
protected  void markInitialSize()
           
(package private)  void markUpdatableByCursor()
          Mark all the (base) columns in this list as updatable by a positioned update statement.
(package private)  void markUpdatableByCursor(java.util.Vector updateColumns)
          Mark as updatable all the columns in this result column list that match the columns in the given update column list
(package private)  void markUpdated()
          Mark all the columns in this list as updated by an update statement.
(package private)  void markUpdated(ResultColumnList updateColumns)
          Mark as updatable all the columns in this result column list that match the columns in the given update column list.
 void nameAllResultColumns()
          Generate (unique across the entire statement) column names for those ResultColumns in this list which are not named.
 boolean nopProjection(ResultColumnList childRCL)
          Determine whether this RCL is a No-Op projection of the given RCL.
private  int numGeneratedColumns()
           
(package private)  int numGeneratedColumnsForGroupBy()
           
 void populate(TableDescriptor table, int[] columnIDs)
          Build this ResultColumnList from a table description and an array of column IDs.
 void preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList)
          Preprocess the expression trees under the RCL.
 void propagateDCLInfo(ResultColumnList derivedRCL, java.lang.String tableName)
          Validate the derived column list (DCL) and propagate the info from the list to the final ResultColumnList.
(package private)  void pullVirtualIsReferenced()
          Or in any isReferenced booleans from the virtual column chain.
 void recordColumnReferences(boolean[] colArray1, JBitSet[] tableColMap, int tableNumber)
          Record the top level ColumnReferences in the specified array and table map This is useful when checking for uniqueness conditions.
 void recordColumnReferences(int[] idArray, int basis)
          Record the column ids of the referenced columns in the specified array.
(package private)  void rejectParameters()
          Look for and reject ?
(package private)  void rejectXMLValues()
          Check for (and reject) XML values directly under the ResultColumns.
 void remapColumnReferencesToExpressions()
          Remap all ColumnReferences in this tree to be clones of the underlying expression.
(package private)  void removeGeneratedGroupingColumns()
          Remove any generated columns from this RCL.
(package private)  void removeJoinColumns(ResultColumnList joinColumns)
          Remove the columns which are join columns (in the joinColumns RCL) from this list.
 void removeOrderByColumns()
          Remove any columns that may have been added for an order by clause.
(package private)  void replaceOrForbidDefaults(TableDescriptor ttd, ResultColumnList tcl, boolean allowDefaults)
          Replace any DEFAULTs with the associated tree for the default if allowed, or flag.
(package private)  void resetVirtualColumnIds()
          Reset the virtual column ids for all of the underlying RCs.
(package private)  boolean reusableResult()
          Return whether or not the same result row can be used for all rows returned by the associated ResultSet.
protected  void setCountMismatchAllowed(boolean allowed)
          Set the value of whether or not a count mismatch is allowed between this RCL, as a derived column list, and an underlying RCL.
(package private)  void setIndexRow(long cid, boolean forUpdate)
           
 void setNullability(boolean nullability)
          Set the nullability of every ResultColumn in this list
 void setRedundant()
          Mark all of the ResultColumns as redundant.
 void setResultSetNumber(int resultSetNumber)
          Set the resultSetNumber in all of the ResultColumns.
 void setUnionResultExpression(ResultColumnList otherRCL, int tableNumber, int level, java.lang.String operatorName)
          Set up the result expressions for a UNION, INTERSECT, or EXCEPT: o Verify union type compatiblity o Get dominant type for result (type + max length + nullability) o Create a new ColumnReference with dominant type and name of from this RCL and make that the new expression.
 int[] sortMe()
          Return an array of all my column positions, sorted in ascending order.
private static boolean streamableType(ResultColumn rc)
           
 java.lang.String toString()
          Convert this object to a String.
(package private)  boolean updatableByCursor(int columnPosition)
          Returns true if the given column position is for a column that will be or could be updated by the positioned update of a cursor.
private static void updateArrays(int[] mapArray, boolean[] cloneMap, java.util.Map seenMap, ResultColumn rc, int index)
           
 boolean updateOverlaps(int[] columns)
          Does the column list contain any of the given column positions that are updated?
(package private)  void verifyAllOrderable()
          Verify that all of the RCs in this list are comparable.
 java.lang.String verifyCreateConstraintColumnList(TableElementList tel)
          Verify that all of the column names in this list are contained within the ColumnDefinitionNodes within the TableElementList.
 java.lang.String verifyUniqueNames(boolean errForGenCols)
          Check the uniqueness of the column names within a column list.
 int visibleSize()
           
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
acceptChildren, addElement, destructiveAppend, elementAt, indexOf, insertElementAt, nondestructiveAppend, printSubNodes, remove, removeAllElements, removeElement, removeElementAt, setElementAt, size
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

indexRow

protected boolean indexRow

conglomerateId

protected long conglomerateId

orderBySelect

int orderBySelect

forUpdate

protected boolean forUpdate

countMismatchAllowed

private boolean countMismatchAllowed

initialListSize

private int initialListSize
Constructor Detail

ResultColumnList

public ResultColumnList()
Method Detail

addResultColumn

public void addResultColumn(ResultColumn resultColumn)
Add a ResultColumn (at this point, ResultColumn or AllResultColumn) to the list

Parameters:
resultColumn - The ResultColumn to add to the list

appendResultColumns

public void appendResultColumns(ResultColumnList resultColumns,
                                boolean destructiveCopy)
Append a given ResultColumnList to this one, resetting the virtual column ids in the appended portion.

Parameters:
resultColumns - The ResultColumnList to be appended
destructiveCopy - Whether or not this is a descructive copy from resultColumns

getResultColumn

public ResultColumn getResultColumn(int position)
Get a ResultColumn from a column position (1-based) in the list

Parameters:
position - The ResultColumn to get from the list (1-based)
Returns:
the column at that position.

getResultColumn

public ResultColumn getResultColumn(int colNum,
                                    ResultSetNode rsn,
                                    int[] whichRC)
                             throws StandardException
Take a column position and a ResultSetNode and find the ResultColumn in this RCL whose source result set is the same as the received RSN and whose column position is the same as the received column position.

Parameters:
colNum - The column position (w.r.t rsn) for which we're searching
rsn - The result set node for which we're searching.
Returns:
The ResultColumn in this RCL whose source is column colNum in result set rsn. That ResultColumn's position w.r.t to this RCL is also returned via the whichRC parameter. If no match is found, return null and leave whichRC untouched.
Throws:
StandardException

getOrderByColumn

public ResultColumn getOrderByColumn(int position)
Get a ResultColumn from a column position (1-based) in the list, null if out of range (for order by).

Parameters:
position - The ResultColumn to get from the list (1-based)
Returns:
the column at that position, null if out of range

getResultColumn

public ResultColumn getResultColumn(java.lang.String columnName)
Get a ResultColumn that matches the specified columnName and mark the ResultColumn as being referenced.

Parameters:
columnName - The ResultColumn to get from the list
Returns:
the column that matches that name.

getResultColumn

public ResultColumn getResultColumn(java.lang.String columnName,
                                    boolean markIfReferenced)
Get a ResultColumn that matches the specified columnName. If requested to, mark the column as referenced.

Parameters:
columnName - The ResultColumn to get from the list
markIfReferenced - True if we should mark this column as referenced.
Returns:
the column that matches that name.

getResultColumn

public ResultColumn getResultColumn(int tableNumber,
                                    int columnNumber,
                                    java.lang.String columnName)
Return a result column, if any found, which contains in its expression/{VCN,CR} chain a result column with the given columnNumber from a FromTable with the given tableNumber.

Used by the optimizer preprocess phase when it is flattening queries, which has to use the pair {table number, column number} to uniquely distinguish the column desired in situations where the same table may appear multiple times in the queries with separate correlation names, and/or column names from different tables may be the same (hence looking up by column name will not always work), cf DERBY-4679.

columnName is used to assert that we find the right column. If we found a match on (tn, cn) but columnName is wrong, return null. Once we trust table numbers and column numbers to always be correct, cf. DERBY-4695, we could remove this parameter.

Parameters:
tableNumber - the table number to look for
columnNumber - the column number to look for
columnName - name of the desired column

getResultColumn

public ResultColumn getResultColumn(java.lang.String columnsTableName,
                                    java.lang.String columnName)
Get a ResultColumn that matches the specified columnName and mark the ResultColumn as being referenced.

Parameters:
columnsTableName - Qualifying name for the column
columnName - The ResultColumn to get from the list
Returns:
the column that matches that name.

getAtMostOneResultColumn

public ResultColumn getAtMostOneResultColumn(ColumnReference cr,
                                             java.lang.String exposedTableName,
                                             boolean considerGeneratedColumns)
                                      throws StandardException
Get a ResultColumn that matches the specified columnName and mark the ResultColumn as being referenced. NOTE - this flavor enforces no ambiguity (at most 1 match) Only FromSubquery needs to call this flavor since it can have ambiguous references in its own list.

Parameters:
cr - The ColumnReference to resolve
exposedTableName - Exposed table name for FromTable
considerGeneratedColumns - Also consider columns that are generated. One example of this is group by where columns are added to the select list if they are referenced in the group by but are not present in the select list.
Returns:
the column that matches that name.
Throws:
StandardException - Thrown on error

getOrderByColumnToBind

public ResultColumn getOrderByColumnToBind(java.lang.String columnName,
                                           TableName tableName,
                                           int tableNumber,
                                           OrderByColumn obc)
                                    throws StandardException
For order by column bind, get a ResultColumn that matches the specified columnName. This method is called during bind processing, in the special "bind the order by" call that is made by CursorNode.bindStatement(). The OrderByList has a special set of bind processing routines that analyzes the columns in the ORDER BY list and verifies that each column is one of: - a direct reference to a column explicitly mentioned in the SELECT list - a direct reference to a column implicitly mentioned as "SELECT *" - a direct reference to a column "pulled up" into the result column list - or a valid and fully-bound expression ("c+2", "YEAR(hire_date)", etc.) At this point in the processing, it is possible that we'll find the column present in the RCL twice: once because it was pulled up during statement compilation, and once because it was added when "SELECT *" was expanded into the table's actual column list. If we find such a duplicated column, we can, and do, remove the pulled-up copy of the column and point the OrderByColumn to the actual ResultColumn from the *-expansion. Note that the association of the OrderByColumn with the corresponding ResultColumn in the RCL occurs in OrderByColumn.resolveAddedColumn.

Parameters:
columnName - The ResultColumn to get from the list
tableName - The table name on the OrderByColumn, if any
tableNumber - The tableNumber corresponding to the FromTable with the exposed name of tableName, if tableName != null.
obc - The OrderByColumn we're binding.
Returns:
the column that matches that name.
Throws:
StandardException - thrown on ambiguity

collapseVirtualColumnIdGap

private void collapseVirtualColumnIdGap(int gap)
Adjust virtualColumnId values due to result column removal This method is called when a duplicate column has been detected and removed from the list. We iterate through each of the other columns in the list and notify them of the column removal so they can adjust their virtual column id if necessary.

Parameters:
gap - id of the column which was just removed.

findResultColumnForOrderBy

public ResultColumn findResultColumnForOrderBy(java.lang.String columnName,
                                               TableName tableName)
                                        throws StandardException
For order by, get a ResultColumn that matches the specified columnName. This method is called during pull-up processing, at the very start of bind processing, as part of OrderByList.pullUpOrderByColumns. Its job is to figure out whether the provided column (from the ORDER BY list) already exists in the ResultColumnList or not. If the column does not exist in the RCL, we return NULL, which signifies that a new ResultColumn should be generated and added ("pulled up") to the RCL by our caller. Note that at this point in the processing, we should never find this column present in the RCL multiple times; if the column is already present in the RCL, then we don't need to, and won't, pull a new ResultColumn up into the RCL. If the caller specified "SELECT *", then the RCL at this point contains a special AllResultColumn object. This object will later be expanded and replaced by the actual set of columns in the table, but at this point we don't know what those columns are, so we may pull up an OrderByColumn which duplicates a column in the *-expansion; such duplicates will be removed at the end of bind processing by OrderByList.bindOrderByColumns.

Parameters:
columnName - The ResultColumn to get from the list
tableName - The table name on the OrderByColumn, if any
Returns:
the column that matches that name, or NULL if pull-up needed
Throws:
StandardException - thrown on ambiguity

copyResultColumnNames

void copyResultColumnNames(ResultColumnList nameList)
Copy the result column names from the given ResultColumnList to this ResultColumnList. This is useful for insert-select, where the columns being inserted into may be different from the columns being selected from. The result column list for an insert is supposed to have the column names being inserted into.

Parameters:
nameList - The ResultColumnList from which to copy the column names

bindExpressions

public void bindExpressions(FromList fromList,
                            SubqueryList subqueryList,
                            java.util.Vector aggregateVector)
                     throws StandardException
Bind the expressions in this ResultColumnList. This means binding the expression under each ResultColumn node.

Parameters:
fromList - The FROM list for the query this expression is in, for binding columns.
subqueryList - The subquery list being built as we find SubqueryNodes
aggregateVector - The aggregate vector being built as we find AggregateNodes
Throws:
StandardException - Thrown on error

bindResultColumnsToExpressions

public void bindResultColumnsToExpressions()
                                    throws StandardException
Bind the result columns to the expressions that live under them. All this does is copy the datatype information to from each expression to each result column. This is useful for SELECT statements, where the result type of each column is the type of the column's expression.

Throws:
StandardException - Thrown on error

bindResultColumnsByName

public void bindResultColumnsByName(TableDescriptor targetTableDescriptor)
                             throws StandardException
Bind the result columns by their names. This is useful for GRANT and REVOKE statements like "GRANT SELECT ON t(c1,c1,c3) TO george", where the user specified a column list. This method does not check for duplicate column names.

Parameters:
targetTableDescriptor - The descriptor for the table
Throws:
StandardException - Thrown on error

bindResultColumnsByName

public FormatableBitSet bindResultColumnsByName(TableDescriptor targetTableDescriptor,
                                                DMLStatementNode statement)
                                         throws StandardException
Bind the result columns by their names. This is useful for update, grant, and revoke statements, and for INSERT statements like "insert into t (a, b, c) values (1, 2, 3)" where the user specified a column list. If the statment is an insert or update verify that the result column list does not contain any duplicates. NOTE: We pass the ResultColumns position in the ResultColumnList so that the VirtualColumnId gets set.

Parameters:
targetTableDescriptor - The descriptor for the table being updated or inserted into
statement - DMLStatementNode containing this list, null if no duplicate checking is to be done
Returns:
A FormatableBitSet representing the set of columns with respect to the table
Throws:
StandardException - Thrown on error

bindResultColumnsByName

public void bindResultColumnsByName(ResultColumnList fullRCL,
                                    FromVTI targetVTI,
                                    DMLStatementNode statement)
                             throws StandardException
Bind the result columns by their names. This is useful for update VTI statements, and for INSERT statements like "insert into new t() (a, b, c) values (1, 2, 3)" where the user specified a column list. Also, verify that the result column list does not contain any duplicates. NOTE: We pass the ResultColumns position in the ResultColumnList so that the VirtualColumnId gets set.

Parameters:
fullRCL - The full RCL for the target table
statement - DMLStatementNode containing this list
Throws:
StandardException - Thrown on error

bindResultColumnsByPosition

public void bindResultColumnsByPosition(TableDescriptor targetTableDescriptor)
                                 throws StandardException
Bind the result columns by ordinal position. This is useful for INSERT statements like "insert into t values (1, 2, 3)", where the user did not specify a column list.

Parameters:
targetTableDescriptor - The descriptor for the table being inserted into
Throws:
StandardException - Thrown on error

preprocess

public void preprocess(int numTables,
                       FromList outerFromList,
                       SubqueryList outerSubqueryList,
                       PredicateList outerPredicateList)
                throws StandardException
Preprocess the expression trees under the RCL. 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
outerFromList - FromList from outer query block
outerSubqueryList - SubqueryList from outer query block
outerPredicateList - PredicateList from outer query block
Throws:
StandardException - Thrown on error

checkStorableExpressions

void checkStorableExpressions(ResultColumnList toStore)
                        throws StandardException
Verify that all the result columns have expressions that are storable for them. Check versus the given ResultColumnList.

Throws:
StandardException - Thrown on error

getStreamStorableColIds

public int[] getStreamStorableColIds(int heapColCount)
                              throws StandardException
Return an array holding the 0 based heap offsets of the StreamStorable columns in this ResultColumnList. This returns null if this list does not contain any StreamStorableColumns. The list this returns does not contain duplicates. This should only be used for a resultColumnList the refers to a single heap such as the target for an Insert, Update or Delete.

Parameters:
heapColCount - the number of heap columns
Throws:
StandardException - Thrown on error

checkStorableExpressions

void checkStorableExpressions()
                        throws StandardException
Verify that all the result columns have expressions that are storable for them. Check versus the expressions under the ResultColumns.

Throws:
StandardException - Thrown on error

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Generate the code to place the columns' values into a row variable named "r". This wrapper is here rather than in ResultColumn, because that class does not know about the position of the columns in the list.

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method for the generated code to go into
Throws:
StandardException - Thrown on error

generateNulls

void generateNulls(ActivationClassBuilder acb,
                   MethodBuilder mb)
             throws StandardException
Generate the code to place the columns' values into a row variable named "r". This wrapper is here rather than in ResultColumn, because that class does not know about the position of the columns in the list.

Throws:
StandardException - Thrown on error

generateCore

void generateCore(ExpressionClassBuilder acb,
                  MethodBuilder mb,
                  boolean genNulls)
            throws StandardException
Generate the code to place the columns' values into a row variable named "r". This wrapper is here rather than in ResultColumn, because that class does not know about the position of the columns in the list. This is the method that does the work.

Throws:
StandardException

buildEmptyRow

public ExecRow buildEmptyRow()
                      throws StandardException
Build an empty row with the size and shape of the ResultColumnList.

Returns:
an empty row of the correct size and shape.
Throws:
StandardException - Thrown on error

buildEmptyIndexRow

public ExecRow buildEmptyIndexRow(TableDescriptor td,
                                  ConglomerateDescriptor cd,
                                  StoreCostController scc,
                                  DataDictionary dd)
                           throws StandardException
Build an empty index row for the given conglomerate.

Returns:
an empty row of the correct size and shape.
Throws:
StandardException - Thrown on error

generateHolder

void generateHolder(ExpressionClassBuilder acb,
                    MethodBuilder mb)
              throws StandardException
Generates a row with the size and shape of the ResultColumnList. Some structures, like FromBaseTable and DistinctNode, need to generate rowAllocator functions to get a row the size and shape of their ResultColumnList. We return the method pointer, which is a field access in the generated class.

Throws:
StandardException

generateHolder

void generateHolder(ExpressionClassBuilder acb,
                    MethodBuilder mb,
                    FormatableBitSet referencedCols,
                    FormatableBitSet propagatedCols)
              throws StandardException
Generates a row with the size and shape of the ResultColumnList. Some structures, like FromBaseTable and DistinctNode, need to generate rowAllocator functions to get a row the size and shape of their ResultColumnList. We return the method pointer, which is a field access in the generated class.

Throws:
StandardException

generateHolderMethod

MethodBuilder generateHolderMethod(ExpressionClassBuilder acb,
                                   FormatableBitSet referencedCols,
                                   FormatableBitSet propagatedCols)
                             throws StandardException
Throws:
StandardException

genCreateRow

private void genCreateRow(ExpressionClassBuilder acb,
                          LocalField field,
                          java.lang.String rowAllocatorMethod,
                          java.lang.String rowAllocatorType,
                          int numCols)
                   throws StandardException
Generate the code to create an empty row in the constructor.

Parameters:
acb - The ACB.
field - The field for the new row.
rowAllocatorMethod - The method to call.
rowAllocatorType - The row type.
numCols - The number of columns in the row.
Throws:
StandardException - Thrown on error

makeResultDescriptors

public ResultColumnDescriptor[] makeResultDescriptors()
Make a ResultDescription for use in a ResultSet. This is useful when generating/executing a NormalizeResultSet, since it can appear anywhere in the tree.

Returns:
A ResultDescription for this ResultSetNode.

expandAllsAndNameColumns

public void expandAllsAndNameColumns(FromList fromList)
                              throws StandardException
Expand any *'s in the ResultColumnList. In addition, we will guarantee that each ResultColumn has a name. (All generated names will be unique across the entire statement.)

Throws:
StandardException - Thrown on error

nameAllResultColumns

public void nameAllResultColumns()
                          throws StandardException
Generate (unique across the entire statement) column names for those ResultColumns in this list which are not named.

Throws:
StandardException - Thrown on error

columnTypesAndLengthsMatch

boolean columnTypesAndLengthsMatch()
                             throws StandardException
Check whether the column lengths and types of the result columns match the expressions under those columns. This is useful for INSERT and UPDATE statements. For SELECT statements this method should always return true. There is no need to call this for a DELETE statement. NOTE: We skip over generated columns since they won't have a column descriptor.

Returns:
true means all the columns match their expressions, false means at least one column does not match its expression
Throws:
StandardException

columnTypesAndLengthsMatch

boolean columnTypesAndLengthsMatch(ResultColumnList otherRCL)
                             throws StandardException
Throws:
StandardException

nopProjection

public boolean nopProjection(ResultColumnList childRCL)
Determine whether this RCL is a No-Op projection of the given RCL. It only makes sense to do this if the given RCL is from the child result set of the ProjectRestrict that this RCL is from.

Parameters:
childRCL - The ResultColumnList of the child result set.
Returns:
true if this RCL is a No-Op projection of the given RCL.

copyListAndObjects

public ResultColumnList copyListAndObjects()
                                    throws StandardException
Create a shallow copy of a ResultColumnList and its ResultColumns. (All other pointers are preserved.) Useful for building new ResultSetNodes during preprocessing.

Returns:
None.
Throws:
StandardException - Thrown on error

removeOrderByColumns

public void removeOrderByColumns()
Remove any columns that may have been added for an order by clause. In a query like:
select a from t order by b
b is added to the select list However in the final projection, after the sort is complete, b will have to be removed.


genVirtualColumnNodes

public void genVirtualColumnNodes(ResultSetNode sourceResultSet,
                                  ResultColumnList sourceResultColumnList)
                           throws StandardException
Walk the list and replace ResultColumn.expression with a new VirtualColumnNode. This is useful when propagating a ResultColumnList up the query tree. NOTE: This flavor marks all of the underlying RCs as referenced.

Parameters:
sourceResultSet - ResultSetNode that is source of value
Throws:
StandardException - Thrown on error

genVirtualColumnNodes

public void genVirtualColumnNodes(ResultSetNode sourceResultSet,
                                  ResultColumnList sourceResultColumnList,
                                  boolean markReferenced)
                           throws StandardException
Walk the list and replace ResultColumn.expression with a new VirtualColumnNode. This is useful when propagating a ResultColumnList up the query tree.

Parameters:
sourceResultSet - ResultSetNode that is source of value
markReferenced - Whether or not to mark the underlying RCs as referenced
Throws:
StandardException - Thrown on error

adjustVirtualColumnIds

public void adjustVirtualColumnIds(int adjust)
Walk the list and adjust the virtualColumnIds in the ResultColumns by the specified amount. If ResultColumn.expression is a VirtualColumnNode, then we adjust the columnId there as well.

Parameters:
adjust - The size of the increment.

doProjection

public void doProjection()
                  throws StandardException
Project out any unreferenced ResultColumns from the list and reset the virtual column ids in the referenced ResultColumns. If all ResultColumns are projected out, then the list is not empty.

Throws:
StandardException - Thrown on error

verifyUniqueNames

public java.lang.String verifyUniqueNames(boolean errForGenCols)
                                   throws StandardException
Check the uniqueness of the column names within a column list.

Parameters:
errForGenCols - Raise an error for any generated column names.
Returns:
String The first duplicate column name, if any.
Throws:
StandardException

propagateDCLInfo

public void propagateDCLInfo(ResultColumnList derivedRCL,
                             java.lang.String tableName)
                      throws StandardException
Validate the derived column list (DCL) and propagate the info from the list to the final ResultColumnList.

Parameters:
derivedRCL - The derived column list
tableName - The table name for the FromTable
Throws:
StandardException - Thrown on error

rejectParameters

void rejectParameters()
                throws StandardException
Look for and reject ? parameters under ResultColumns. This is done for SELECT statements.

Throws:
StandardException - Thrown if a ? parameter found directly under a ResultColumn

rejectXMLValues

void rejectXMLValues()
               throws StandardException
Check for (and reject) XML values directly under the ResultColumns. This is done for SELECT/VALUES statements. We reject values in this case because JDBC does not define an XML type/binding and thus there's no standard way to pass such a type back to a JDBC application. Note that we DO allow an XML column in a top-level RCL IF that column was added to the RCL by _us_ instead of by the user. For example, if we have a table: create table t1 (i int, x xml) and the user query is: select i from t1 order by x the "x" column will be added (internally) to the RCL as part of ORDER BY processing--and so we need to allow that XML column to be bound without throwing an error. If, as in this case, the XML column reference is invalid (we can't use ORDER BY on an XML column because XML values aren't ordered), a more appropriate error message should be returned to the user in later processing. If we didn't allow for this, the user would get an error saying that XML columns are not valid as part of the result set--but as far as s/he knows, there isn't such a column: only "i" is supposed to be returned (the RC for "x" was added to the RCL by _us_ as part of ORDER BY processing). ASSUMPTION: Any RCs that are generated internally and added to this RCL (before this RCL is bound) are added at the _end_ of the list. If that's true, then any RC with an index greater than the size of the initial (user-specified) list must have been added internally and will not be returned to the user.

Throws:
StandardException - Thrown if an XML value found directly under a ResultColumn

setResultSetNumber

public void setResultSetNumber(int resultSetNumber)
Set the resultSetNumber in all of the ResultColumns.

Parameters:
resultSetNumber - The resultSetNumber

setRedundant

public void setRedundant()
Mark all of the ResultColumns as redundant. Useful when chopping a ResultSetNode out of a tree when there are still references to its RCL.


checkColumnUpdateability

public void checkColumnUpdateability(java.lang.String[] ucl,
                                     java.lang.String cursorName)
                              throws StandardException
Verify that all of the columns in the SET clause of a positioned update appear in the cursor's FOR UPDATE OF list.

Parameters:
ucl - The cursor's FOR UPDATE OF list. (May be null.)
cursorName - The cursor's name.
Throws:
StandardException - Thrown on error

setUnionResultExpression

public void setUnionResultExpression(ResultColumnList otherRCL,
                                     int tableNumber,
                                     int level,
                                     java.lang.String operatorName)
                              throws StandardException
Set up the result expressions for a UNION, INTERSECT, or EXCEPT: o Verify union type compatiblity o Get dominant type for result (type + max length + nullability) o Create a new ColumnReference with dominant type and name of from this RCL and make that the new expression. o Set the type info for in the ResultColumn to the dominant type NOTE - We are assuming that caller has generated a new RCL for the UNION with the same names as the left side's RCL and copies of the expressions.

Parameters:
otherRCL - RCL from other side of the UNION.
tableNumber - The tableNumber for the UNION.
level - The nesting level for the UNION.
operatorName - "UNION", "INTERSECT", or "EXCEPT"
Throws:
StandardException - Thrown on error

isExactTypeAndLengthMatch

public boolean isExactTypeAndLengthMatch(ResultColumnList otherRCL)
                                  throws StandardException
Do the 2 RCLs have the same type & length. This is useful for UNIONs when deciding whether a NormalizeResultSet is required.

Parameters:
otherRCL - The other RCL.
Returns:
boolean Whether or not there is an exact UNION type match on the 2 RCLs.
Throws:
StandardException

updateOverlaps

public boolean updateOverlaps(int[] columns)
Does the column list contain any of the given column positions that are updated? Implements same named routine in UpdateList.

Parameters:
columns - An array of column positions
Returns:
True if this column list contains any of the given columns

getSortedByPosition

ResultColumn[] getSortedByPosition()
Return an array that contains references to the columns in this list sorted by position.

Returns:
The sorted array.

sortMe

public int[] sortMe()
Return an array of all my column positions, sorted in ascending order.

Returns:
a sorted array

expandToAll

public ResultColumnList expandToAll(TableDescriptor td,
                                    TableName tableName)
                             throws StandardException
Expand this ResultColumnList by adding all columns from the given table that are not in this list. The result is sorted by column position.

Parameters:
td - The TableDescriptor for the table in question
tableName - The name of the table as given in the query
Returns:
A new ResultColumnList expanded to include all columns in the given table.
Throws:
StandardException - Thrown on error

bindUntypedNullsToResultColumns

public void bindUntypedNullsToResultColumns(ResultColumnList bindingRCL)
                                     throws StandardException
Bind any untyped null nodes to the types in the given ResultColumnList. Nodes that don't know their type may pass down nulls to children nodes. In the case of something like a union, it knows to try its right and left result sets against each other. But if a null reaches us, it means we have a null type that we don't know how to handle.

Parameters:
bindingRCL - The ResultColumnList with the types to bind to.
Throws:
StandardException - Thrown on error

markUpdated

void markUpdated()
Mark all the columns in this list as updated by an update statement.


markUpdatableByCursor

void markUpdatableByCursor()
Mark all the (base) columns in this list as updatable by a positioned update statement. This is necessary for positioned update statements, because we expand the column list to include all the columns in the base table, and we need to be able to tell which ones the user is really trying to update so we can determine correctly whether all the updated columns are in the "for update" list.


disablePrivilegeCollection

public void disablePrivilegeCollection()
Description copied from class: QueryTreeNode
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. Based on this, any time a trigger/view/constraint is executing, we do not need to waste time in checking if the definer still has the right set of privileges. At compile time, we wil make sure that we do not collect the privilege requirement for objects accessed with definer privileges by calling the following method.

Overrides:
disablePrivilegeCollection in class QueryTreeNode
See Also:
QueryTreeNode.disablePrivilegeCollection()

verifyCreateConstraintColumnList

public java.lang.String verifyCreateConstraintColumnList(TableElementList tel)
Verify that all of the column names in this list are contained within the ColumnDefinitionNodes within the TableElementList.

Returns:
String The 1st column name, if any, that is not in the list.

exportNames

public void exportNames(java.lang.String[] columnNames)
Export the result column names to the passed in String[].

Parameters:
columnNames - String[] to hold the column names.

findParentResultColumn

public ResultColumn findParentResultColumn(ResultColumn childRC)
Given a ResultColumn at the next deepest level in the tree, search this RCL for its parent ResultColumn.

Parameters:
childRC - The child ResultColumn
Returns:
ResultColumn The parent ResultColumn

markUpdated

void markUpdated(ResultColumnList updateColumns)
Mark as updatable all the columns in this result column list that match the columns in the given update column list.

Parameters:
updateColumns - A ResultColumnList representing the columns to be updated.

markColumnsInSelectListUpdatableByCursor

void markColumnsInSelectListUpdatableByCursor(java.util.Vector updateColumns)
Mark all the columns in the select sql that this result column list represents as updatable if they match the columns in the given update column list.

Parameters:
updateColumns - A Vector representing the columns to be updated.

commonCodeForUpdatableByCursor

private void commonCodeForUpdatableByCursor(java.util.Vector updateColumns,
                                            boolean dealingWithSelectResultColumnList)
dealingWithSelectResultColumnList true means we are dealing with ResultColumnList for a select sql. When dealing with ResultColumnList for select sql, it is possible that not all the updatable columns are projected in the select column list and hence it is possible that we may not find the column to be updated in the ResultColumnList and that is why special handling is required when dealingWithSelectResultColumnList is true. eg select c11, c13 from t1 for update of c11, c12 In the eg above, we will find updatable column c11 in the select column list but we will not find updatable column c12 in the select column list


markUpdatableByCursor

void markUpdatableByCursor(java.util.Vector updateColumns)
Mark as updatable all the columns in this result column list that match the columns in the given update column list

Parameters:
updateColumns - A Vector representing the columns to be updated.

updatableByCursor

boolean updatableByCursor(int columnPosition)
Returns true if the given column position is for a column that will be or could be updated by the positioned update of a cursor.

Parameters:
columnPosition - The position of the column in question
Returns:
true if the column is updatable

isCloneable

public boolean isCloneable()
Return whether or not this RCL can be flattened out of a tree. It can only be flattened if the expressions are all cloneable.

Returns:
boolean Whether or not this RCL can be flattened out of a tree.

remapColumnReferencesToExpressions

public void remapColumnReferencesToExpressions()
                                        throws StandardException
Remap all ColumnReferences in this tree to be clones of the underlying expression.

Throws:
StandardException - Thrown on error

setIndexRow

void setIndexRow(long cid,
                 boolean forUpdate)

hasConsistentTypeInfo

public boolean hasConsistentTypeInfo()
                              throws StandardException
Verify that all ResultColumns and their expressions have type information and that the type information between the respective RCs and expressions matches.

Returns:
boolean Whether or not the type information is consistent
Throws:
StandardException

containsAllResultColumn

public boolean containsAllResultColumn()
Return whether or not this RCL contains an AllResultColumn. This is useful when dealing with SELECT * views which reference tables that may have had columns added to them via ALTER TABLE since the view was created.

Returns:
Whether or not this RCL contains an AllResultColumn.

countReferencedColumns

public int countReferencedColumns()
Count the number of RCs in the list that are referenced.

Returns:
The number of RCs in the list that are referenced.

recordColumnReferences

public void recordColumnReferences(int[] idArray,
                                   int basis)
Record the column ids of the referenced columns in the specified array.

Parameters:
idArray - int[] for column ids
basis - 0 (for 0-based ids) or 1 (for 1-based ids)

getPosition

public int getPosition(java.lang.String name,
                       int basis)
Get the position of first result column with the given name.

Parameters:
name - Name of the column
basis - 0 (for 0-based ids) or 1 (for 1-based ids)

recordColumnReferences

public void recordColumnReferences(boolean[] colArray1,
                                   JBitSet[] tableColMap,
                                   int tableNumber)
Record the top level ColumnReferences in the specified array and table map This is useful when checking for uniqueness conditions. NOTE: All top level CRs assumed to be from the same table. The size of the array is expected to be the # of columns in the table of interest + 1, so we use 1-base column #s.

Parameters:
colArray1 - boolean[] for columns
tableColMap - JBitSet[] for tables
tableNumber - Table number of column references

allTopCRsFromSameTable

int allTopCRsFromSameTable()
Return whether or not all of the RCs in the list whose expressions are ColumnReferences are from the same table. One place this is useful for distinct elimination based on the existence of a uniqueness condition.

Returns:
-1 if all of the top level CRs in the RCL are not ColumnReferences from the same table, else the tableNumber

clearColumnReferences

public void clearColumnReferences()
Clear the column references from the RCL. (Restore RCL back to a state where none of the RCs are marked as referenced.)


copyReferencedColumnsToNewList

public void copyReferencedColumnsToNewList(ResultColumnList targetList)
Copy the referenced RCs from this list to the supplied target list.

Parameters:
targetList - The list to copy to

copyColumnsToNewList

public void copyColumnsToNewList(ResultColumnList targetList,
                                 FormatableBitSet copyList)
Copy the RCs from this list to the supplied target list.

Parameters:
targetList - The list to copy to,
copyList - 1 based bitMap we copy columns associated with set bits.

getColumnReferenceMap

public FormatableBitSet getColumnReferenceMap()
Get a FormatableBitSet of the columns referenced in this rcl

Returns:
the FormatableBitSet

pullVirtualIsReferenced

void pullVirtualIsReferenced()
Or in any isReferenced booleans from the virtual column chain. That is the isReferenced bits on each ResultColumn on the list will be set if the ResultColumn is referenced or if any VirtualColumnNode in its expression chain refers to a referenced column.


clearTableNames

public void clearTableNames()

setCountMismatchAllowed

protected void setCountMismatchAllowed(boolean allowed)
Set the value of whether or not a count mismatch is allowed between this RCL, as a derived column list, and an underlying RCL. This is allowed for SELECT * views when an underlying table has had columns added to it via ALTER TABLE.

Parameters:
allowed - Whether or not a mismatch is allowed.

getCountMismatchAllowed

protected boolean getCountMismatchAllowed()
Return whether or not a count mismatch is allowed between this RCL, as a derived column list, and an underlying RCL. This is allowed for SELECT * views when an underlying table has had columns added to it via ALTER TABLE. return Whether or not a mismatch is allowed.


getTotalColumnSize

public int getTotalColumnSize()
Get the size of all the columns added together. Does NOT include the column overhead that the store requires. Also, will be a very rough estimate for user types.

Returns:
the size

createListFromResultSetMetaData

public void createListFromResultSetMetaData(java.sql.ResultSetMetaData rsmd,
                                            TableName tableName,
                                            java.lang.String javaClassName)
                                     throws StandardException
Generate an RCL to match the contents of a ResultSetMetaData. This is useful when dealing with VTIs.

Parameters:
rsmd - The ResultSetMetaData.
tableName - The TableName for the BCNs.
javaClassName - The name of the VTI
Throws:
StandardException - Thrown on error

addColumn

public void addColumn(TableName tableName,
                      java.lang.String columnName,
                      DataTypeDescriptor dts)
               throws StandardException
Add a column to the list given a tablename, columnname, and datatype.

Throws:
StandardException

addRCForRID

public void addRCForRID()
                 throws StandardException
Add an RC to the end of the list for the RID from an index. NOTE: RC.expression is a CurrentRowLocationNode. This was previously only used for non-select DML. We test for this node when generating the holder above and generate the expected code. (We really should create yet another new node type with its own code generation.)

Throws:
StandardException - Thrown on error

markAllUnreferenced

public void markAllUnreferenced()
                         throws StandardException
Walk the list and mark all RCs as unreferenced. This is useful when recalculating which RCs are referenced at what level like when deciding which columns need to be returned from a non-matching index scan (as opposed to those returned from the base table).

Throws:
StandardException - Thrown on error

allExpressionsAreColumns

boolean allExpressionsAreColumns(ResultSetNode sourceRS)
Determine if all of the RC.expressions are columns in the source result set. This is useful for determining if we need to do reflection at execution time.

Parameters:
sourceRS - The source ResultSet.
Returns:
Whether or not all of the RC.expressions are columns in the source result set.

mapSourceColumns

ResultColumnList.ColumnMapping mapSourceColumns()
Map the source columns to these columns. Build an array to represent the mapping. For each RC, if the expression is simply a VCN or a CR then set the array element to be the virtual column number of the source RC. Otherwise, set the array element to -1. This is useful for determining if we need to do reflection at execution time.

Also build an array of boolean for columns that point to the same virtual column and have types that are streamable to be able to determine if cloning is needed at execution time.

Returns:
Array representiong mapping of RCs to source RCs.

setNullability

public void setNullability(boolean nullability)
                    throws StandardException
Set the nullability of every ResultColumn in this list

Throws:
StandardException

getReferencedFormatableBitSet

FormatableBitSet getReferencedFormatableBitSet(boolean positionedUpdate,
                                               boolean always,
                                               boolean onlyBCNs)
Generate a FormatableBitSet representing the columns that are referenced in this RCL. The caller decides if they want this FormatableBitSet if every RC is referenced.

Parameters:
positionedUpdate - Whether or not the scan that the RCL belongs to is for update w/o a column list
always - Whether or not caller always wants a non-null FormatableBitSet if all RCs are referenced.
onlyBCNs - If true, only set bit if expression is a BaseColumnNode, otherwise set bit for all referenced RCs.
Returns:
The FormatableBitSet representing the referenced RCs.

compactColumns

ResultColumnList compactColumns(boolean positionedUpdate,
                                boolean always)
                          throws StandardException
Create a new, compacted RCL based on the referenced RCs in this list. If the RCL being compacted is for an updatable scan, then we simply return this. The caller tells us whether or not they want a new list if there is no compaction because all RCs are referenced. This is useful in the case where the caller needs a new RCL for existing RCs so that it can augment the new list.

Parameters:
positionedUpdate - Whether or not the scan that the RCL belongs to is for update w/o a column list
always - Whether or not caller always wants a new RCL
Returns:
The compacted RCL if compaction occurred, otherwise return this RCL.
Throws:
StandardException - Thrown on error

removeJoinColumns

void removeJoinColumns(ResultColumnList joinColumns)
Remove the columns which are join columns (in the joinColumns RCL) from this list. This is useful for a JOIN with a USING clause.

Parameters:
joinColumns - The list of join columns

getJoinColumns

ResultColumnList getJoinColumns(ResultColumnList joinColumns)
                          throws StandardException
Get the join columns from this list. This is useful for a join with a USING clause. (ANSI specifies that the join columns appear 1st.)

Parameters:
joinColumns - A list of the join columns.
Returns:
A list of the join columns from this list
Throws:
StandardException

resetVirtualColumnIds

void resetVirtualColumnIds()
Reset the virtual column ids for all of the underlying RCs. (Virtual column ids are 1-based.)


reusableResult

boolean reusableResult()
Return whether or not the same result row can be used for all rows returned by the associated ResultSet. This is possible if all entries in the list are constants or AggregateNodes.

Returns:
Whether or not the same result row can be used for all rows returned by the associated ResultSet.

getColumnPositions

public int[] getColumnPositions(TableDescriptor td)
                         throws StandardException
Get an array of column positions (1-based) for all the columns in this RCL. Assumes that all the columns are in the passed-in table

Returns:
the array of strings
Throws:
throws - StandardException on error
StandardException

getColumnNames

public java.lang.String[] getColumnNames()
Get an array of strings for all the columns in this RCL.

Returns:
the array of strings

replaceOrForbidDefaults

void replaceOrForbidDefaults(TableDescriptor ttd,
                             ResultColumnList tcl,
                             boolean allowDefaults)
                       throws StandardException
Replace any DEFAULTs with the associated tree for the default if allowed, or flag.

Parameters:
ttd - The TableDescriptor for the target table.
tcl - The RCL for the target table.
allowDefaults - true if allowed
Throws:
StandardException - Thrown on error

checkForInvalidDefaults

void checkForInvalidDefaults()
                       throws StandardException
Walk the RCL and check for DEFAULTs. DEFAULTs are invalid at the time that this method is called, so we throw an exception if found. NOTE: The grammar allows: VALUES DEFAULT;

Throws:
StandardException - Thrown on error

verifyAllOrderable

void verifyAllOrderable()
                  throws StandardException
Verify that all of the RCs in this list are comparable.

Throws:
StandardException - Thrown on error

populate

public void populate(TableDescriptor table,
                     int[] columnIDs)
              throws StandardException
Build this ResultColumnList from a table description and an array of column IDs.

Parameters:
table - describes the table
columnIDs - column positions in that table (1-based)
Throws:
StandardException - Thrown on error

makeColumnFromName

private ResultColumn makeColumnFromName(java.lang.String columnName)
                                 throws StandardException
Throws:
StandardException

makeColumnReferenceFromName

private ResultColumn makeColumnReferenceFromName(TableName tableName,
                                                 java.lang.String columnName)
                                          throws StandardException
Throws:
StandardException

forbidOverrides

public void forbidOverrides(ResultColumnList sourceRSRCL)
                     throws StandardException
check if any autoincrement or generated columns exist in the result column list. called from insert or update where you cannot insert/update the value of a generated or autoincrement column.

Throws:
StandardException - If the column is an ai column

incOrderBySelect

public void incOrderBySelect()

decOrderBySelect

private void decOrderBySelect()

getOrderBySelect

public int getOrderBySelect()

copyOrderBySelect

public void copyOrderBySelect(ResultColumnList src)

markInitialSize

protected void markInitialSize()

numGeneratedColumns

private int numGeneratedColumns()

numGeneratedColumnsForGroupBy

int numGeneratedColumnsForGroupBy()
Returns:
the number of generated columns in this RCL.

removeGeneratedGroupingColumns

void removeGeneratedGroupingColumns()
Remove any generated columns from this RCL.


visibleSize

public int visibleSize()
Returns:
the number of columns that will be visible during execution. During compilation we can add columns for a group by/order by but these to an RCL but these are projected out during query execution.

toString

public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class QueryTreeNode
Returns:
This object as a String

streamableType

private static boolean streamableType(ResultColumn rc)

updateArrays

private static void updateArrays(int[] mapArray,
                                 boolean[] cloneMap,
                                 java.util.Map seenMap,
                                 ResultColumn rc,
                                 int index)

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.