[ 
https://issues.apache.org/jira/browse/DERBY-532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13795273#comment-13795273
 ] 

Dag H. Wanvik edited comment on DERBY-532 at 10/15/13 3:08 PM:
---------------------------------------------------------------

This experimental patch enables deferrable constraints for 

{quote}
     a) primary key constraints
     b) unique constraint with not nullable columns
     c) unique constraint with nullable columns
{quote}

by new logic in supporting BTree indexes and sorts.

The patch includes relaxing the constraint at insertion and update time, as 
well as adding a constraint to an existing table. There is as yet no support 
for importing data into a table with a deferred constraint, cf. the issue 
DERBY-6374. When that issue is fixed, I'll add support for deferrable 
constraints for import as well.

Derby treats constraints a) and b) the same, and in the code these are marked 
as "unique" when they are not deferrable (as in existing code).

Constraint type c) is currently marked as "uniqueWithDuplicateNulls". 
Insert/update of these is implemented in the BTree by including the RowLocation 
of the base row in the set of keys in the index row (DERBY-3330). This makes 
them trivially unique, but there is an extra code path in BTreeController that 
checks neighbor rows for duplicates, and only allows insertion if the key 
contains a null. When adding a constraint to an existing table, these are 
handled by a specially crafted sorter (UniqueWithDuplicateNullsMergeSort).

The implementation of insert/update of deferrable indexes is based on the same 
approach, i.e. neighbor row comparison and tweaking the sorters. [This means a) 
and b) if deferrable are no longer marked "unique"].

Deferrable indexes are not shared.

If there are duplicates and we have deferred constraint mode (a dynamic session 
property), we save the duplicate index row in a disk based hash table 
(DeferredDuplicates#rememberDuplicate).

For a) and b), constraints which are deferrable are marked as 
"uniqueDeferrable" and "hasDeferrableChecking". Constraints of type c) which 
are deferrable are marked "uniqueWithDuplicateNulls" and 
"hasDeferrableChecking". These marks determines the code paths used. Note that 
existing indexes and non-deferrable constraint do not get a new code path, 
which should preserve correctness and performance of those.

