匹配和更改的行数不相等
Number of rows matched and changed not equal
我有一个简单的更新查询:
UPDATE mytable SET mycolumn = replace(mycolumn, "somestring", "otherstring")
WHERE mycolumn LIKE '%somestring%';
示例输出:
Query OK, 198 rows affected (24.18 sec)
Rows matched: 200 Changed: 198 Warnings: 0
更改的行数怎么可能比匹配的少?每个匹配的行应在列中包含 somestring
,因此应将其替换。
这是一个 bug 的报告,现在已在 MySQL 5.1 之后恢复。
来自同一个:
Whether the number of rows updated is different from the number of
rows found is engine specific. Some storage engines are able to read
just a subset of the columns when doing an update (InnoDB is one such
engine). So the server can't reliably check if a row will not be
updated. And because of that it will always have number of rows
updated equal to the number of rows found. The reason that this worked
differently in 5.0 is the fact that in 5.1 the server passes
information for the columns it needs to read to InnoDB and hence not
all the columns are read anymore. In 5.0 such information was not
passed down to the InnoDB storage engine, so it always returned all
the columns and a check wether a rows is updated was possible.
我有一个简单的更新查询:
UPDATE mytable SET mycolumn = replace(mycolumn, "somestring", "otherstring")
WHERE mycolumn LIKE '%somestring%';
示例输出:
Query OK, 198 rows affected (24.18 sec)
Rows matched: 200 Changed: 198 Warnings: 0
更改的行数怎么可能比匹配的少?每个匹配的行应在列中包含 somestring
,因此应将其替换。
这是一个 bug 的报告,现在已在 MySQL 5.1 之后恢复。
来自同一个:
Whether the number of rows updated is different from the number of rows found is engine specific. Some storage engines are able to read just a subset of the columns when doing an update (InnoDB is one such engine). So the server can't reliably check if a row will not be updated. And because of that it will always have number of rows updated equal to the number of rows found. The reason that this worked differently in 5.0 is the fact that in 5.1 the server passes information for the columns it needs to read to InnoDB and hence not all the columns are read anymore. In 5.0 such information was not passed down to the InnoDB storage engine, so it always returned all the columns and a check wether a rows is updated was possible.