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

public final Class InsertNode

extends DMLModGeneratedColumnsStatementNode
Class Inheritance
Imports
java.util.Properties, org.apache.derby.catalog.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.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.StatementType, org.apache.derby.iapi.sql.compile.CompilerContext, .IgnoreFilter, .Visitor, org.apache.derby.iapi.sql.conn.Authorizer, org.apache.derby.iapi.sql.dictionary.ColumnDescriptor, .ColumnDescriptorList, .ConglomerateDescriptor, .DataDictionary, .IndexLister, .TableDescriptor, org.apache.derby.iapi.sql.execute.ConstantAction, .ExecRowBuilder, org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo, .TransactionController, org.apache.derby.iapi.util.StringUtil, org.apache.derby.impl.sql.execute.FKInfo, org.apache.derby.vti.DeferModification

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

Modifier and TypeField and Description
public boolean
protected boolean
private boolean
public ValueNode
private boolean
private ValueNode
public FKInfo
public boolean
private boolean
private ValueNode
private OrderByList
private ResultColumnList
public Properties
Inherited from org.apache.derby.impl.sql.compile.DMLModGeneratedColumnsStatementNode:
autoincRowLocationidentitySequenceUUIDString

Constructor Summary

AccessConstructor and Description
pack-priv
InsertNode(QueryTreeNode
The name of the table/VTI to insert into
targetName
,
ResultColumnList
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.
insertColumns
,
ResultSetNode
The query expression that will generate the rows to insert into the given table
queryExpression
,
MatchingClauseNode
Non-null if this DML is part of a MATCHED clause of a MERGE statement.
matchingClause
,
Properties
The properties specified on the target table
targetProperties
,
OrderByList
The order by list for the source result set, null if no order by list
orderByList
,
ValueNode
The value of a if present
offset
,
ValueNode
The value of a if present
fetchFirst
,
boolean
True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntax
hasJDBClimitClause
,
ContextManager
The context manager
cm
)

Constructor for an InsertNode.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

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

Accept the visitor for all visitable children of this node.

public void
pack-priv ResultSetNode

Returns:

a node representing the source for the insert
enhanceAndCheckForAutoincrement
(ResultSetNode
current node in the result set tree
resultSet
,
boolean
FALSE if the column list needs reordering
inOrder
,
int[]
correspondence between RCLs
colMap
,
boolean
true if DEFAULT clauses were replaced with generated expressions
defaultsWereReplaced
)

Process ResultSet column lists for projection and autoincrement.

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 insert creates an expression for: ResultSetFactory.getInsertResultSet(resultSet.generate(ps), generationClausesResult, checkConstrainResult, this )

private void
getAffectedIndexes(TableDescriptor
TableDescriptor for the table being inserted into or deleted from
td
)

Get the list of indexes on the table being inserted into.

pack-priv boolean[]

Returns:

A boolean[] to track the (0-based) columns which are indexed.
getIndexedCols
()

Create a boolean[] to track the (0-based) columns which are indexed.

pack-priv int
getPrivType()

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

Return default privilege needed for this node.

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 int

Returns:

the type of statement
getStatementType
(Properties targetProperties)

Return the statement type, where it is dependent on the targetProperties.

public ConstantAction
makeConstantAction()

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

Compile constants that Execution will use

public void
optimizeStatement()

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

Generate an optimized QueryTree from a bound QueryTree.

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)

private void
requestBulkInsert()

Request bulk insert optimization at run time.

pack-priv String
public String

Returns:

This object as a String
toString
()

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

Convert this object to a String.

private boolean

Returns:

Whether or not bulkInsert is allowed.
verifyBulkInsert
(DataDictionary
The DataDictionary
dd
,
String
The insert mode
mode
)

Do the bind time checks to see if bulkInsert is allowed on this table.

private void
verifyTargetProperties(DataDictionary
The DataDictionary
dd
)

Verify that the target properties that we are interested in all hold valid values.

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

Field Detail

