且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果不存在则插入

更新时间:2022-05-21 02:56:29

其官方语法是

INSERT IGNORE ...

但是,在您的情况下,这样做实际上更可取

However, in your case it may actually be preferable to do

INSERT ... ON DUPLICATE KEY UPDATE id=id

请参见

See benchmarks. In my experience, this hack only improves performance if you've got a primary key--the optimizer won't recognize the no-op if you do follower_id = follower_id.