创建/销毁查询比编辑/更新更快?

时间:2022-02-14 19:20:14

Are Create/Destroy queries faster than edit/update?

创建/销毁查询是否比编辑/更新更快?

If we want to add like feature to post, is better to create a new table "likes" with user_id and post_id columns or create a new column likes_number on post table?

如果我们想要添加类似功能的帖子,最好用user_id和post_id列创建一个新的“喜欢”表,或者在帖子表上创建一个新列like_number?

Thank you very much.

非常感谢你。

1 个解决方案

#1


1  

This depends very much on many different parameters, but in general consider the following:

这很大程度上取决于许多不同的参数,但通常考虑以下因素:

  • Is there meta-data specific to the flag? In the case of likes there could be: The user that made the like, the timestamp of when the like occurred as examples. Tracking this data in the post table would require a column for each piece of data. If you want to store this meta data then you should use another table.

    是否有特定于旗帜的元数据?在喜欢的情况下,可能存在:制作类似的用户,例如发生类似的时间戳。在post表中跟踪此数据将需要每列数据的列。如果要存储此元数据,则应使用另一个表。

  • Is there a one to many relationship? In this case there is -- there can be many likers. This shows that a row in another table could have value. Every row stores the meta data for that like.

    有一对多关系吗?在这种情况下,可以有许多喜欢的人。这表明另一个表中的行可能有值。每一行都存储元数据。

  • How used is the table -- will locking have a performance impact? In your case I doubt it but it could be the case that locking to row to change the like count could cause performance issues. If the like data is in a different table there is no impact.

    如何使用表 - 锁定会对性能产生影响吗?在您的情况下,我怀疑它,但可能是锁定到行以更改类似计数可能会导致性能问题。如果相同的数据在不同的表中,则没有影响。

To me it seems clear that in this case another table makes sense.

对我来说,似乎很清楚,在这种情况下,另一个表是有道理的。

Other types of data could be the other way -- for example a flag for a task being finished in a todo list. In that case it makes sense to just add a column.

其他类型的数据可能是另一种方式 - 例如,在待办事项列表中完成任务的标志。在这种情况下,只添加一列是有意义的。


As for create/destory vs edit/update -- it depends so much on many details but I would say in general edit/update is faster.

至于创建/存储与编辑/更新 - 它在很大程度上取决于许多细节,但我会说通常编辑/更新更快。

#1


1  

This depends very much on many different parameters, but in general consider the following:

这很大程度上取决于许多不同的参数,但通常考虑以下因素:

  • Is there meta-data specific to the flag? In the case of likes there could be: The user that made the like, the timestamp of when the like occurred as examples. Tracking this data in the post table would require a column for each piece of data. If you want to store this meta data then you should use another table.

    是否有特定于旗帜的元数据?在喜欢的情况下,可能存在:制作类似的用户,例如发生类似的时间戳。在post表中跟踪此数据将需要每列数据的列。如果要存储此元数据,则应使用另一个表。

  • Is there a one to many relationship? In this case there is -- there can be many likers. This shows that a row in another table could have value. Every row stores the meta data for that like.

    有一对多关系吗?在这种情况下,可以有许多喜欢的人。这表明另一个表中的行可能有值。每一行都存储元数据。

  • How used is the table -- will locking have a performance impact? In your case I doubt it but it could be the case that locking to row to change the like count could cause performance issues. If the like data is in a different table there is no impact.

    如何使用表 - 锁定会对性能产生影响吗?在您的情况下,我怀疑它,但可能是锁定到行以更改类似计数可能会导致性能问题。如果相同的数据在不同的表中,则没有影响。

To me it seems clear that in this case another table makes sense.

对我来说,似乎很清楚,在这种情况下,另一个表是有道理的。

Other types of data could be the other way -- for example a flag for a task being finished in a todo list. In that case it makes sense to just add a column.

其他类型的数据可能是另一种方式 - 例如,在待办事项列表中完成任务的标志。在这种情况下,只添加一列是有意义的。


As for create/destory vs edit/update -- it depends so much on many details but I would say in general edit/update is faster.

至于创建/存储与编辑/更新 - 它在很大程度上取决于许多细节,但我会说通常编辑/更新更快。