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

public final Class UpdateNode

extends DMLModGeneratedColumnsStatementNode
Class Inheritance
Imports
java.lang.reflect.Modifier, java.sql.Types, java.util.ArrayList, .HashSet, .List, org.apache.derby.catalog.DefaultInfo, .UUID, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, .SQLState, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.sql.StatementType, org.apache.derby.iapi.sql.compile.CompilerContext, .TagFilter, org.apache.derby.iapi.sql.conn.Authorizer, .LanguageConnectionContext, org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor, .ColumnDescriptor, .ColumnDescriptorList, .ConglomerateDescriptor, .ConstraintDescriptor, .ConstraintDescriptorList, .DataDictionary, .TableDescriptor, .TriggerDescriptor, .TriggerDescriptorList, org.apache.derby.iapi.sql.execute.ConstantAction, .ExecPreparedStatement, org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo, .TransactionController, org.apache.derby.iapi.types.TypeId, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.vti.DeferModification

An UpdateNode represents an UPDATE statement. It is the top node of the query tree for that statement. For positioned update, there may be no from table specified. The from table will be derived from the cursor specification of the named cursor.

Field Summary

Modifier and TypeField and Description
pack-priv int[]
pack-priv ValueNode
pack-priv static final String
pack-priv boolean
protected boolean
protected FormatableBitSet
protected FromTable
Inherited from org.apache.derby.impl.sql.compile.DMLModGeneratedColumnsStatementNode:
autoincRowLocationidentitySequenceUUIDString

Constructor Summary

AccessConstructor and Description
pack-priv
UpdateNode(TableName
The name of the table to update
targetTableName
,
ResultSetNode
The ResultSet that we will generate
resultSet
,
MatchingClauseNode
Non-null if this DML is part of a MATCHED clause of a MERGE statement.
matchingClause
,
ContextManager
The context manager
cm
)

Constructor for an UpdateNode.

Method Summary

Modifier and TypeMethod and Description
private static void
addGeneratedColumnPrecursors(TableDescriptor baseTable, ColumnDescriptorList affectedGeneratedColumns, FormatableBitSet columnMap)

Add all of the columns mentioned by the generation clauses of generated columns.

private void
addGeneratedColumns(TableDescriptor baseTable, ResultSetNode updateSet, ColumnDescriptorList affectedGeneratedColumns, ColumnDescriptorList addedGeneratedColumns)

Add generated columns to the update list as necessary.

private void
addUpdatePriv(ArrayList<String> explicitlySetColumns)

Add UPDATE_PRIV on all columns on the left side of SET operators.

private void
associateAddedColumns()

Associate all added columns with the TARGET table of the enclosing MERGE statement.

public void
private void
checkTableNameAndScrubResultColumns(ResultColumnList rcl)

Check table name and then clear it from the result set columns.

private List<CastNode>
collectAllCastNodes()

Collect all of the CastNodes in the WHERE clause and on the right side of SET operators.

private List<ColumnReference>
collectAllResultSetColumns()

Collect all of the result set columns.

private void
collectPrivilegedNodes(ArrayList<QueryTreeNode> result, QueryTreeNode expr)

Add to an evolving list all of the nodes under an expression which may require privilege checks.

private void
forbidGenerationOverrides(ResultColumnList
the row in the table being UPDATEd
targetRCL
,
ColumnDescriptorList
generated columns which the compiler added earlier on
addedGeneratedColumns
)

Do not allow generation clauses to be overriden.

pack-priv void
generate(ActivationClassBuilder
The ActivationClassBuilder for the class being built
acb
,
MethodBuilder
The method for the execute() method to be built
mb
)

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

Code generation for update.

private int[]
getChangedColumnIds(ResultColumnList rcl)

Construct the changedColumnIds array.

private ArrayList<String>
getExplicitlySetColumns()

Get the names of the explicitly set columns, that is, the columns on the left side of SET operators.

pack-priv int
getPrivType()

Overrides org.apache.derby.impl.sql.compile.DMLStatementNode.getPrivType.

Return default privilege needed for this node.

pack-priv FormatableBitSet

Returns:

a FormatableBitSet of columns to be read out of the base table
getReadMap
(DataDictionary
the data dictionary to look in
dd
,
TableDescriptor
the base table descriptor
baseTable
,
ResultColumnList
the rcl for the update. CANNOT BE NULL
updateColumnList
,
ColumnDescriptorList
columns whose generation clauses mention columns being updated
affectedGeneratedColumns
)

Gets the map of all columns which must be read out of the base table.

protected final int

Returns:

the type of statement
getStatementType
()

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

Return the type of statement, something from StatementType.

pack-priv static FormatableBitSet

