Commit 5e345281 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-3888.

When inserting a record with update on duplicate keys the server calls
the ha_index_read_idx_map handler function to look for the record
that violates unique key constraints. The third parameter of this call
should mark only the base components of the index where the server is
searched for the record. Possible hidden components of the primary key
are to be unmarked.
parent b057f95d
...@@ -744,5 +744,33 @@ SELECT * FROM t1, t2 WHERE b=a; ...@@ -744,5 +744,33 @@ SELECT * FROM t1, t2 WHERE b=a;
a b a b
set optimizer_switch=@save_optimizer_switch; set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug mdev-3888: INSERT with UPDATE on duplicate keys
# with extended_keys=on
#
CREATE TABLE t1 (
c1 bigint(20) unsigned NOT NULL AUTO_INCREMENT,
c2 bigint(20) unsigned NOT NULL,
c3 bigint(20) unsigned NOT NULL,
c4 varchar(128) DEFAULT NULL,
PRIMARY KEY (c1),
UNIQUE KEY uq (c2,c3),
KEY c3 (c3),
KEY c4 (c4)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
set @save_optimizer_switch=@@optimizer_switch;
set session optimizer_switch='extended_keys=off';
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
DELETE FROM t1;
set session optimizer_switch='extended_keys=on';
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1;
set optimizer_switch=@save_ext_key_optimizer_switch; set optimizer_switch=@save_ext_key_optimizer_switch;
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -428,5 +428,44 @@ set optimizer_switch=@save_optimizer_switch; ...@@ -428,5 +428,44 @@ set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo #
--echo # Bug mdev-3888: INSERT with UPDATE on duplicate keys
--echo # with extended_keys=on
--echo #
CREATE TABLE t1 (
c1 bigint(20) unsigned NOT NULL AUTO_INCREMENT,
c2 bigint(20) unsigned NOT NULL,
c3 bigint(20) unsigned NOT NULL,
c4 varchar(128) DEFAULT NULL,
PRIMARY KEY (c1),
UNIQUE KEY uq (c2,c3),
KEY c3 (c3),
KEY c4 (c4)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
set @save_optimizer_switch=@@optimizer_switch;
set session optimizer_switch='extended_keys=off';
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
DELETE FROM t1;
set session optimizer_switch='extended_keys=on';
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar')
ON DUPLICATE KEY UPDATE c4 = VALUES(c4);
set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1;
set optimizer_switch=@save_ext_key_optimizer_switch; set optimizer_switch=@save_ext_key_optimizer_switch;
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -1677,9 +1677,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) ...@@ -1677,9 +1677,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
} }
} }
key_copy((uchar*) key,table->record[0],table->key_info+key_nr,0); key_copy((uchar*) key,table->record[0],table->key_info+key_nr,0);
key_part_map keypart_map= (1 << table->key_info[key_nr].key_parts) - 1;
if ((error= (table->file->ha_index_read_idx_map(table->record[1], if ((error= (table->file->ha_index_read_idx_map(table->record[1],
key_nr, (uchar*) key, key_nr, (uchar*) key,
HA_WHOLE_KEY, keypart_map,
HA_READ_KEY_EXACT)))) HA_READ_KEY_EXACT))))
goto err; goto err;
} }
......
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