mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
5a0e7394a5
UPDATED TWICE For multi update it is not allowed to update a column of a table if that table is accessed through multiple aliases and either 1) the updated column is used as partitioning key 2) the updated column is part of the primary key and the primary key is clustered This check is done in unsafe_key_update(). The bug was that for case 2), it was checked whether updated_column_number == table_share->primary_key However, the primary_key variable is the index number of the primary key, not a column number. Prior to this bugfix, the first column was wrongly believed to be the primary key. The columns covered by an index is found in table->key_info[idx_number]->key_part. The bugfix is to check if any of the columns in the keyparts of the primary key are updated. The user-visible effect is that for storage engines with clustered primary key (e.g. InnoDB but not MyISAM) queries like "UPDATE t1 AS A JOIN t2 AS B SET A.primkey=..." will now error with "ERROR HY000: Primary key/partition key update is not allowed since the table is updated both as 'A' and 'B'." instead of "ERROR 1032 (HY000): Can't find record in 't1_tb'" even if primkey is not the first column in the table. This was the intended behavior of bugfix 11764529. mysql-test/r/multi_update.result: Add test for bug#11882110 mysql-test/r/multi_update_innodb.result: Add test for bug#11882110 mysql-test/t/multi_update.test: Add test for bug#11882110 mysql-test/t/multi_update_innodb.test: Add test for bug#11882110 sql/sql_update.cc: unsafe_key_update() wrongly checked if the primary key index number was the same as updated column number. Now it is checked whether any of the columns making up the primary key is updated. sql/table.h: Fix comment on TABLE_SHARE::primary_key. Incorrect comment was introduced by an earlier merge conflict (as per dlenev)
77 lines
1.6 KiB
Text
77 lines
1.6 KiB
Text
--source include/have_innodb.inc
|
|
|
|
--echo #
|
|
--echo # BUG#57373: Multi update+InnoDB reports ER_KEY_NOT_FOUND if a
|
|
--echo # table is updated twice
|
|
--echo #
|
|
|
|
# Results differ between storage engines.
|
|
# See multi_update.test for the MyISAM variant of this test
|
|
CREATE TABLE t1(
|
|
pk INT,
|
|
a INT,
|
|
b INT,
|
|
PRIMARY KEY (pk)
|
|
) ENGINE=InnoDB;
|
|
|
|
INSERT INTO t1 VALUES (0,0,0);
|
|
--error ER_MULTI_UPDATE_KEY_CONFLICT
|
|
UPDATE t1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
|
|
SELECT * FROM t1;
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
--error ER_MULTI_UPDATE_KEY_CONFLICT
|
|
UPDATE v1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
|
|
SELECT * FROM t1;
|
|
|
|
UPDATE t1 AS A, t1 AS B SET A.a = 1, B.b = 2;
|
|
--echo # Should be (0,1,2)
|
|
SELECT * FROM t1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
--echo # BUG#11882110: UPDATE REPORTS ER_KEY_NOT_FOUND IF TABLE IS
|
|
--echo # UPDATED TWICE
|
|
--echo #
|
|
|
|
# Results differ between storage engines.
|
|
# See multi_update.test for the MyISAM variant of this test
|
|
CREATE TABLE t1 (
|
|
col_int_key int,
|
|
pk int,
|
|
col_int int,
|
|
key(col_int_key),
|
|
primary key (pk)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES (1,2,3);
|
|
|
|
--echo
|
|
CREATE TABLE t2 (
|
|
col_int_key int,
|
|
pk_1 int,
|
|
pk_2 int,
|
|
col_int int,
|
|
key(col_int_key),
|
|
primary key (pk_1,pk_2)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO t2 VALUES (1,2,3,4);
|
|
|
|
--echo
|
|
--error ER_MULTI_UPDATE_KEY_CONFLICT
|
|
UPDATE t1 AS A NATURAL JOIN t1 B SET A.pk=5,B.pk=7;
|
|
--echo
|
|
SELECT * FROM t1;
|
|
|
|
--echo
|
|
--error ER_MULTI_UPDATE_KEY_CONFLICT
|
|
UPDATE t2 AS A NATURAL JOIN t2 B SET A.pk_1=5,B.pk_1=7;
|
|
--echo
|
|
--error ER_MULTI_UPDATE_KEY_CONFLICT
|
|
UPDATE t2 AS A NATURAL JOIN t2 B SET A.pk_2=10,B.pk_2=11;
|
|
|
|
--echo
|
|
SELECT * FROM t2;
|
|
|
|
DROP TABLE t1,t2;
|