【发布时间】:2016-09-08 21:57:01
【问题描述】:
我有一个显示餐厅资料数据的页面,其中显示的数据之一是该餐厅的用户总签到数
我有一个 mysql 表,如:user_checkins,它将用户签入存储到餐厅,如:
id | user_id | res_id | checkin_date |
1 | 102 | 5526 | 2016-04-21 03:20:21 |
2 | 165 | 5574 | 2016-04-21 06:35:21 |
3 | 102 | 4565 | 2016-04-24 02:15:30 |
还有一张桌子res_checkin_count:
id | res_id | total_checkin_count |
1 | 5526 | 1055 |
一段时间后,user_checkins 中会创建很多行,因为人们经常签到
问题:我应该删除旧行吗?比如创建一个定时作业,定期(如每天)删除到达餐厅的旧行,并在另一个mysql TABLE 中更新餐厅total_checkin_count 编号,仅存储每家餐厅的total_checkin_count?这会消耗大量内存吗?
或
我保留行并让它累积并使用SELECT COUNT(*) all 来获取每个餐厅total_checkin_count?
编辑:user_checkins 表实际上存储了各种餐馆的所有用户签到,每次有人访问“restaurant_profile”网页时,SELECT COUNT(*) 查询将在user_checkins 表上运行res_id x,以获取total checkin count 那家餐厅,那是多余的吗?
【问题讨论】:
-
为什么不在单个表中只包含每个位置的运行总数和最后一个签到列?你真的需要知道他们何时登记入住吗?如果可以,可以存档吗?
-
每当有人访问 restaurant_profile 网页时,我将为 user_checkins 表(存储所有餐厅的签到)运行 SELECT COUNT(),这意味着每次有人访问 restaurant_profile 网页时, SELECT COUNT() 将在该表上运行,这是多余的吗?
标签: php mysql database database-design relational-database