Returns:

a FormatableBitSet of columns to be read out of the base table
getUpdateReadMap
(DataDictionary
Data Dictionary
dd
,
TableDescriptor
Table on which update is issued
baseTable
,
ResultColumnList
a list of updated columns
updateColumnList
,
List<ConglomerateDescriptor>
OUT: list of affected indices
conglomerates
,
ConstraintDescriptorList
IN/OUT. Empty list is passed in. We hang constraints on it as we go.
relevantConstraints
,
TriggerDescriptorList
IN/OUT. Passed in as an empty list. Filled in as we go.
relevantTriggers
,
boolean[]
IN/OUT. true if the statement already needs deferred processing. set while evaluating this routine if a trigger or constraint requires deferred processing
needsDeferredProcessing
,
ColumnDescriptorList
columns whose generation clauses mention updated columns
affectedGeneratedColumns
)

Builds a bitmap of all columns which should be read from the Store in order to satisfy an UPDATE statement.

public ConstantAction
makeConstantAction()

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

Compile constants that Execution will use

private void
private void
normalizeSynonymColumns(ResultColumnList
The result column list of the target table
rcl
,
FromTable
The table name to set the column refs to
fromTable
)

Normalize synonym column references to have the name of the base table.

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

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

Prints the sub-nodes of this object.

public boolean

Returns:

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

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

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

protected void
setDeferredForUpdateOfIndexColumn()

Updates are deferred if they update a column in the index used to scan the table being updated.

pack-priv String
private void
tagOriginalResultSetColumns()

Tag the original columns mentioned in the result list.

private void
tagPrivilegedNodes()

Tag all of the nodes which may require privilege checks.

public String

Returns:

This object as a String
toString
()

Overrides org.apache.derby.impl.sql.compile.StatementNode.toString.

Convert this object to a String.

Inherited from org.apache.derby.impl.sql.compile.DMLModGeneratedColumnsStatementNode:
getUUIDofSequenceGenerator

Field Detail

changedColumnIdsback to summary
pack-priv int[] changedColumnIds
checkConstraintsback to summary
pack-priv ValueNode checkConstraints

Hides org.apache.derby.impl.sql.compile.DMLModStatementNode.checkConstraints.

COLUMNNAMEback to summary
pack-priv static final String COLUMNNAME
deferredback to summary
pack-priv boolean deferred
positionedUpdateback to summary
protected boolean positionedUpdate
readColsBitSetback to summary
protected FormatableBitSet readColsBitSet
targetTableback to summary
protected FromTable targetTable

Constructor Detail

UpdateNodeback to summary
pack-priv UpdateNode(TableName targetTableName, ResultSetNode resultSet, MatchingClauseNode matchingClause, ContextManager cm)

Constructor for an UpdateNode.

Parameters
targetTableName:TableName

The name of the table to update

resultSet:ResultSetNode

The ResultSet that we will generate

matchingClause:MatchingClauseNode

Non-null if this DML is part of a MATCHED clause of a MERGE statement.

cm:ContextManager

The context manager

Method Detail

addGeneratedColumnPrecursorsback to summary
private static void addGeneratedColumnPrecursors(TableDescriptor baseTable, ColumnDescriptorList affectedGeneratedColumns, FormatableBitSet columnMap) throws StandardException

Add all of the columns mentioned by the generation clauses of generated columns. The generated columns were added when we called addGeneratedColumns earlier on.

addGeneratedColumnsback to summary
private void addGeneratedColumns(TableDescriptor baseTable, ResultSetNode updateSet, ColumnDescriptorList affectedGeneratedColumns, ColumnDescriptorList addedGeneratedColumns) throws StandardException

Add generated columns to the update list as necessary. We add any column whose generation clause mentions columns already in the update list. We fill in a list of all generated columns affected by this update. We also fill in a list of all generated columns which we added to the update list.

addUpdatePrivback to summary
private void addUpdatePriv(ArrayList<String> explicitlySetColumns) throws StandardException

Add UPDATE_PRIV on all columns on the left side of SET operators.

associateAddedColumnsback to summary
private void associateAddedColumns() throws StandardException

Associate all added columns with the TARGET table of the enclosing MERGE statement.

bindStatementback to summary
public void bindStatement() throws StandardException

Overrides org.apache.derby.impl.sql.compile.StatementNode.bindStatement.

Bind this UpdateNode. This means looking up tables and columns and getting their types, and figuring out the result types of all expressions, as well as doing view resolution, permissions checking, etc.

