Which DB design is faster: a unique index and INSERT IGNORE, or using SELECT to find existing records?

后端 未结 6 1969
长情又很酷
长情又很酷 2020-12-21 12:03

I have a table with just one column: userid.

When a user accesses a certain page, his userid is being inserted to the table. Userids are unique, so there shouldn\'t

6条回答
  •  失恋的感觉
    2020-12-21 12:27

    what about doing update, e.g.

    UPDATE xxx SET x=x+1 WHERE userid=y
    

    and if that fails (e.g. no matched rows), then do an insert for a new user?

提交回复
热议问题