Commit 82eb2c6d authored by unknown's avatar unknown

fixed MDEV-568: Wrong result for a hash index look-up if the index is unique and the key is NULL

Check ability of index to be NULL as it made in MyISAM. UNIQUE with NULL could have several NULL entries so we have to continue even if ve have found a row.
parent 807f537f
......@@ -382,3 +382,22 @@ INSERT INTO t1 VALUES('A ', 'A ');
ERROR 23000: Duplicate entry 'A -A ' for key 'key1'
DROP TABLE t1;
End of 5.0 tests
#
# MDEV-568 (AKA LP BUG#1007981, AKA MySQL bug#44771)
# Wrong result for a hash index look-up if the index is unique and
# the key is NULL
#
CREATE TABLE t1 ( pk INT PRIMARY KEY, val INT, UNIQUE KEY USING HASH(val)) ENGINE=MEMORY;
INSERT INTO t1 VALUES (1, NULL);
INSERT INTO t1 VALUES (2, NULL);
INSERT INTO t1 VALUES (3, 1);
INSERT INTO t1 VALUES (4, NULL);
EXPLAIN SELECT * FROM t1 WHERE val IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref val val 5 const 1 Using where
SELECT * FROM t1 WHERE val IS NULL;
pk val
4 NULL
2 NULL
1 NULL
drop table t1;
......@@ -284,3 +284,18 @@ INSERT INTO t1 VALUES('A ', 'A ');
DROP TABLE t1;
--echo End of 5.0 tests
--echo #
--echo # MDEV-568 (AKA LP BUG#1007981, AKA MySQL bug#44771)
--echo # Wrong result for a hash index look-up if the index is unique and
--echo # the key is NULL
--echo #
CREATE TABLE t1 ( pk INT PRIMARY KEY, val INT, UNIQUE KEY USING HASH(val)) ENGINE=MEMORY;
INSERT INTO t1 VALUES (1, NULL);
INSERT INTO t1 VALUES (2, NULL);
INSERT INTO t1 VALUES (3, 1);
INSERT INTO t1 VALUES (4, NULL);
EXPLAIN SELECT * FROM t1 WHERE val IS NULL;
SELECT * FROM t1 WHERE val IS NULL;
drop table t1;
......@@ -63,7 +63,7 @@ int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key,
info->update= 0;
DBUG_RETURN(my_errno);
}
if (!(keyinfo->flag & HA_NOSAME))
if ((keyinfo->flag & (HA_NOSAME | HA_NULL_PART_KEY)) != HA_NOSAME)
memcpy(info->lastkey, key, (size_t) keyinfo->length);
}
memcpy(record, pos, (size_t) share->reclength);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment