Use MySQL's replace into carefully (reproduced)

Source: Internet
Author: User

MySQL the SQL There are many extensions, some of which are handy, but some have performance problems after being misused, and there are some unintended side effects, such as REPLACE into .

MySQLwhen the data conflicts, it actually deletes the old record, and then writes the new record, which is usedREPLACE intoThe biggest mistake of all time, take the previous example, after the executionREPLACE into auto (k, v) VALUES (1, ' 1-1 ')after the new record is written, theExtrafield specifies the value, the original recordExtraThe value of the field is "Lost", which is usually not business-expected, and the more common requirement is actually when there isk=1record, just putvthe value of the field is updated to' 1-1 ', other unspecified fields remain intact, and the requirements are metMySQLdialect isINSERT into auto (k, v) VALUES (1, ' 1-1 ') on DUPLICATE KEY UPDATE v=values (v);

in view of this, many use REPLACE into the scenes that actually need to be INSERT into ... On DUPLICATE KEY UPDATE, use replaceinto sparingly ifyou understand the replace into behavior and side effects correctly.

Use MySQL's replace into carefully (reproduced)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.