How can I detect redundant rows in the table?

前端 未结 4 1088
梦谈多话
梦谈多话 2020-12-22 12:19

I\'m following solution #1 of this answer. After a while, there will be some redundant rows in the table. Suppose this table:

+------+------         


        
4条回答
  •  旧巷少年郎
    2020-12-22 12:38

    It's not clear what redundant means in this case. There's no way to distinguish between these two rows:

    +------+------------------+
    | user |     cookie       |
    +------+------------------+
    | 1    | ojer0f934mf2...  | -- now this row is useless anymore
    | 1    | 0243hfd348i4...  |
    +------+------------------+
    

    If you add a column to make the first row identifiable, then the problem solves itself: before each insert, delete the row it will supersede. No need of cron; at worst each user will have one leftover row in the database that will be removed on next use.

    I also recommend a primary key to enforce the no-redundant-rows rule.

提交回复
热议问题