Class InsertResultSet
- java.lang.Object
-
- org.apache.derby.impl.sql.execute.NoRowsResultSetImpl
-
- org.apache.derby.impl.sql.execute.DMLWriteResultSet
-
- org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet
-
- org.apache.derby.impl.sql.execute.InsertResultSet
-
- All Implemented Interfaces:
TargetResultSet
,ResultSet
class InsertResultSet extends DMLWriteGeneratedColumnsResultSet implements TargetResultSet
Insert the rows from the source into the specified base table. This will cause constraints to be checked and triggers to be executed based on the c's and t's compiled into the insert plan.
-
-
Field Summary
-
Fields inherited from class org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet
aiCache, autoGeneratedKeysColumnIndexes, autoGeneratedKeysResultSet, autoGeneratedKeysRowsHolder, autoincrementGenerated, identitySequenceUUIDString, identityVal, setIdentity, sourceResultSet
-
Fields inherited from class org.apache.derby.impl.sql.execute.DMLWriteResultSet
baseRowReadMap, cachedDestinations, constantAction, heapDCOCI, indexDCOCIs, resultDescription, rowCount, streamStorableHeapColIds
-
Fields inherited from class org.apache.derby.impl.sql.execute.NoRowsResultSetImpl
activation, beginExecutionTime, beginTime, endExecutionTime, endTime, lcc
-
Fields inherited from interface org.apache.derby.iapi.sql.ResultSet
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST
-
-
Constructor Summary
Constructors Constructor Description InsertResultSet(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, java.lang.String schemaName, java.lang.String tableName, Activation activation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
bulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom)
private void
bulkValidateForeignKeys(TransactionController tc, ContextManager cm, ExecRow fullTemplate)
Bulk Referential Integrity Checkerprivate void
bulkValidateForeignKeysCore(TransactionController tc, ContextManager cm, FKInfo fkInfo, long fkConglom, long pkConglom, java.lang.String fkConstraintName, ExecRow fullTemplate)
void
changedRow(ExecRow execRow, RowLocation rowLocation)
Pass a changed row and the row location for that row to the target result set.void
cleanUp()
Tells the system to clean up on an error.void
close()
Clean up resources and call close on data members.private void
emptyIndexes(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate)
Empty the indexes after doing a bulk insert replace where the table has 0 rows after the replace.private boolean
evaluateCheckConstraints()
Run the check constraints against the current row.void
finish()
Tells the system that there will be no more access to any database information via this result set; in particular, no more calls to open().private int[]
generatedColumnPositionsArray()
If user didn't provide columns list for auto-generated columns, then only include columns with auto-generated values in the resultset.private java.lang.String[]
getColumnNames(int[] baseColumnPositions)
private boolean
getExclusiveTableLock()
Get an exclusive table lock on the target table (and check to see if the table is populated if this is not a bulk insert replace).protected ExecRow
getNextRowCore(NoPutResultSet source)
Get next row from the source result set.private void
getOldStyleBulkInsertValue(int index, long increment)
Identity generation logic for bulk-insert used in pre-10.11 databases.private NumberDataValue
getOldStyleIdentityValue(int index)
Identity generation logic used in pre-10.11 databases.NumberDataValue
getSetAutoincrementValue(int columnPosition, long increment)
getSetAutoincrementValue will get the autoincrement value of the columnPosition specified for the target table.private BulkTableScanResultSet
getTableScanResultSet(long conglomId)
Get me a table scan result set, preferably a bulk table scan, thank you.protected void
initializeAIcache(RowLocation[] rla)
private boolean
isSingleRowResultSet()
private boolean
isSourceRowResultSet()
private ExecRow
makeIndexTemplate(FKInfo fkInfo, ExecRow fullTemplate, ContextManager cm)
Make a template row with the correct columns.private void
normalInsertCore(LanguageConnectionContext lcc, boolean firstExecute)
void
offendingRowLocation(RowLocation rl, long constainerId)
void
open()
Needs to be called before the result set will do anything.ExecRow
preprocessSourceRow(ExecRow execRow)
Preprocess the source row.private ExecRow
processMergeRow(NoPutResultSet sourceRS, ExecRow row)
Special handling if this is an INSERT action of a MERGE statement.void
rememberConstraint(UUID cid)
private void
setEstimatedRowCount(long heapConglom)
Set the estimated row count for this table.private void
setUpAllSorts(ExecRow sourceRow, RowLocation rl)
Set up to update all of the indexes on a table when doing a bulk insert on an empty table.private void
updateAllIndexes(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate)
Update all of the indexes on a table when doing a bulk insert on an empty table.protected boolean
verifyBulkInsert()
Verify that bulkInsert is allowed on this table.-
Methods inherited from class org.apache.derby.impl.sql.execute.DMLWriteGeneratedColumnsResultSet
firstExecuteSpecialHandlingAutoGen, getAutoGeneratedKeysResultset, getCompactRow, saveAIcacheInformation, verifyAutoGeneratedRScolumnsList
-
Methods inherited from class org.apache.derby.impl.sql.execute.DMLWriteResultSet
decodeLockMode, getIndexNameFromCID, getResultDescription, makeDeferredSparseRow, modifiedRowCount, normalizeRow
-
Methods inherited from class org.apache.derby.impl.sql.execute.NoRowsResultSetImpl
addWarning, checkRowPosition, clearCurrentRow, close, doesCommit, evaluateGenerationClauses, getAbsoluteRow, getActivation, getBeginExecutionTimestamp, getCurrentTimeMillis, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getQueryPlanText, getRelativeRow, getRowNumber, getSubqueryTrackingArray, getTimeSpent, getWarnings, isClosed, returnsRows, setAfterLastRow, setBeforeFirstRow, setup, toXML
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.derby.iapi.sql.ResultSet
addWarning, checkRowPosition, clearCurrentRow, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getRelativeRow, getResultDescription, getRowNumber, getSubqueryTrackingArray, getTimeSpent, getWarnings, isClosed, modifiedRowCount, returnsRows, setAfterLastRow, setBeforeFirstRow, toXML
-
-
-
-
Field Detail
-
savedSource
NoPutResultSet savedSource
-
constants
InsertConstantAction constants
-
generationClauses
private GeneratedMethod generationClauses
-
checkGM
private GeneratedMethod checkGM
-
heapConglom
private long heapConglom
-
rowChanger
private RowChanger rowChanger
-
tc
private TransactionController tc
-
row
private ExecRow row
-
userSpecifiedBulkInsert
boolean userSpecifiedBulkInsert
-
bulkInsertPerformed
boolean bulkInsertPerformed
-
bulkInsert
protected boolean bulkInsert
-
bulkInsertReplace
private boolean bulkInsertReplace
-
firstRow
private boolean firstRow
-
needToDropSort
private boolean[] needToDropSort
-
indexConversionTable
private java.util.Hashtable<java.lang.Long,java.lang.Long> indexConversionTable
-
indexedCols
private FormatableBitSet indexedCols
-
bulkHeapCC
private ConglomerateController bulkHeapCC
-
dd
protected DataDictionary dd
-
td
protected TableDescriptor td
-
indexRows
private ExecIndexRow[] indexRows
-
fullTemplateId
private final int fullTemplateId
-
schemaName
private final java.lang.String schemaName
-
tableName
private final java.lang.String tableName
-
sortIds
private long[] sortIds
-
rowSources
private RowLocationRetRowSource[] rowSources
-
bulkHeapSC
private ScanController bulkHeapSC
-
ordering
private ColumnOrdering[][] ordering
-
collation
private int[][] collation
-
sorters
private SortController[] sorters
-
rowHolder
private TemporaryRowHolderImpl rowHolder
-
rl
private RowLocation rl
-
hasBeforeRowTrigger
private boolean hasBeforeRowTrigger
-
tableScan
private BulkTableScanResultSet tableScan
-
numOpens
private int numOpens
-
firstExecute
private boolean firstExecute
-
fkInfoArray
private FKInfo[] fkInfoArray
-
triggerInfo
private TriggerInfo triggerInfo
-
fkChecker
private RISetChecker fkChecker
-
triggerActivator
private TriggerEventActivator triggerActivator
-
bulkInsertCounters
private BulkInsertCounter[] bulkInsertCounters
-
deferredChecks
private BackingStoreHashtable deferredChecks
-
violatingCheckConstraints
private java.util.List<UUID> violatingCheckConstraints
-
-
Constructor Detail
-
InsertResultSet
InsertResultSet(NoPutResultSet source, GeneratedMethod generationClauses, GeneratedMethod checkGM, int fullTemplate, java.lang.String schemaName, java.lang.String tableName, Activation activation) throws StandardException
- Throws:
StandardException
- Thrown on error
-
-
Method Detail
-
changedRow
public void changedRow(ExecRow execRow, RowLocation rowLocation) throws StandardException
Description copied from interface:TargetResultSet
Pass a changed row and the row location for that row to the target result set.- Specified by:
changedRow
in interfaceTargetResultSet
- Parameters:
execRow
- The changed row.rowLocation
- The row location of the row.- Throws:
StandardException
- thrown if cursor finish ed.- See Also:
TargetResultSet.changedRow(org.apache.derby.iapi.sql.execute.ExecRow, org.apache.derby.iapi.types.RowLocation)
-
preprocessSourceRow
public ExecRow preprocessSourceRow(ExecRow execRow) throws StandardException
Preprocess the source row. Apply any check constraints here. Do an inplace cloning of all key columns. For triggers, if we have a before row trigger, we fire it here if we can. This is useful for bulk insert where the store stands between the source and us.- Specified by:
preprocessSourceRow
in interfaceTargetResultSet
- Parameters:
execRow
- The source row.- Returns:
- The preprocessed source row.
- Throws:
StandardException
- thrown on error
-
offendingRowLocation
public void offendingRowLocation(RowLocation rl, long constainerId) throws StandardException
- Specified by:
offendingRowLocation
in interfaceTargetResultSet
- Throws:
StandardException
-
evaluateCheckConstraints
private boolean evaluateCheckConstraints() throws StandardException
Run the check constraints against the current row. Raise an error if a check constraint is violated, unless all the offending checks are deferred, in which case a false value will be returned. A NULL value will be interpreted as success (not violation).- Throws:
StandardException
- thrown on error
-
open
public void open() throws StandardException
Description copied from interface:ResultSet
Needs to be called before the result set will do anything. Need to call before getNextRow(), or for a result set that doesn't return rows, this is the call that will cause all the work to be done.- Specified by:
open
in interfaceResultSet
- Throws:
StandardException
- Standard Derby error policy
-
close
public void close() throws StandardException
Clean up resources and call close on data members.- Specified by:
close
in interfaceResultSet
- Throws:
StandardException
- Thrown on error.
-
generatedColumnPositionsArray
private int[] generatedColumnPositionsArray() throws StandardException
If user didn't provide columns list for auto-generated columns, then only include columns with auto-generated values in the resultset. Those columns would be ones with default value defined.- Throws:
StandardException
-
getSetAutoincrementValue
public NumberDataValue getSetAutoincrementValue(int columnPosition, long increment) throws StandardException
getSetAutoincrementValue will get the autoincrement value of the columnPosition specified for the target table. If increment is non-zero we will also update the autoincrement value.- Overrides:
getSetAutoincrementValue
in classDMLWriteGeneratedColumnsResultSet
- Parameters:
columnPosition
- position of the column in the table (1-based)increment
- amount of increment.- Throws:
StandardException
- if anything goes wrong.
-
getOldStyleBulkInsertValue
private void getOldStyleBulkInsertValue(int index, long increment) throws StandardException
Identity generation logic for bulk-insert used in pre-10.11 databases.- Parameters:
index
- 0-based index into aiCache- Throws:
StandardException
-
getOldStyleIdentityValue
private NumberDataValue getOldStyleIdentityValue(int index) throws StandardException
Identity generation logic used in pre-10.11 databases.- Parameters:
index
- 0-based index into aiCache- Throws:
StandardException
-
isSourceRowResultSet
private boolean isSourceRowResultSet()
-
isSingleRowResultSet
private boolean isSingleRowResultSet()
-
normalInsertCore
private void normalInsertCore(LanguageConnectionContext lcc, boolean firstExecute) throws StandardException
- Throws:
StandardException
-
getNextRowCore
protected ExecRow getNextRowCore(NoPutResultSet source) throws StandardException
Description copied from class:DMLWriteResultSet
Get next row from the source result set.- Overrides:
getNextRowCore
in classDMLWriteResultSet
- Parameters:
source
- SourceResultSet Also look at Track#2432/change 12433- Returns:
- The next row in the result set
- Throws:
StandardException
- Standard error policy
-
processMergeRow
private ExecRow processMergeRow(NoPutResultSet sourceRS, ExecRow row) throws StandardException
Special handling if this is an INSERT action of a MERGE statement.
- Throws:
StandardException
-
bulkInsertCore
private void bulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom) throws StandardException
- Throws:
StandardException
-
bulkValidateForeignKeys
private void bulkValidateForeignKeys(TransactionController tc, ContextManager cm, ExecRow fullTemplate) throws StandardException
Bulk Referential Integrity Checker- Throws:
StandardException
-
bulkValidateForeignKeysCore
private void bulkValidateForeignKeysCore(TransactionController tc, ContextManager cm, FKInfo fkInfo, long fkConglom, long pkConglom, java.lang.String fkConstraintName, ExecRow fullTemplate) throws StandardException
- Throws:
StandardException
-
makeIndexTemplate
private ExecRow makeIndexTemplate(FKInfo fkInfo, ExecRow fullTemplate, ContextManager cm) throws StandardException
Make a template row with the correct columns.- Throws:
StandardException
-
setUpAllSorts
private void setUpAllSorts(ExecRow sourceRow, RowLocation rl) throws StandardException
Set up to update all of the indexes on a table when doing a bulk insert on an empty table.- Throws:
StandardException
- thrown on error
-
updateAllIndexes
private void updateAllIndexes(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate) throws StandardException
Update all of the indexes on a table when doing a bulk insert on an empty table.- Throws:
StandardException
- thrown on error
-
cleanUp
public void cleanUp() throws StandardException
Description copied from interface:ResultSet
Tells the system to clean up on an error.- Specified by:
cleanUp
in interfaceResultSet
- Throws:
StandardException
- Thrown on error- See Also:
ResultSet.cleanUp()
-
verifyBulkInsert
protected boolean verifyBulkInsert() throws StandardException
Verify that bulkInsert is allowed on this table. The execution time check to see if bulkInsert is allowed simply consists of checking to see if this is not a deferred mode insert and that the table is empty if this is not replace. A side effect of calling this method is to get an exclusive table lock on the table.- Returns:
- Whether or not bulkInsert is allowed on this table.
- Throws:
StandardException
- Thrown on error
-
getExclusiveTableLock
private boolean getExclusiveTableLock() throws StandardException
Get an exclusive table lock on the target table (and check to see if the table is populated if this is not a bulk insert replace).- Returns:
- Whether or not bulkInsert is allowed on this table.
- Throws:
StandardException
- Thrown on error
-
setEstimatedRowCount
private void setEstimatedRowCount(long heapConglom) throws StandardException
Set the estimated row count for this table.- Parameters:
heapConglom
- Conglomerate number for the heap- Throws:
StandardException
- Thrown on failure
-
emptyIndexes
private void emptyIndexes(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate) throws StandardException
Empty the indexes after doing a bulk insert replace where the table has 0 rows after the replace. RESOLVE: This method is ugly! Prior to 2.0, we simply scanned back across the table to build the indexes. We changed this in 2.0 to populate the sorters via a call back as we populated the table. Doing a 0 row replace into a table with indexes is a degenerate case, hence we allow ugly and unoptimized code.- Throws:
StandardException
- Thrown on failure
-
getTableScanResultSet
private BulkTableScanResultSet getTableScanResultSet(long conglomId) throws StandardException
Get me a table scan result set, preferably a bulk table scan, thank you. If we already have one, reopen it.- Throws:
StandardException
-
getColumnNames
private java.lang.String[] getColumnNames(int[] baseColumnPositions)
-
finish
public void finish() throws StandardException
Description copied from interface:ResultSet
Tells the system that there will be no more access to any database information via this result set; in particular, no more calls to open(). Will close the result set if it is not already closed.- Specified by:
finish
in interfaceResultSet
- Overrides:
finish
in classNoRowsResultSetImpl
- Throws:
StandardException
- on error
-
rememberConstraint
public void rememberConstraint(UUID cid) throws StandardException
- Overrides:
rememberConstraint
in classDMLWriteResultSet
- Throws:
StandardException
-
initializeAIcache
protected void initializeAIcache(RowLocation[] rla) throws StandardException
- Throws:
StandardException
-
-