Bugs item #2873564, was opened at 2009-10-06 16:26
Message generated for change (Comment added) made by nielsnes
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=482468&aid=2873564&group_id=56967

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: SQL/Core
Group: SQL "stable"
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Guillaume Theoret (smokinn)
Assigned to: Niels Nes (nielsnes)
Summary: Cannot create unique constraint on char column

Initial Comment:
When creating a unique constraint, if one of the columns is of type char, the 
unique constraint is ignored.

To reproduce:

ql>CREATE TABLE test.keytest (
more>  date_added int NOT NULL,
more>  hash_key char(32) NOT NULL,
more>  dimension1 int NOT NULL,
more>  dimension2 int NOT NULL,
more>  metric1 int NOT NULL,
more>  metric2 int NOT NULL,
more>
more>  CONSTRAINT key_test UNIQUE (hash_key,date_added)
more>);
Operation successful
sql>insert into test.keytest (date_added, hash_key, dimension1,
dimension2, metric1, metric2) VALUES (1, 'a', 1, 1, 2, 2);
Rows affected 1
Timer      12.126 msec 0 rows
sql>insert into test.keytest (date_added, hash_key, dimension1,
dimension2, metric1, metric2) VALUES (1, 'a', 1, 1, 2, 2);
Rows affected 1
Timer      18.345 msec 0 rows
sql>select * from test.keytest;
select * from test.keytest;
+------------+----------------------------------+------------+------------+---------+---------+
| date_added | hash_key                         | dimension1 |
dimension2 | metric1 | metric2 |
+============+==================================+============+============+=========+=========+
|          1 | a                                |          1 |
 1 |       2 |       2 |
|          1 | a                                |          1 |
 1 |       2 |       2 |
+------------+----------------------------------+------------+------------+---------+---------+
2 tuples
Timer       1.997 msec 2 rows
sql>CREATE UNIQUE INDEX unique_key_test ON test.keytest (date_added, hash_key);
Operation successful
Timer      25.904 msec 2 rows
sql>insert into test.keytest (date_added, hash_key, dimension1,
dimension2, metric1, metric2) VALUES (1, 'a', 1, 1, 2, 2);
Rows affected 1
Timer      78.637 msec 2 rows
sql>insert into test.keytest (date_added, hash_key, dimension1,
dimension2, metric1, metric2) VALUES (1, 'a', 1, 1, 2, 2);
Rows affected 1
Timer      31.788 msec 2 rows
sql>select * from test.keytest;
select * from test.keytest;
+------------+----------------------------------+------------+------------+---------+---------+
| date_added | hash_key                         | dimension1 |
dimension2 | metric1 | metric2 |
+============+==================================+============+============+=========+=========+
|          1 | a                                |          1 |
 1 |       2 |       2 |
|          1 | a                                |          1 |
 1 |       2 |       2 |
|          1 | a                                |          1 |
 1 |       2 |       2 |
|          1 | a                                |          1 |
 1 |       2 |       2 |
+------------+----------------------------------+------------+------------+---------+---------+
4 tuples
Timer      18.083 msec 4 rows

Unique constraint on all int columns is not affected:

sql>CREATE TABLE test.keytest2 (
more>  date_added int NOT NULL,
more>  key int NOT NULL,
more>  dimension1 int NOT NULL,
more>  dimension2 int NOT NULL,
more>  metric1 int NOT NULL,
more>  metric2 int NOT NULL,
more>
more>  CONSTRAINT key_test2 UNIQUE (key,date_added)
more>);
Operation successful
Timer     167.384 msec 0 rows
sql>insert into test.keytest2 (date_added, key, dimension1,
dimension2, metric1, metric2) VALUES (1, 1, 1, 1, 2, 2);
Rows affected 1
Timer       1.693 msec 0 rows
sql>insert into test.keytest2 (date_added, key, dimension1,
dimension2, metric1, metric2) VALUES (1, 1, 1, 1, 2, 2);
!SQLException:assert:INSERT INTO: UNIQUE constraint
'keytest2.key_test2' violated
0 tuples
Timer      66.634 msec 0 rows
sql>select * from test.keytest2;
select * from test.keytest2;
+------------+-------+------------+------------+---------+---------+
| date_added | key   | dimension1 | dimension2 | metric1 | metric2 |
+============+=======+============+============+=========+=========+
|          1 |     1 |          1 |          1 |       2 |       2 |
+------------+-------+------------+------------+---------+---------+

----------------------------------------------------------------------

>Comment By: Niels Nes (nielsnes)
Date: 2009-11-11 20:35

Message:
added test unique_constraint_on_char.SF-2873564.sql

fix by fixing the hash computation. (it was computed on the pointer
instead of on the value for strings)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=482468&aid=2873564&group_id=56967

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Monetdb-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-bugs

Reply via email to