Bug #2483 | COUNT(*) on NULL incorrect for UNIQUE index | ||
---|---|---|---|
Submitted: | 22 Jan 2004 14:01 | Modified: | 27 Jan 2004 10:08 |
Reporter: | James Farley | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 4.0.17-standard-log | OS: | Linux (RedHat 7.3) |
Assigned to: | Jani Tolonen | CPU Architecture: | Any |
[22 Jan 2004 14:01]
James Farley
[22 Jan 2004 14:35]
Dean Ellis
Verified with 4.0.18 and 4.1.2. Does not occur with MyISAM, so I am changing the category. Thank you.
[26 Jan 2004 15:46]
Jani Tolonen
I believe the problem is that InnoDB assumes that if a search is done on a unique key with exact match, only one match can occur. This is true in any other case except if the key is NULL and there are more than one NULL values in the key field. Suggested fix: Make the following change in row0sel.c *** innobase/row/row0sel.c 2004-01-27 01:37:08.000000000 +0200 --- /my/tmp/row0sel.c 2004-01-27 01:36:43.000000000 +0200 *************** *** 2883,2906 **** thus in a secondary index we must use next-key locks when locking delete-marked records. */ ! if (match_mode == ROW_SEL_EXACT ! && index->type & DICT_UNIQUE ! && dtuple_get_n_fields(search_tuple) ! == dict_index_get_n_unique(index)) { ! unique_search = TRUE; ! ! /* Even if the condition is unique, MySQL seems to try to ! retrieve also a second row if a primary key contains more than ! 1 column. Return immediately if this is not a HANDLER ! command. */ ! ! if (direction != 0 && !prebuilt->used_in_HANDLER) { ! ! trx->op_info = (char *) ""; ! return(DB_RECORD_NOT_FOUND); ! } ! } ! mtr_start(&mtr); /*-------------------------------------------------------------*/ --- 2883,2893 ---- thus in a secondary index we must use next-key locks when locking delete-marked records. */ ! if (match_mode == ROW_SEL_EXACT && index->type & DICT_UNIQUE && ! dtuple_get_n_fields(search_tuple) == ! dict_index_get_n_unique(index)) ! unique_search = TRUE; ! mtr_start(&mtr); /*-------------------------------------------------------------*/ Tested and works for me at least. I will however wait that Heikki reviews the patch before submitting it. Regards, Jani
[27 Jan 2004 10:08]
Heikki Tuuri
Hi! InnoDB assumed that there can only be one IS NULL row in a UNIQUE index, though there can be many! Fixed in 4.0.18. Thank you, Heikki