Now, with these markers in place, deferral of checks happens in logic in two 
places:
{quote}
{{        IndexChanger#insertAndCheckDups + BTreeController#doIns}}

{{and     CreateIndexConstantAction#executeConstantAction +}}
{{        MergeSort#compare and UniqueWithDuplicateNullsMergeSort#compare }}
{quote}

The former is active for deferral under INSERT and UPDATE.  The latter when 
adding a deferrable constraint to an existing table, when we sort existing rows 
detecting any duplicates.

At transaction commit (1), or when the constraint mode for a deferred 
constraint is changed back to immediate (2), we validate the constraint 
(DeferredDuplicates#validate) by replaying the hash table and scanning the 
index for the duplicate index rows to ascertain there are none, or else we have 
an error: transaction or statement severity respectively for (1) and (2).

The constraint mode is a SQL session level variable, and inside routines 
(nested connections), we push this on the stack. This means change of the 
constraint mode inside nested connections will be popped on routine exit. If, 
as part of this, a constraint changes from deferred to immediate mode, we also 
validate it for correctness. If this fail, the transaction rolls back 
(GenericLanguageConnectionContext#popNestedSessionContext calls 
#compareConstraintModes).

#popNestedSessionContext is new: earlier we didn't need a handle for popping 
SQL session context, we needed one in this case, so we implemented the general 
mechanism as well. That hook is called from 
GenericPreparedStatement#executeStmt. As a part of this effort, we also renamed 
#setupNestedSessionContext to #pushNestedSessionContext.

The test case "testBasicDeferral" and "testRoutines" has been added to 
ConstraintCharacteristicsTest to test these basic behaviors.

The "not enforced" feature is not yet implemented in this patch.

Regressions passed OK with this patch.

Patch details:

{color:blue}new file:   
java/engine/org/apache/derby/impl/sql/execute/DeferredDuplicates.java{color}

New static class which handles much of the mechanics of saving duplicate index 
rows and later validating the index.

{color:blue}new file:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2I_10_4.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2I.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2IFactory.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java{color}

The index conglomerate format has been bumped so we can store the deferral 
properties. Upgrade of indexes from old databases is lazy: they are not 
deferrable, but the format just lacks two final properties which default to 
false: hasDeferrableChecking and isUniqueDeferrable. The new format id is 
ACCESS_B2I_V6_ID. The new class B2I_10_4 makes sure we can write old 
conglomerate format correctly in soft upgrade mode (in format ACCESS_B2I_V5_ID).

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java{color}

Added DERBY_STORE_MINOR_VERSION_11 which allows use of the new index 
conglomerate format.

{color:blue}modified:   
java/engine/org/apache/derby/catalog/IndexDescriptor.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/catalog/types/IndexDescriptorImpl.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/dictionary/IndexRowGenerator.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/TableElementList.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/DDLSingleTableConstantAction.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/MaterializedResultSet.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/RIBulkChecker.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/RowChangerImpl.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderImpl.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/BTree.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2IController.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java{color}

Addition/propagation of "hasDeferrableChecking" and "uniqueDeferrable" 
properties and add "deferred=false" argument to ConglomerateController#insert 
calls.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/conn/SQLSessionContext.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/conn/SQLSessionContextImpl.java{color}

Storage of the session's current constraint modes and operations for pushing 
and clearing that information.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj{color}

Add check that we are at dictionary 10_11 before allowing SET CONSTRAINTS to 
proceed. (Already done for deferred constraint creation).

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/ConglomerateController.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/heap/HeapController.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/catalog/TabInfoImpl.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java{color}

Add boolean "deferred" to indicate current behavior to #insert. For 
BTreeController, report back duplicates but still do insert iff deferred mode. 
Ignored by HeapController. The real use of the new argument is by IndexChanger 
which knows about constraints in deferred mode.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java{color}

New default arguments (doesn't use the deferred values).

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/RowUtil.java{color}

Small formatting fix to #toString.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/SortObserver.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/BasicSortObserver.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/UniqueIndexSortObserver.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/UniqueWithDuplicateNullsIndexSortObserver.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/sort/UniqueWithDuplicateNullsMergeSo{color}

Changes to accommodate saving duplicates during sorting of existing rows when 
adding an index for a constraint.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java{color}

Call hook for popNestedSessionContext. Renaming of pushNestedSessionContext.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java{color}

Removed unnecessary overload of IndexRowGenerator (as part of adding more 
arguments anyway).

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/AlterConstraintConstantAction.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java{color}

Addition of dictionary level check + one bug fix.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java{color}

Determine the flags for the index conglomerates to support constraints, see 
introduction, and set up for creation of correct conglomerates.  Handle any 
initial insertion of rows when constraint mode is initially deferred.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java{color}

Partial support (preparatory code) for bulk import [type a) and b)] in the 
presence of deferrable constraints, but see introduction.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/SetConstraintsConstantAction.java{color}

Logic for setting the session's constraint mode at execution time.


{color:blue}modified:   java/engine/org/apache/derby/loc/messages.xml{color}
{color:blue}modified:   
java/shared/org/apache/derby/shared/common/reference/SQLState.java{color}

New error messages. 

{color:blue}modified:   
java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java{color}

Added test cases "testBasicDeferral" and "testRoutines".

{color:blue}modified:   
java/testing/org/apache/derbyTesting/functionTests/util/T_ConsistencyChecker.java{color}
{color:blue}modified:   
java/testing/org/apache/derbyTesting/unitTests/store/T_AccessFactory.java{color}
{color:blue}modified:   
java/testing/org/apache/derbyTesting/unitTests/store/T_QualifierTest.java{color}
{color:blue}modified:   
java/testing/org/apache/derbyTesting/unitTests/store/T_b2i.java{color}

Adjustment of old tests to use deferred=false argument to 
ConglomerateController#insert

{color:blue}modified:   
java/testing/org/apache/derbyTesting/unitTests/store/T_SortController.java{color}

Instantiate sorters with default implementations for the new SortObserver 
interface methods.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java{color}

Import fixes, Javadoc fixes, renaming of pushNestedSessionContext, added new 
interface method: setDeferred, isEffectivelyDeferred, setDeferredAll, 
getDeferredHashTables.

{color:blue}modified:{color}
java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java

Implementations of above. Store "deferredHashTables" for the transaction: the 
set of disk based hash tables that holds deferred rows for the session, if any. 
New logic in doCommit and doRollback to handle deferred rows and reset modes. 
New logic to push constraint modes state on routine invocation in 
pushNestedSessionContext. Added popNestedSessionContext to validate any 
deferred rows if we switch back to immediate checking.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/conn/StatementContext.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/TransactionController.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/ForeignKeyRIChecker.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/GenericRIChecker.java{color}

Javadoc fixes.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java{color}

Javadoc fixes and removal of an assertion that no longer hold with added call 
in GenericPreparedStatement.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/SetConstraintsNode.java{color}

Import fix.

To apply the patch, you need to add empty versions of the two new files:
java/engine/org/apache/derby/impl/sql/execute/DeferredDuplicates.java
java/engine/org/apache/derby/impl/store/access/btree/index/B2I_10_4.java



was (Author: dagw):
This experimental patch enables deferrable constraints for 

{quote}
     a) primary key constraints
     b) unique constraint with not nullable columns
     c) unique constraint with nullable columns
{quote}

by new logic in supporting BTree indexes and sorts.

The patch includes relaxing the constraint at insertion and update time, as 
well as adding a constraint to an existing table. There is as yet no support 
for importing data into a table with a deferred constraint, cf. the issue 
DERBY-6374. When that issue is fixed, I'll add support for deferrable 
constraints for import as well.

Derby treats constraints a) and b) the same, and in the code these are marked 
as "unique" when they are not deferrable (as in existing code).

Constraint type c) is currently marked as "uniqueWithDuplicateNulls". 
Insert/update of these is implemented in the BTree by including the RowLocation 
of the base row in the set of keys in the index row (DERBY-3330). This makes 
them trivially unique, but there is an extra code path in BTreeController that 
checks neighbor rows for duplicates, and only allows insertion if the key 
contains a null. When adding a constraint to an existing table, these are 
handled by a specially crafted sorter (UniqueWithDuplicateNullsMergeSort).

The implementation of insert/update of deferrable indexes is based on the same 
approach, i.e. neighbor row comparison and tweaking the sorters. [This means a) 
and b) if deferrable are no longer marked "unique"].