Binding an update will also massage the tree so that the ResultSetNode has a set of columns to contain the old row value, followed by a set of columns to contain the new row value, followed by a column to contain the RowLocation of the row to be updated.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
checkTableNameAndScrubResultColumnsback to summary
private void checkTableNameAndScrubResultColumns(ResultColumnList rcl) throws StandardException

Check table name and then clear it from the result set columns.

Exceptions
StandardException:
if invalid column/table is specified.
collectAllCastNodesback to summary
private List<CastNode> collectAllCastNodes() throws StandardException

Collect all of the CastNodes in the WHERE clause and on the right side of SET operators. Later on, we will need to add permissions for all UDTs mentioned by these nodes.

collectAllResultSetColumnsback to summary
private List<ColumnReference> collectAllResultSetColumns() throws StandardException

Collect all of the result set columns.

collectPrivilegedNodesback to summary
private void collectPrivilegedNodes(ArrayList<QueryTreeNode> result, QueryTreeNode expr) throws StandardException

Add to an evolving list all of the nodes under an expression which may require privilege checks.

forbidGenerationOverridesback to summary
private void forbidGenerationOverrides(ResultColumnList targetRCL, ColumnDescriptorList addedGeneratedColumns) throws StandardException

Do not allow generation clauses to be overriden. Throws an exception if the user attempts to override the value of a generated column. The only value allowed in a generated column is DEFAULT. We will use addedGeneratedColumns list to pass through the generated columns which have already been added to the update list.

Parameters
targetRCL:ResultColumnList

the row in the table being UPDATEd

addedGeneratedColumns:ColumnDescriptorList

generated columns which the compiler added earlier on

Exceptions
StandardException:
on error
generateback to summary
pack-priv void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException

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

Code generation for update. The generated code will contain: o A static member for the (xxx)ResultSet with the RowLocations and new update values o The static member will be assigned the appropriate ResultSet within the nested calls to get the ResultSets. (The appropriate cast to the (xxx)ResultSet will be generated.) o The CurrentRowLocation() in SelectNode's select list will generate a new method for returning the RowLocation as well as a call to that method when generating the (xxx)ResultSet.

Parameters
acb:ActivationClassBuilder

The ActivationClassBuilder for the class being built

mb:MethodBuilder

The method for the execute() method to be built

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getChangedColumnIdsback to summary
private int[] getChangedColumnIds(ResultColumnList rcl)

Construct the changedColumnIds array. Note we sort its entries by columnId.

getExplicitlySetColumnsback to summary
private ArrayList<String> getExplicitlySetColumns() throws StandardException

Get the names of the explicitly set columns, that is, the columns on the left side of SET operators.

getPrivTypeback to summary
pack-priv int getPrivType()

Overrides org.apache.derby.impl.sql.compile.DMLStatementNode.getPrivType.

Doc from org.apache.derby.impl.sql.compile.DMLStatementNode.getPrivType.

Return default privilege needed for this node. Other DML nodes can override this method to set their own default privilege.

Returns:int

true if the statement is atomic

Annotations
@Override
getReadMapback to summary
pack-priv FormatableBitSet getReadMap(DataDictionary dd, TableDescriptor baseTable, ResultColumnList updateColumnList, ColumnDescriptorList affectedGeneratedColumns) throws StandardException

Gets the map of all columns which must be read out of the base table. These are the columns needed to

    :
  • maintain indices
  • maintain foreign keys
  • maintain generated columns
  • support Replication's Delta Optimization

The returned map is a FormatableBitSet with 1 bit for each column in the table plus an extra, unsued 0-bit. If a 1-based column id must be read from the base table, then the corresponding 1-based bit is turned ON in the returned FormatableBitSet.

Note

this method is not expected to be called when all columns are being updated (i.e. updateColumnList is null).

Parameters
dd:DataDictionary

the data dictionary to look in

baseTable:TableDescriptor

the base table descriptor

updateColumnList:ResultColumnList

the rcl for the update. CANNOT BE NULL

affectedGeneratedColumns:ColumnDescriptorList

columns whose generation clauses mention columns being updated

Returns:FormatableBitSet

a FormatableBitSet of columns to be read out of the base table

Exceptions
StandardException:
Thrown on error
getStatementTypeback to summary
protected final int getStatementType()

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

Return the type of statement, something from StatementType.

Returns:int

the type of statement

Annotations
@Override
getUpdateReadMapback to summary
pack-priv static FormatableBitSet getUpdateReadMap(DataDictionary dd, TableDescriptor baseTable, ResultColumnList updateColumnList, List<ConglomerateDescriptor> conglomerates, ConstraintDescriptorList relevantConstraints, TriggerDescriptorList relevantTriggers, boolean[] needsDeferredProcessing, ColumnDescriptorList affectedGeneratedColumns) throws StandardException