autoincrementColumnSetToDEFAULTback to summary
public boolean autoincrementColumnSetToDEFAULT
bulkInsertback to summary
protected boolean bulkInsert
bulkInsertReplaceback to summary
private boolean bulkInsertReplace
checkConstraintsback to summary
public ValueNode checkConstraints

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

deferredback to summary
private boolean deferred
fetchFirstback to summary
private ValueNode fetchFirst
fkInfoback to summary
public FKInfo fkInfo

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

hasDeferrableCheckConstraintsback to summary
public boolean hasDeferrableCheckConstraints
hasJDBClimitClauseback to summary
private boolean hasJDBClimitClause
offsetback to summary
private ValueNode offset
orderByListback to summary
private OrderByList orderByList
targetColumnListback to summary
private ResultColumnList targetColumnList
targetPropertiesback to summary
public Properties targetProperties

Constructor Detail

InsertNodeback to summary
pack-priv InsertNode(QueryTreeNode targetName, ResultColumnList insertColumns, ResultSetNode queryExpression, MatchingClauseNode matchingClause, Properties targetProperties, OrderByList orderByList, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, ContextManager cm)

Constructor for an InsertNode.

Parameters
targetName:QueryTreeNode

The name of the table/VTI to insert into

insertColumns:ResultColumnList

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:ResultSetNode

The query expression that will generate the rows to insert into the given table

matchingClause:MatchingClauseNode

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

targetProperties:Properties

The properties specified on the target table

orderByList:OrderByList

The order by list for the source result set, null if no order by list

offset:ValueNode

The value of a if present

fetchFirst:ValueNode

The value of a if present

hasJDBClimitClause:boolean

True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntax

cm:ContextManager

The context manager

Method Detail

acceptChildrenback to summary
pack-priv void acceptChildren(Visitor v) throws StandardException

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

Accept the visitor for all visitable children of this node.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on error
bindStatementback to summary
public void bindStatement() throws StandardException

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

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.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
enhanceAndCheckForAutoincrementback to summary
pack-priv 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:ResultSetNode

current node in the result set tree

inOrder:boolean

FALSE if the column list needs reordering

colMap:int[]

correspondence between RCLs

defaultsWereReplaced:boolean

true if DEFAULT clauses were replaced with generated expressions

Returns:ResultSetNode

a node representing the source for the insert

Exceptions
StandardException:
Thrown 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 insert creates an expression for: ResultSetFactory.getInsertResultSet(resultSet.generate(ps), generationClausesResult, checkConstrainResult, this )

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
getAffectedIndexesback to summary
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

TableDescriptor for the table being inserted into or deleted from

Exceptions
StandardException:
Thrown on error
getIndexedColsback to summary
pack-priv boolean[] getIndexedCols() throws StandardException

Create a boolean[] to track the (0-based) columns which are indexed.

Returns:boolean[]

A boolean[] to track the (0-based) columns which are indexed.

Exceptions
StandardException:
Thrown on failure
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
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
getStatementTypeback to summary
pack-priv static int getStatementType(Properties targetProperties)

Return the statement type, where it is dependent on the targetProperties. (insertMode = replace causes statement type to be BULK_INSERT_REPLACE.

Returns:int

the type of statement

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
optimizeStatementback to summary
public void optimizeStatement() throws StandardException

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

Doc from org.apache.derby.impl.sql.compile.DMLModStatementNode.optimizeStatement.

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.

Annotations
@Override
Exceptions
StandardException:
Thrown on failure
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
requestBulkInsertback to summary
private void requestBulkInsert()

Request bulk insert optimization at run time.

statementToStringback to summary
pack-priv String statementToString()

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

Annotations
@Override
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
verifyBulkInsertback to summary
private boolean verifyBulkInsert(DataDictionary dd, 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:DataDictionary

The DataDictionary

mode:String

The insert mode

Returns:boolean

Whether or not bulkInsert is allowed.

Exceptions
StandardException:
Thrown on error
verifyTargetPropertiesback to summary
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:DataDictionary

The DataDictionary

Exceptions
StandardException:
Thrown on error