Deferrable indexes are not shared.

If there are duplicates and we have deferred constraint mode (a dynamic session 
property), we save the duplicate index row in a disk based hash table 
(DeferredDuplicates#rememberDuplicate).

For a) and b), constraints which are deferrable are marked as 
"uniqueDeferrable" and "hasDeferrableChecking". Constraints of type c) which 
are deferrable are marked "uniqueWithDuplicateNulls" and 
"hasDeferrableChecking". These marks determines the code paths used. Note that 
existing indexes and non-deferrable constraint do not get a new code path, 
which should preserve correctness and performance of those.

Now, with these markers in place, deferral of checks happens in logic in two 
places:
{quote}
{{        IndexChanger#insertAndCheckDups + BTreeController#doIns}}

{{and     CreateIndexConstantAction#executeConstantAction +}}
{{        MergeSort#compare and UniqueWithDuplicateNullsMergeSort#compare }}
{quote}

The former is active for deferral under INSERT and UPDATE.  The latter when 
adding a deferrable constraint to an existing table, when we sort existing rows 
detecting any duplicates.

At transaction commit (1), or when the constraint mode for a deferred 
constraint is changed back to immediate (2), we validate the constraint 
(DeferredDuplicates#validate) by replaying the hash table and scanning the 
index for the duplicate index rows to ascertain there are none, or else we have 
an error: transaction or statement severity respectively for (1) and (2).

The constraint mode is a SQL session level variable, and inside routines 
(nested connections), we push this on the stack. This means change of the 
constraint mode inside nested connections will be popped on routine exit. If, 
as part of this, a constraint changes from deferred to immediate mode, we also 
validate it for correctness. If this fail, the transaction rolls back 
(GenericLanguageConnectionContext#popNestedSessionContext calls 
#compareConstraintModes).

#popNestedSessionContext is new: earlier we didn't need a handle for popping 
SQL session context, we needed one in this case, so we implemented the general 
mechanism as well. That hook is called from 
GenericPreparedStatement#executeStmt. As a part of this effort, we also renamed 
#setupNestedSessionContext to #pushNestedSessionContext.

The test case "testBasicDeferral" and "testRoutines" has been added to 
ConstraintCharacteristicsTest to test these basic behaviors.

The "not enforced" feature is not yet implemented in this patch.

Regressions passed OK with this patch.

Patch details:

{color:blue}new file:   
java/engine/org/apache/derby/impl/sql/execute/DeferredDuplicates.java{color}

New static class which handles much of the mechanics of saving duplicate index 
rows and later validating the index.

{color:blue}new file:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2I_10_4.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2I.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2IFactory.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java{color}

The index conglomerate format has been bumped so we can store the deferral 
properties. Upgrade of indexes from old databases is lazy: they are not 
deferrable, but the format just lacks two final properties which default to 
false: hasDeferrableChecking and isUniqueDeferrable. The new format id is 
ACCESS_B2I_V6_ID. The new class B2I_10_4 makes sure we can write old 
conglomerate format correctly in soft upgrade mode (in format ACCESS_B2I_V5_ID).

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/raw/RawStoreFactory.java{color}

Added DERBY_STORE_MINOR_VERSION_11 which allows use of the new index 
conglomerate format.

{color:blue}modified:   
java/engine/org/apache/derby/catalog/IndexDescriptor.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/catalog/types/IndexDescriptorImpl.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/dictionary/IndexRowGenerator.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/TableElementList.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/DDLSingleTableConstantAction.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/MaterializedResultSet.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/RIBulkChecker.java{color}
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/RowChangerImpl.java{color}
modified:   
java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderImpl.java
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/btree/BTree.java{color}
modified:   
java/engine/org/apache/derby/impl/store/access/btree/index/B2IController.java
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/PropertyConglomerate.java{color}

Addition/propagation of "hasDeferrableChecking" and "uniqueDeferrable" 
properties and add "deferred=false" argument to ConglomerateController#insert 
calls.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/conn/SQLSessionContext.java{color}
modified:   
java/engine/org/apache/derby/impl/sql/conn/SQLSessionContextImpl.java

Storage of the session's current constraint modes and operations for pushing 
and clearing that information.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj{color}

Add check that we are at dictionary 10_11 before allowing SET CONSTRAINTS to 
proceed. (Already done for deferred constraint creation).

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/ConglomerateController.java{color}
modified:   
java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/heap/HeapController.java{color}
modified:   java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/catalog/TabInfoImpl.java{color}
modified:   java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java

Add boolean "deferred" to indicate current behavior to #insert. For 
BTreeController, report back duplicates but still do insert iff deferred mode. 
Ignored by HeapController. The real use of the new argument is by IndexChanger 
which knows about constraints in deferred mode.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java{color}

New default arguments (doesn't use the deferred values).

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/RowUtil.java{color}

Small formatting fix to #toString.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/store/access/SortObserver.java{color}
modified:   java/engine/org/apache/derby/impl/sql/execute/BasicSortObserver.java
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/UniqueIndexSortObserver.java{color}
modified:   
java/engine/org/apache/derby/impl/sql/execute/UniqueWithDuplicateNullsIndexSortObserver.java
{color:blue}modified:   
java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java{color}
modified:   
java/engine/org/apache/derby/impl/store/access/sort/UniqueWithDuplicateNullsMergeSo

Changes to accommodate saving duplicates during sorting of existing rows when 
adding an index for a constraint.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java{color}
modified:   
java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java

Call hook for popNestedSessionContext. Renaming of pushNestedSessionContext.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java{color}

Removed unnecessary overload of IndexRowGenerator (as part of adding more 
arguments anyway).

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/AlterConstraintConstantAction.java{color}
modified:   
java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java

Addition of dictionary level check + one bug fix.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java{color}

Determine the flags for the index conglomerates to support constraints, see 
introduction, and set up for creation of correct conglomerates.  Handle any 
initial insertion of rows when constraint mode is initially deferred.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java{color}

Partial support (preparatory code) for bulk import [type a) and b)] in the 
presence of deferrable constraints, but see introduction.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/SetConstraintsConstantAction.java{color}

Logic for setting the session's constraint mode at execution time.


{color:blue}modified:   java/engine/org/apache/derby/loc/messages.xml{color}
modified:   java/shared/org/apache/derby/shared/common/reference/SQLState.java

New error messages. 

{color:blue}modified:   
java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java{color}

Added test cases "testBasicDeferral" and "testRoutines".

{color:blue}modified:   
java/testing/org/apache/derbyTesting/functionTests/util/T_ConsistencyChecker.java{color}
modified:   
java/testing/org/apache/derbyTesting/unitTests/store/T_AccessFactory.java
{color:blue}modified:   
java/testing/org/apache/derbyTesting/unitTests/store/T_QualifierTest.java{color}
modified:   java/testing/org/apache/derbyTesting/unitTests/store/T_b2i.java

Adjustment of old tests to use deferred=false argument to 
ConglomerateController#insert

{color:blue}modified:   
java/testing/org/apache/derbyTesting/unitTests/store/T_SortController.java{color}

Instantiate sorters with default implementations for the new SortObserver 
interface methods.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java{color}

Import fixes, Javadoc fixes, renaming of pushNestedSessionContext, added new 
interface method: setDeferred, isEffectivelyDeferred, setDeferredAll, 
getDeferredHashTables.

{color:blue}modified:{color}
java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java

Implementations of above. Store "deferredHashTables" for the transaction: the 
set of disk based hash tables that holds deferred rows for the session, if any. 
New logic in doCommit and doRollback to handle deferred rows and reset modes. 
New logic to push constraint modes state on routine invocation in 
pushNestedSessionContext. Added popNestedSessionContext to validate any 
deferred rows if we switch back to immediate checking.

{color:blue}modified:   
java/engine/org/apache/derby/iapi/sql/conn/StatementContext.java{color}
modified:   
java/engine/org/apache/derby/iapi/store/access/TransactionController.java
{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/ForeignKeyRIChecker.java{color}
modified:   java/engine/org/apache/derby/impl/sql/execute/GenericRIChecker.java

Javadoc fixes.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java{color}

Javadoc fixes and removal of an assertion that no longer hold with added call 
in GenericPreparedStatement.

{color:blue}modified:   
java/engine/org/apache/derby/impl/sql/compile/SetConstraintsNode.java{color}

Import fix.

To apply the patch, you need to add empty versions of the two new files:
java/engine/org/apache/derby/impl/sql/execute/DeferredDuplicates.java
java/engine/org/apache/derby/impl/store/access/btree/index/B2I_10_4.java


> Support deferrable constraints
> ------------------------------
>
>                 Key: DERBY-532
>                 URL: https://issues.apache.org/jira/browse/DERBY-532
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>            Reporter: Jörg von Frantzius
>            Assignee: Dag H. Wanvik
>              Labels: derby_triage10_11
>         Attachments: deferredConstraints.html, deferredConstraints.html, 
> derby-532-syntax-binding-dict-1.diff, derby-532-syntax-binding-dict-1.status, 
> derby-532-syntax-binding-dict-2.diff, derby-532-syntax-binding-dict-2.status, 
> derby-532-syntax-binding-dict-all-1.diff, 
> derby-532-testAlterConstraintInvalidation.diff, 
> derby-532-testAlterConstraintInvalidation.status, derby-532-unique-pk-1.diff, 
> derby-532-unique-pk-1.status
>
>
> In many situations it is desirable to have constraints checking taking place 
> only at transaction commit time, and not before. If e.g. there is a chain of 
> foreign key constraints between tables, insert statements have to be ordered 
> to avoid constraint violations. If foreign key references are circular, the 
> DML has to be split into insert statements and subsequent update statements 
> by the user.
> In other words, with deferred constraints checking, life is much easier for 
> the user. Also it can create problems with softwares such as 
> object-relational mapping tools that are not prepared for statement ordering 
> and thus depend on deferred constraints checking.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to