Class MatchingClauseNode
- All Implemented Interfaces:
Visitable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private int
private DMLModStatementNode
private ResultColumnList
private ResultColumnList
private ValueNode
private String
private String
private ResultColumnList
private ResultColumnList
private static final String
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
MatchingClauseNode
(ValueNode matchingRefinement, ResultColumnList updateColumns, ResultColumnList insertColumns, ResultColumnList insertValues, ContextManager cm) Constructor called by factory methods. -
Method Summary
Modifier and TypeMethodDescription(package private) void
Accept the visitor for all visitable children of this node.private void
adjustMatchingRefinement
(ResultColumnList selectList, ResultSetNode generatedScan) Point the column references in the matching refinement at the corresponding columns returned by the driving left join.private void
adjustThenColumns
(ResultColumnList selectList, ResultSetNode generatedScan, HalfOuterJoinNode hojn) Point the column references in the temporary row at the corresponding columns returned by the driving left join.(package private) void
bind
(DataDictionary dd, MergeNode mergeNode, FromList fullFromList, FromBaseTable targetTable) Bind this WHEN [ NOT ] MATCHED clause against the parent MergeNodeprivate void
bindDelete
(DataDictionary dd, FromList fullFromList, FromBaseTable targetTable) Bind a WHEN MATCHED ...private void
bindExpressions
(ResultColumnList rcl, FromList fromList) Boilerplate for binding a list of ResultColumns against a FromListprivate void
bindInsert
(DataDictionary dd, MergeNode mergeNode, FromList fullFromList, FromBaseTable targetTable) Bind a WHEN NOT MATCHED ...private void
bindInsertValues
(FromList fullFromList, FromTable targetTable) Bind the values in the INSERT list(package private) void
bindRefinement
(MergeNode mergeNode, FromList fullFromList) Bind the optional refinement condition in the MATCHED clauseprivate void
bindSetClauses
(MergeNode mergeNode, FromList fullFromList, FromTable targetTable, ResultColumnList setClauses) Bind the SET clauses of an UPDATE actionprivate void
bindUpdate
(DataDictionary dd, MergeNode mergeNode, FromList fullFromList, FromBaseTable targetTable) Bind a WHEN MATCHED ...private ResultColumnList
Build the full column list for a table.private void
Construct the signature of the temporary table which drives the INSERT/UPDATE/DELETE action.private void
buildThenColumnsForInsert
(FromList fullFromList, FromTable targetTable, ResultColumnList fullRow, ResultColumnList insertColumns, ResultColumnList insertValues) Construct the row in the temporary table which drives an INSERT action.private void
buildThenColumnsForUpdate
(FromList fullFromList, FromTable targetTable, ResultColumnList fullRow, ResultColumnList beforeRow, ResultColumnList afterValues) Construct the row in the temporary table which drives an UPDATE action.private ResultDescription
Build the signature of the row which will go into the temporary table.private void
Forbid subqueries in WHEN [ NOT ] MATCHED clauses.private void
private void
forbidSubqueries
(ValueNode expr) (package private) void
generate
(ActivationClassBuilder acb, ResultColumnList selectList, ResultSetNode generatedScan, HalfOuterJoinNode hojn, int clauseNumber) Generate a method to invoke the INSERT/UPDATE/DELETE action.private void
generateInsertUpdateRow
(ActivationClassBuilder acb, ResultColumnList selectList, ResultSetNode generatedScan, HalfOuterJoinNode hojn) Generate a method to build a row for the temporary table for INSERT/UPDATE actions.(package private) void
Adds a field to the generated class to hold the ResultSet of "then" rows which drive the INSERT/UPDATE/DELETE action.private ResultSetNode
Get the bound SELECT node under the dummy UPDATE node.Get the names of the columns explicitly changed by SET clausesgetChangedGeneratedColumnNames
(TableDescriptor targetTableDescriptor, HashSet<String> changedColumnNames) Get the names of the generated columns which are changed by the UPDATE statement.private int
private List
<ColumnReference> getColumnReferences
(QueryTreeNode expression) Get a list of column references in an expression(package private) void
getColumnsInExpressions
(MergeNode mergeNode, HashMap<String, ColumnReference> drivingColumnMap) Collect the columns mentioned by expressions in this MATCHED clauseprivate int
Find the MERGE table id of the indicated columnprivate int
getSelectListOffset
(ResultColumnList selectList, ValueNode thenExpression) Find a column reference in the SELECT list of the driving left join and return its 1-based offset into that list.(package private) ResultColumnList
Return the list of columns which form the rows of the ResultSet which drive the INSERT/UPDATE/DELETE actions.(package private) boolean
Return true if this is a WHEN MATCHED ...(package private) boolean
Return true if this is a WHEN NOT MATCHED ...private boolean
Return true if the ResultColumn represents a RowLocation(package private) boolean
Return true if this is a WHEN MATCHED ...private ResultColumn
makeAutoGenRC
(FromTable targetTable, ResultColumn origRC, int virtualColumnID) Make a ResultColumn for an identity column which is being set to the DEFAULT value.(package private) ConstantAction
(package private) static MatchingClauseNode
makeDeleteClause
(ValueNode matchingRefinement, ContextManager cm) Make a WHEN MATCHED ...(package private) static MatchingClauseNode
makeInsertClause
(ValueNode matchingRefinement, ResultColumnList insertColumns, ResultColumnList insertValues, ContextManager cm) Make a WHEN NOT MATCHED ...(package private) static MatchingClauseNode
makeUpdateClause
(ValueNode matchingRefinement, ResultColumnList updateColumns, ContextManager cm) Make a WHEN MATCHED ...(package private) void
optimize()
Optimize the INSERT/UPDATE/DELETE action.(package private) void
printSubNodes
(int depth) Prints the sub-nodes of this object.private ResultColumnList
realiasSetClauses
(FromBaseTable targetTable) Due to discrepancies in how names are resolved by SELECT and UPDATE, we have to force the left side of SET clauses to use the same table identifiers as the right sides of the SET clauses.boolean
Return true if the node references SESSION schema tables (temporary or permanent)private static boolean
private void
Re-map ColumnReferences in constraints to point into the row from the temporary table.toString()
Convert this object to a String.private void
useGeneratedScan
(ResultColumnList selectList, ResultSetNode generatedScan, QueryTreeNode node) Point a node's ColumnReferences into the row returned by the driving left join.Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
Field Details
-
CURRENT_OF_NODE_NAME
- See Also:
-
_matchingRefinement
-
_updateColumns
-
_insertColumns
-
_insertValues
-
_dml
-
_thenColumns
-
_clauseNumber
private int _clauseNumber -
_actionMethodName
-
_resultSetFieldName
-
_rowMakingMethodName
-
-
Constructor Details
-
MatchingClauseNode
private MatchingClauseNode(ValueNode matchingRefinement, ResultColumnList updateColumns, ResultColumnList insertColumns, ResultColumnList insertValues, ContextManager cm) throws StandardException Constructor called by factory methods.- Throws:
StandardException
-
-
Method Details
-
makeUpdateClause
static MatchingClauseNode makeUpdateClause(ValueNode matchingRefinement, ResultColumnList updateColumns, ContextManager cm) throws StandardException Make a WHEN MATCHED ... THEN UPDATE clause- Throws:
StandardException
-
makeDeleteClause
static MatchingClauseNode makeDeleteClause(ValueNode matchingRefinement, ContextManager cm) throws StandardException Make a WHEN MATCHED ... THEN DELETE clause- Throws:
StandardException
-
makeInsertClause
static MatchingClauseNode makeInsertClause(ValueNode matchingRefinement, ResultColumnList insertColumns, ResultColumnList insertValues, ContextManager cm) throws StandardException Make a WHEN NOT MATCHED ... THEN INSERT clause- Throws:
StandardException
-
isUpdateClause
boolean isUpdateClause()Return true if this is a WHEN MATCHED ... UPDATE clause -
isInsertClause
boolean isInsertClause()Return true if this is a WHEN NOT MATCHED ... INSERT clause -
isDeleteClause
boolean isDeleteClause()Return true if this is a WHEN MATCHED ... DELETE clause -
getThenColumns
ResultColumnList getThenColumns()Return the list of columns which form the rows of the ResultSet which drive the INSERT/UPDATE/DELETE actions. -
bind
void bind(DataDictionary dd, MergeNode mergeNode, FromList fullFromList, FromBaseTable targetTable) throws StandardException Bind this WHEN [ NOT ] MATCHED clause against the parent MergeNode- Throws:
StandardException
-
bindRefinement
Bind the optional refinement condition in the MATCHED clause- Throws:
StandardException
-
getColumnsInExpressions
void getColumnsInExpressions(MergeNode mergeNode, HashMap<String, ColumnReference> drivingColumnMap) throws StandardExceptionCollect the columns mentioned by expressions in this MATCHED clause- Throws:
StandardException
-
bindUpdate
private void bindUpdate(DataDictionary dd, MergeNode mergeNode, FromList fullFromList, FromBaseTable targetTable) throws StandardException Bind a WHEN MATCHED ... THEN UPDATE clause- Throws:
StandardException
-
realiasSetClauses
Due to discrepancies in how names are resolved by SELECT and UPDATE, we have to force the left side of SET clauses to use the same table identifiers as the right sides of the SET clauses.
- Throws:
StandardException
-
getBoundSelectUnderUpdate
Get the bound SELECT node under the dummy UPDATE node. This may not be the source result set of the UPDATE node. That is because a ProjectRestrictNode may have been inserted on top of it by DEFAULT handling. This method exists to make the UPDATE actions of MERGE statements behave like ordinary UPDATE statements in this situation. The behavior is actually wrong. See DERBY-6414. Depending on how that bug is addressed, we may be able to remove this method eventually.
- Throws:
StandardException
-
bindSetClauses
private void bindSetClauses(MergeNode mergeNode, FromList fullFromList, FromTable targetTable, ResultColumnList setClauses) throws StandardException Bind the SET clauses of an UPDATE action- Throws:
StandardException
-
buildThenColumnsForUpdate
private void buildThenColumnsForUpdate(FromList fullFromList, FromTable targetTable, ResultColumnList fullRow, ResultColumnList beforeRow, ResultColumnList afterValues) throws StandardException Construct the row in the temporary table which drives an UPDATE action. Unlike a DELETE, whose temporary row is just a list of copied columns, the temporary row for UPDATE may contain complex expressions which must be code-generated later on.
- Throws:
StandardException
-
getChangedColumnNames
Get the names of the columns explicitly changed by SET clauses- Throws:
StandardException
-
getChangedGeneratedColumnNames
private HashSet<String> getChangedGeneratedColumnNames(TableDescriptor targetTableDescriptor, HashSet<String> changedColumnNames) throws StandardException Get the names of the generated columns which are changed by the UPDATE statement. These are the generated columns which match one of the following conditions:
- Are explicitly mentioned on the left side of a SET clause.
- Are built from other columns which are explicitly mentioned on the left side of a SET clause.
- Throws:
StandardException
-
bindDelete
private void bindDelete(DataDictionary dd, FromList fullFromList, FromBaseTable targetTable) throws StandardException Bind a WHEN MATCHED ... THEN DELETE clause- Throws:
StandardException
-
buildThenColumnsForDelete
Construct the signature of the temporary table which drives the INSERT/UPDATE/DELETE action.
- Throws:
StandardException
-
bindInsert
private void bindInsert(DataDictionary dd, MergeNode mergeNode, FromList fullFromList, FromBaseTable targetTable) throws StandardException Bind a WHEN NOT MATCHED ... THEN INSERT clause- Throws:
StandardException
-
bindInsertValues
private void bindInsertValues(FromList fullFromList, FromTable targetTable) throws StandardException Bind the values in the INSERT list- Throws:
StandardException
-
buildFullColumnList
Build the full column list for a table.
- Throws:
StandardException
-
buildThenColumnsForInsert
private void buildThenColumnsForInsert(FromList fullFromList, FromTable targetTable, ResultColumnList fullRow, ResultColumnList insertColumns, ResultColumnList insertValues) throws StandardException Construct the row in the temporary table which drives an INSERT action. Unlike a DELETE, whose temporary row is just a list of copied columns, the temporary row for INSERT may contain complex expressions which must be code-generated later on.
- Throws:
StandardException
-
makeAutoGenRC
private ResultColumn makeAutoGenRC(FromTable targetTable, ResultColumn origRC, int virtualColumnID) throws StandardException Make a ResultColumn for an identity column which is being set to the DEFAULT value. This special ResultColumn will make it through code generation so that it will be calculated when the INSERT/UPDATE action is run.
- Throws:
StandardException
-
bindExpressions
Boilerplate for binding a list of ResultColumns against a FromList- Throws:
StandardException
-
forbidSubqueries
Forbid subqueries in WHEN [ NOT ] MATCHED clauses.
- Throws:
StandardException
-
forbidSubqueries
- Throws:
StandardException
-
forbidSubqueries
- Throws:
StandardException
-
optimize
Optimize the INSERT/UPDATE/DELETE action.
- Throws:
StandardException
-
makeConstantAction
- Throws:
StandardException
-
getClauseType
private int getClauseType() -
buildThenColumnSignature
Build the signature of the row which will go into the temporary table.
- Throws:
StandardException
-
generate
void generate(ActivationClassBuilder acb, ResultColumnList selectList, ResultSetNode generatedScan, HalfOuterJoinNode hojn, int clauseNumber) throws StandardException Generate a method to invoke the INSERT/UPDATE/DELETE action. This method will be called at runtime by MatchingClauseConstantAction.executeConstantAction().
- Throws:
StandardException
-
remapConstraints
Re-map ColumnReferences in constraints to point into the row from the temporary table. This is where the row will be stored when constraints are being evaluated.
- Throws:
StandardException
-
generateResultSetField
Adds a field to the generated class to hold the ResultSet of "then" rows which drive the INSERT/UPDATE/DELETE action. Generates code to push the contents of that field onto the stack.
- Throws:
StandardException
-
generateInsertUpdateRow
private void generateInsertUpdateRow(ActivationClassBuilder acb, ResultColumnList selectList, ResultSetNode generatedScan, HalfOuterJoinNode hojn) throws StandardException Generate a method to build a row for the temporary table for INSERT/UPDATE actions. The method stuffs each column in the row with the result of the corresponding expression built out of columns in the current row of the driving left join. The method returns the stuffed row.
- Throws:
StandardException
-
adjustMatchingRefinement
private void adjustMatchingRefinement(ResultColumnList selectList, ResultSetNode generatedScan) throws StandardException Point the column references in the matching refinement at the corresponding columns returned by the driving left join.
- Throws:
StandardException
-
adjustThenColumns
private void adjustThenColumns(ResultColumnList selectList, ResultSetNode generatedScan, HalfOuterJoinNode hojn) throws StandardException Point the column references in the temporary row at the corresponding columns returned by the driving left join.
- Throws:
StandardException
-
useGeneratedScan
private void useGeneratedScan(ResultColumnList selectList, ResultSetNode generatedScan, QueryTreeNode node) throws StandardException Point a node's ColumnReferences into the row returned by the driving left join.
- Throws:
StandardException
-
getSelectListOffset
private int getSelectListOffset(ResultColumnList selectList, ValueNode thenExpression) throws StandardException Find a column reference in the SELECT list of the driving left join and return its 1-based offset into that list. Returns -1 if the column can't be found.
- Throws:
StandardException
-
getMergeTableID
Find the MERGE table id of the indicated column -
acceptChildren
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classQueryTreeNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-
printSubNodes
void printSubNodes(int depth) Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.- Overrides:
printSubNodes
in classQueryTreeNode
- Parameters:
depth
- The depth of this node in the tree
-
toString
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.- Overrides:
toString
in classQueryTreeNode
- Returns:
- This object as a String
-
getColumnReferences
private List<ColumnReference> getColumnReferences(QueryTreeNode expression) throws StandardException Get a list of column references in an expression- Throws:
StandardException
-
isRowLocation
Return true if the ResultColumn represents a RowLocation- Throws:
StandardException
-
referencesSessionSchema
Description copied from class:QueryTreeNode
Return true if the node references SESSION schema tables (temporary or permanent)- Overrides:
referencesSessionSchema
in classQueryTreeNode
- Returns:
- true if references SESSION schema tables, else false
- Throws:
StandardException
- Thrown on error
-
referencesSessionSchema
- Throws:
StandardException
-