MySQL 'UPDATE ON DUPLICATE KEY' without a unique column?

后端 未结 3 1454
逝去的感伤
逝去的感伤 2021-01-12 10:31

What are peoples\' thoughts on the most performance efficient way to do the following query:

  • 3 column table

  • if the combination of col_

3条回答
  •  终归单人心
    2021-01-12 10:55

    Most efficient way is to create UNIQUE KEY and use ON DUPLICATE KEY UPDATE.

    Slower way is to:
    LOCK TABLE
    SELECT TABLE (you need an index anyway for the best performance)
    if exists, UPDATE
    else INSERT
    UNLOCK TABLES

提交回复
热议问题