简体   繁体   English

MySQL性能-删除表行或仅将列标记为已删除

[英]MySQL Performance - Delete Table Rows or Just Mark a Column as Deleted

I've read a few times that for performance reasons you best not to delete rows in a table but rather use a column to mark the rows as deleted. 我读过几次,出于性能方面的考虑,最好不要删除表中的行,而应使用列将行标记为已删除。

eg: I have a table that holds members photos and when I member removes a photo I currently delete the row. 例如:我有一张桌子,上面放着会员的照片,当会员删除照片时,我当前删除该行。 I could instead just mark the photo as deleted but leave it in the table. 相反,我可以将照片标记为已删除,然后将其保留在表格中。

So rather then run a DELETE I would run a UPDATE. 因此,宁可先运行DELETE,也要运行UPDATE。

Is this really a better way to use MySQL INNODB Tables or does it really not make any difference? 这真的是使用MySQL INNODB表的更好方法,还是真的没有任何区别?

If you need to preserve the data and history set a field to DELETE otherwise removed the row from your table. 如果需要保留数据和历史记录,请将字段设置为DELETE,否则从表中删除该行。 No point using disk space, for data you don't need. 没有必要使用磁盘空间来存储不需要的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM