db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anurag Shekhar (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-2212) Add "Unique where not null" to create index
Date Mon, 03 Sep 2007 05:57:19 GMT

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

Anurag Shekhar commented on DERBY-2212:
---------------------------------------

I am trying to add duplicate null in unique index by making null 
not equal to null in case of unique index. The changes are in 
ControlRow class. But this is only part of the implemenation the
 other major part is to change the scan method used if there is
 a null in search criterion while scanning index.

Changes are something like this

--- java/engine/org/apache/derby/impl/store/access/btree/ControlRow.java        (revision
572236)
+++ java/engine/org/apache/derby/impl/store/access/btree/ControlRow.java        (working copy)
@@ -1293,7 +1293,9 @@
                        // int r = indexcol.compare(keycol);

             int r = indexrow[i].compare(key[i]);
-
+                        if (r == 0 && key [i].isNull()) {
+                            r = 1;
+                        }



(Doing this corrupt the btree index and i get an exception while deleting 
the table. I am checking out how to fix this)

I am also modifying the optimizer to select bulk Index scan when there 
is a "is null" in select. 

This change will make indexes incompatible with the older behaviour.
I plan to support soft upgrades by adding another attribute in index 
header and extending B2I class. 

I think this will be less expensive that letting the duplicates go into the 
tree and then checking if there is some duplicate key without null as any 
of their part. Please let me know if my assumption is wrong.



> Add "Unique where not null" to create index
> -------------------------------------------
>
>                 Key: DERBY-2212
>                 URL: https://issues.apache.org/jira/browse/DERBY-2212
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 10.2.1.6
>            Reporter: Oleksandr Alesinskyy
>
> Derby prohibits creation of unique constraints on nullable colums (as well if only some
columns in the constraint list are nullable) and treat nulls in unique indexes as normal values
(i.e. only one row with null values in indexed columns may be inserted into the table). This
bahavior is very restrictive, does not completely comply with SQL standards (both letter and
intent) as well as with business needs and intending meaning of NULL values (2 null values
are not considered as equal, this comparision shall return NULL, and for selection criteria
boolean null is treated as FALSE).
> This behavior, as far as I can see, is modelled after DB2 (and differs from behavior
of most other major databases, like SyBase, Oracle, etc.).
> But even DB2 provide some means to alleviate these restrictions, namely "UNIQUE WHERE
NOT NULL" clause for CREATE INDEX statement.
> It will be very good if such "UNIQUE WHERE NOT NULL" clause will be introduced in Derby.
> Regards,
> Oleksandr Alesinskyy

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


Mime
View raw message