Class InsertNode
- java.lang.Object
-
- All Implemented Interfaces:
Visitable
public final class InsertNode extends DMLModGeneratedColumnsStatementNode
An InsertNode is the top node in a query tree for an insert statement.After parsing, the node contains targetTableName: the target table for the insert collist: a list of column names, if specified queryexpr: the expression being inserted, either a values clause or a select form; both of these are represented via the SelectNode, potentially with a TableOperatorNode such as UnionNode above it.
After binding, the node has had the target table's descriptor located and inserted, and the queryexpr and collist have been massaged so that they are identical to the table layout. This involves adding any default values for missing columns, and reordering the columns to match the table's ordering of them.
After optimizing, ...
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
bulkInsert
private boolean
bulkInsertReplace
ValueNode
checkConstraints
private boolean
deferred
private ValueNode
fetchFirst
FKInfo
fkInfo
boolean
hasDeferrableCheckConstraints
private boolean
hasJDBClimitClause
private ValueNode
offset
private OrderByList
orderByList
private ResultColumnList
targetColumnList
java.util.Properties
targetProperties
-
Fields inherited from class org.apache.derby.impl.sql.compile.DMLModGeneratedColumnsStatementNode
autoincRowLocation, identitySequenceUUIDString
-
Fields inherited from class org.apache.derby.impl.sql.compile.DMLModStatementNode
dependentTables, fkColArrays, fkColDescriptors, fkIndexConglomNumbers, fkRefActions, fkSchemaNames, fkTableNames, indexConglomerateNumbers, indexNames, indicesToMaintain, isDependentTable, lockMode, matchingClause, relevantCdl, relevantTriggers, resultColumnList, synonymTableName, targetTableDescriptor, targetTableName, targetVTI, triggerInfo
-
Fields inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
resultSet
-
Fields inherited from class org.apache.derby.impl.sql.compile.StatementNode
EMPTY_TD_LIST, NEED_CURSOR_ACTIVATION, NEED_DDL_ACTIVATION, NEED_NOTHING_ACTIVATION, NEED_PARAM_ACTIVATION, NEED_ROW_ACTIVATION
-
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
Constructors Constructor Description InsertNode(QueryTreeNode targetName, ResultColumnList insertColumns, ResultSetNode queryExpression, MatchingClauseNode matchingClause, java.util.Properties targetProperties, OrderByList orderByList, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, ContextManager cm)
Constructor for an InsertNode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
acceptChildren(Visitor v)
Accept the visitor for all visitable children of this node.void
bindStatement()
Bind this InsertNode.(package private) ResultSetNode
enhanceAndCheckForAutoincrement(ResultSetNode resultSet, boolean inOrder, int[] colMap, boolean defaultsWereReplaced)
Process ResultSet column lists for projection and autoincrement.(package private) void
generate(ActivationClassBuilder acb, MethodBuilder mb)
Code generation for insert creates an expression for: ResultSetFactory.getInsertResultSet(resultSet.generate(ps), generationClausesResult, checkConstrainResult, this )private void
getAffectedIndexes(TableDescriptor td)
Get the list of indexes on the table being inserted into.(package private) boolean[]
getIndexedCols()
Create a boolean[] to track the (0-based) columns which are indexed.(package private) int
getPrivType()
Return default privilege needed for this node.protected int
getStatementType()
Return the type of statement, something from StatementType.(package private) static int
getStatementType(java.util.Properties targetProperties)
Return the statement type, where it is dependent on the targetProperties.ConstantAction
makeConstantAction()
Compile constants that Execution will usevoid
optimizeStatement()
Generate an optimized QueryTree from a bound QueryTree.(package private) void
printSubNodes(int depth)
Prints the sub-nodes of this object.boolean
referencesSessionSchema()
Return true if the node references SESSION schema tables (temporary or permanent)private void
requestBulkInsert()
Request bulk insert optimization at run time.(package private) java.lang.String
statementToString()
java.lang.String
toString()
Convert this object to a String.private boolean
verifyBulkInsert(DataDictionary dd, java.lang.String mode)
Do the bind time checks to see if bulkInsert is allowed on this table.private void
verifyTargetProperties(DataDictionary dd)
Verify that the target properties that we are interested in all hold valid values.-
Methods inherited from class org.apache.derby.impl.sql.compile.DMLModGeneratedColumnsStatementNode
getUUIDofSequenceGenerator
-
Methods inherited from class org.apache.derby.impl.sql.compile.DMLModStatementNode
adjustDeferredFlag, bindConstraints, bindRowScopedExpression, generateCheckConstraints, generateCheckConstraints, generateCodeForTemporaryTable, generateGenerationClauses, getAffectedIndexes, getAllRelevantConstraints, getAllRelevantTriggers, getCheckConstraints, getFKInfo, getReadColMap, getResultColumnList, getResultColumnList, getSchemaDescriptor, getTriggerInfo, getXAffectedIndexes, hasCheckConstraints, hasGenerationClauses, inMatchingClause, isAtomic, markAffectedIndexes, normalizeSynonymColumns, parseAndBindGenerationClauses, parseCheckConstraint, parseGenerationClause, requiresDeferredProcessing, setRefActionInfo, setTarget, verifyTargetTable
-
Methods inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
activationKind, bind, bindExpressions, bindExpressionsWithTables, bindResultSetsWithTables, bindTables, generateParameterValueSet, getResultSetNode, makeResultDescription
-
Methods inherited from class org.apache.derby.impl.sql.compile.StatementNode
executeSchemaName, executeStatementName, generate, getCursorInfo, getSPSName, lockTableForCompilation, needsSavepoint, updateIndexStatisticsFor
-
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, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getTableDescriptor, getTypeCompiler, getUDTDesc, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setEndOffset, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
-
-
-
Field Detail
-
targetColumnList
private ResultColumnList targetColumnList
-
deferred
private boolean deferred
-
checkConstraints
public ValueNode checkConstraints
-
hasDeferrableCheckConstraints
public boolean hasDeferrableCheckConstraints
-
targetProperties
public java.util.Properties targetProperties
-
fkInfo
public FKInfo fkInfo
-
bulkInsert
protected boolean bulkInsert
-
bulkInsertReplace
private boolean bulkInsertReplace
-
orderByList
private OrderByList orderByList
-
offset
private ValueNode offset
-
fetchFirst
private ValueNode fetchFirst
-
hasJDBClimitClause
private boolean hasJDBClimitClause
-
-
Constructor Detail
-
InsertNode
InsertNode(QueryTreeNode targetName, ResultColumnList insertColumns, ResultSetNode queryExpression, MatchingClauseNode matchingClause, java.util.Properties targetProperties, OrderByList orderByList, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, ContextManager cm)
Constructor for an InsertNode.- Parameters:
targetName
- The name of the table/VTI to insert intoinsertColumns
- A ResultColumnList with the names of the columns to insert into. May be null if the user did not specify the columns - in this case, the binding phase will have to figure it out.queryExpression
- The query expression that will generate the rows to insert into the given tablematchingClause
- Non-null if this DML is part of a MATCHED clause of a MERGE statement.targetProperties
- The properties specified on the target tableorderByList
- The order by list for the source result set, null if no order by listoffset
- The value of aif present fetchFirst
- The value of aif present hasJDBClimitClause
- True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntaxcm
- The context manager
-
-
Method Detail
-
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 classStatementNode
- Returns:
- This object as a String
-
statementToString
java.lang.String statementToString()
- Overrides:
statementToString
in classDMLModStatementNode
-
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 classDMLModStatementNode
- Parameters:
depth
- The depth of this node in the tree
-
bindStatement
public void bindStatement() throws StandardException
Bind this InsertNode. 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 insert will also massage the tree so that the collist and select column order/number are the same as the layout of the table in the store.
- Overrides:
bindStatement
in classStatementNode
- Throws:
StandardException
- Thrown on error
-
enhanceAndCheckForAutoincrement
ResultSetNode enhanceAndCheckForAutoincrement(ResultSetNode resultSet, boolean inOrder, int[] colMap, boolean defaultsWereReplaced) throws StandardException
Process ResultSet column lists for projection and autoincrement. This method recursively descends the result set node tree. When it finds a simple result set, it processes any autoincrement columns in that rs by calling checkAutoIncrement. When it finds a compound result set, like a Union or a PRN, it recursively descends to the child(ren) nodes. Union nodes can arise due to multi-rows in VALUES clause), PRN nodes can arise when the set of columns being inserted is a subset of the set of columns in the table. In addition to checking for autoincrement columns in the result set, we may need to enhance and re-order the column list to match the column list of the table we are inserting into. This work is handled by ResultsetNode.enhanceRCLForInsert. Note that, at the leaf level, we need to enhance the RCL first, then check for autoincrement columns. At the non-leaf levels, we have to enhance the RCL, but we don't have to check for autoincrement columns, since they only occur at the leaf level. This way, all ColumnDescriptor of all rows will be set properly.- Parameters:
resultSet
- current node in the result set treeinOrder
- FALSE if the column list needs reorderingcolMap
- correspondence between RCLsdefaultsWereReplaced
- true if DEFAULT clauses were replaced with generated expressions- Returns:
- a node representing the source for the insert
- Throws:
StandardException
- Thrown on error
-
getPrivType
int getPrivType()
Description copied from class:DMLStatementNode
Return default privilege needed for this node. Other DML nodes can override this method to set their own default privilege.- Overrides:
getPrivType
in classDMLStatementNode
- Returns:
- true if the statement is atomic
-
referencesSessionSchema
public boolean referencesSessionSchema() throws StandardException
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
-
verifyTargetProperties
private void verifyTargetProperties(DataDictionary dd) throws StandardException
Verify that the target properties that we are interested in all hold valid values. NOTE: Any target property which is valid but cannot be supported due to a target database, etc. will be turned off quietly.- Parameters:
dd
- The DataDictionary- Throws:
StandardException
- Thrown on error
-
verifyBulkInsert
private boolean verifyBulkInsert(DataDictionary dd, java.lang.String mode) throws StandardException
Do the bind time checks to see if bulkInsert is allowed on this table. bulkInsert is disallowed at bind time for: o target databases o (tables with triggers?) (It is disallowed at execution time if the table has at least 1 row in it or if it is a deferred mode insert.)- Parameters:
dd
- The DataDictionarymode
- The insert mode- Returns:
- Whether or not bulkInsert is allowed.
- Throws:
StandardException
- Thrown on error
-
makeConstantAction
public ConstantAction makeConstantAction() throws StandardException
Compile constants that Execution will use- Overrides:
makeConstantAction
in classQueryTreeNode
- Throws:
StandardException
- Thrown on failure
-
getIndexedCols
boolean[] getIndexedCols() throws StandardException
Create a boolean[] to track the (0-based) columns which are indexed.- Returns:
- A boolean[] to track the (0-based) columns which are indexed.
- Throws:
StandardException
- Thrown on failure
-
optimizeStatement
public void optimizeStatement() throws StandardException
Generate an optimized QueryTree from a bound QueryTree. Actually, it can annotate the tree in place rather than generate a new tree, but this interface allows the root node of the optimized QueryTree to be different from the root node of the bound QueryTree. For non-optimizable statements, this method is a no-op. Throws an exception if the tree is not bound, or if the binding is out of date.Remove any duplicate ORDER BY columns and push an ORDER BY if present down to the source result set, before calling super.optimizeStatement.
- Overrides:
optimizeStatement
in classDMLModStatementNode
- Throws:
StandardException
- Thrown on failure
-
requestBulkInsert
private void requestBulkInsert()
Request bulk insert optimization at run time.
-
generate
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
Code generation for insert creates an expression for: ResultSetFactory.getInsertResultSet(resultSet.generate(ps), generationClausesResult, checkConstrainResult, this )- Overrides:
generate
in classQueryTreeNode
- Parameters:
acb
- The ActivationClassBuilder for the class being builtmb
- the method for the execute() method to be built- Throws:
StandardException
- Thrown on error
-
getStatementType
protected final int getStatementType()
Return the type of statement, something from StatementType.- Overrides:
getStatementType
in classQueryTreeNode
- Returns:
- the type of statement
-
getStatementType
static int getStatementType(java.util.Properties targetProperties)
Return the statement type, where it is dependent on the targetProperties. (insertMode = replace causes statement type to be BULK_INSERT_REPLACE.- Returns:
- the type of statement
-
getAffectedIndexes
private void getAffectedIndexes(TableDescriptor td) throws StandardException
Get the list of indexes on the table being inserted into. This is used by INSERT. This is an optimized version of what UPDATE and DELETE use.- Parameters:
td
- TableDescriptor for the table being inserted into or deleted from- Throws:
StandardException
- Thrown on error
-
acceptChildren
void acceptChildren(Visitor v) throws StandardException
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classDMLModStatementNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-
-