MYSQL replace into 性能
(2016-08-21 20:39:26)
标签:
更新replaceduplicateupdate |
分类: MYSQL |
MYSQL replace into 性能
ON DUPLICATE KEY UPDATE c=c+1;
MySQL uses the following algorithm for REPLACE (and LOAD DATA
... REPLACE):
Try to insert the new row into the table
While the insertion fails because a duplicate-key error occurs
for a primary key or unique index:
Delete from the table the conflicting row that has the
duplicate key value
Try again to insert the new row into the table
replace into
会直接尝试插入,如果失败,则删除原来的行,然后插入新的行。
另一个类似的语句
INSERT ... ON DUPLICATE KEY UPDATE Syntax
If you specify ON DUPLICATE KEY UPDATE, and a row is inserted
that would cause a duplicate value in a UNIQUE index or PRIMARY
KEY, MySQL performs an UPDATE of the old row. For example, if
column a is declared as UNIQUE and contains the value 1, the
following two statements have similar effect:
INSERT INTO table (a,b,c) VALUES (1,2,3)
UPDATE table SET c=c+1 WHERE a=1;
目测感觉 replace into 需要删除,而insert on duplicate update则直接更新,
看起来update的性能更好一些,量大的话,delete不是一个好选择。
====转===============
mysql中的replace into的效率问题
MySQL "replace into" 的坑