[ 
https://issues.apache.org/jira/browse/DERBY-3330?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Anurag Shekhar updated DERBY-3330:
----------------------------------

    Attachment: derby-3330.diff

I am running the tests and will be updating the patch based on the test results.

Description of patch
modified files 

java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java
java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
Added new methods to support almost unique index for unique constraint

java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java
Added new CreateIndexConstantAction method to support a new parameter (almost 
unique) for indexes. This property is stored and used while executing this 
action.
execute method of this class uses this property to use 
AlmostUniqueIndexSortObserver and AlmostUniqueMergeSort. This two classes 
provide special sorting routine which considers two row as duplicate only if 
all the key parts are non null.

java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java
changed the scope of few attributes to protected so that AlmostUniqueMergeSort 
can  access them.

java/engine/org/apache/derby/impl/store/access/sort/ExternalSortFactory.java
removed final to allow AlmostUniqueExternalSortFactory to extend from it.
moved creation of MergeSort to a protected method so that extending class 
can return a different class.

java/engine/org/apache/derby/impl/store/access/btree/BTree.java
added a new property almostUnique and getter and setters for the same.

java/engine/org/apache/derby/impl/store/access/btree/BTreeController.java
added a new private method to compare the record with immediate left and right 
records to check for duplicate.

java/engine/org/apache/derby/impl/store/access/btree/index/B2I.java
added code to store and retrieve new attribute "almostUnique" to the file 
system.

java/engine/org/apache/derby/iapi/store/access/AccessFactoryGlobals.java
added property string for AlmostUniqueExternalSortFactory.

java/engine/org/apache/derby/modules.properties
Added entry for AlmostUniqueExternalSortFactory.



New files
java/engine/org/apache/derby/impl/sql/execute/AlmostUniqueIndexSortObserver.java
This class implements duplicate checking routine to reject non null duplicate 
keys.
 
java/engine/org/apache/derby/impl/store/access/sort/AlmostUniqueExternalSortFactory.java
This class extends from ExternalSortFactory and overrides getMergeSort methods 
to return AlmostUniqueMergeSort.

java/engine/org/apache/derby/impl/store/access/sort/AlmostUniqueMergeSort.java
This class extends MergeSort and overrides compare methods to ignore last 
keypart (location) while checking for duplicate keys.



> provide support for unique constraint over nullable columns
> -----------------------------------------------------------
>
>                 Key: DERBY-3330
>                 URL: https://issues.apache.org/jira/browse/DERBY-3330
>             Project: Derby
>          Issue Type: New Feature
>          Components: Store
>    Affects Versions: 10.4.0.0
>         Environment: all
>            Reporter: Anurag Shekhar
>            Assignee: Anurag Shekhar
>         Attachments: derby-3330.diff
>
>
> Allow unique constraint over nullable field. Right now derby support unique 
> constraint only over not null columns.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to