Builds a bitmap of all columns which should be read from the Store in order to satisfy an UPDATE statement. Is passed a list of updated columns. Does the following: 1) finds all indices which overlap the updated columns 2) adds the index columns to a bitmap of affected columns 3) adds the index descriptors to a list of conglomerate descriptors. 4) finds all constraints which overlap the updated columns and adds the constrained columns to the bitmap 5) finds all triggers which overlap the updated columns. 6) Go through all those triggers from step 5 and for each one of those triggers, follow the rules below to decide which columns should be read. Rule1)If trigger column information is null, then read all the columns from trigger table into memory irrespective of whether there is any trigger action column information. 2 egs of such triggers create trigger tr1 after update on t1 for each row values(1); create trigger tr1 after update on t1 referencing old as oldt for each row insert into t2 values(2,oldt.j,-2); Rule2)If trigger column information is available but no trigger action column information is found and no REFERENCES clause is used for the trigger, then read all the columns identified by the trigger column. eg create trigger tr1 after update of c1 on t1 for each row values(1); Rule3)If trigger column information and trigger action column information both are not null, then only those columns will be read into memory. This is possible only for triggers created in release 10.9 or higher(with the exception of 10.7.1.1 where we did collect that information but because of corruption caused by those changes, we do not use the information collected by 10.7). Starting 10.9, we are collecting trigger action column informatoin so we can be smart about what columns get read during trigger execution. eg create trigger tr1 after update of c1 on t1 referencing old as oldt for each row insert into t2 values(2,oldt.j,-2); Rule4)If trigger column information is available but no trigger action column information is found but REFERENCES clause is used for the trigger, then read all the columns from the trigger table. This will cover soft-upgrade scenario for triggers created pre-10.9. eg trigger created prior to 10.9 create trigger tr1 after update of c1 on t1 referencing old as oldt for each row insert into t2 values(2,oldt.j,-2); 7) adds the triggers to an evolving list of triggers 8) finds all generated columns whose generation clauses mention the updated columns and adds all of the mentioned columns

Parameters
dd:DataDictionary

Data Dictionary

baseTable:TableDescriptor

Table on which update is issued

updateColumnList:ResultColumnList

a list of updated columns

conglomerates:List<ConglomerateDescriptor>

OUT: list of affected indices

relevantConstraints:ConstraintDescriptorList

IN/OUT. Empty list is passed in. We hang constraints on it as we go.

relevantTriggers:TriggerDescriptorList

IN/OUT. Passed in as an empty list. Filled in as we go.

needsDeferredProcessing:boolean[]

IN/OUT. true if the statement already needs deferred processing. set while evaluating this routine if a trigger or constraint requires deferred processing

affectedGeneratedColumns:ColumnDescriptorList

columns whose generation clauses mention updated columns

Returns:FormatableBitSet

a FormatableBitSet of columns to be read out of the base table

Exceptions
StandardException:
Thrown on error
makeConstantActionback to summary
public ConstantAction makeConstantAction() throws StandardException

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

Compile constants that Execution will use

Annotations
@Override
Exceptions
StandardException:
Thrown on failure
normalizeCorrelatedColumnsback to summary
private void normalizeCorrelatedColumns(ResultColumnList rcl, FromTable fromTable) throws StandardException
normalizeSynonymColumnsback to summary
private void normalizeSynonymColumns(ResultColumnList rcl, FromTable fromTable) throws StandardException

Normalize synonym column references to have the name of the base table.

Parameters
rcl:ResultColumnList

The result column list of the target table

fromTable:FromTable

The table name to set the column refs to

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

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

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

Parameters
depth:int

The depth of this node in the tree

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

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

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

Returns:boolean

true if references SESSION schema tables, else false

Annotations
@Override
Exceptions
StandardException:
Thrown on error
setDeferredForUpdateOfIndexColumnback to summary
protected void setDeferredForUpdateOfIndexColumn()

Updates are deferred if they update a column in the index used to scan the table being updated.

statementToStringback to summary
pack-priv String statementToString()

Overrides org.apache.derby.impl.sql.compile.DMLModStatementNode.statementToString.

Annotations
@Override
tagOriginalResultSetColumnsback to summary
private void tagOriginalResultSetColumns() throws StandardException

Tag the original columns mentioned in the result list.

tagPrivilegedNodesback to summary
private void tagPrivilegedNodes() throws StandardException

Tag all of the nodes which may require privilege checks. These are various QueryTreeNodes in the WHERE clause and on the right side of SET operators.

toStringback to summary
public String toString()

Overrides org.apache.derby.impl.sql.compile.StatementNode.toString.

Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Returns:String

This object as a String

Annotations
@Override