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

Øystein Grøvlen commented on DERBY-2212:
----------------------------------------

I agree with Mike that it seems a bit complicated an error prone to
sometimes treat nulls as equal and sometimes not.

On the other hand, it seems to me that building the requested
functionality on top of non-unique indexes will not be very efficient.
There is a reason for why unique indexes has been implemented in
Derby, and I think that is because it is an more efficient way of
enforcing uniqueness than by doing lookups in a non-unique index.

I also agree with Mike that it needs to be better defined what
functionality one is aiming for here.  The reporter of this Jira
suggest to have a special index type where multiple null values are
allowed (like DB2).  Others have requested to be able to define a
unique constraint on a column that may have null values.  Unique
constraints are currently enforced by an underlying unique index.  The
latter is the main reason why I would like to have an index that
enforcing uniqueness for all values except null.  I think I would
prefer that all unique indexes behaved that way, and not to have a
non-standard syntax for creating such indexes like DB2.

My question is what do we gain from having indexes that treat null
values as equal?  Instead of having unique indexes that sometimes
treat nulls as equal and sometimes not, could not all indexes always
treat null values as unequal?  (I know this will be probably be a lot
more work).  I must admit that I do not fully understand the
consequences of such an approach, and it would be good if someone
could explain if there is cases where it is necessary to treat nulls as equal.  
(Mike mention an example from recovery, but if I understand him correctly
that could be solved by including the row location column in the
look-up.)







> 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
>            Assignee: Anurag Shekhar
>         Attachments: derby-2212preview.diff, derby-2212preview2.diff
>
>
> 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.

Reply via email to