There are few thousand product listings on the site.
网站上有几千种产品清单。
The goal is to store updated listing information for each product (views/likes/etc) in MySql Database ever 15 mins or so while keeping previous results as well.
目标是在15分钟左右的时间内在MySql数据库中存储每个产品(视图/喜欢/等)的更新列表信息,同时保留以前的结果。
This data will be used to show charts with the ability to display hourly, daily, weekly and so on stats.
此数据将用于显示能够显示每小时,每日,每周等统计数据的图表。
The question is, what is the most efficient way to store this data in mysql table?
问题是,在mysql表中存储这些数据的最有效方法是什么?
There are two approaches that I can think of:
我能想到两种方法:
1) Store each 15-min update as a separate record and then retrieve a data range when needed. The problem with this is that this table can quickly escalate into multi-million table which doesn't seem that efficient at all.
1)将每个15分钟的更新存储为单独的记录,然后在需要时检索数据范围。这个问题是这个表可以迅速升级到数百万的表,这看起来根本没有效率。
2) For each 15-min update append required data (views/likes/etc) to the end of existing data string in corresponding columns, and then on retrieval explode that string into array. Since there would be no ranges I could store last updates data stamp and calculate ranges from there. The problem with this it could be less reliable and data strings will grow big overtime as well.
2)对于每个15分钟的更新,将所需数据(views / likes / etc)附加到相应列中现有数据字符串的末尾,然后在检索时将该字符串分解为数组。由于没有范围,我可以存储最后更新数据标记并从那里计算范围。这个问题可能不太可靠,数据串也会随着时间的推移而增长。
Thanks in advance!
提前致谢!
1 个解决方案
#1
0
Solution one is by far the better answer. Don't worry about how many rows are created. For some reason people get obsessed over how many rows tables have. The latter answer you will be violating database normalization by storing multiple values in a single record.
解决方案一是迄今为止更好的答案。不要担心创建了多少行。出于某种原因,人们会对表中有多少行感到困惑。后者的答案是,您将通过在单个记录中存储多个值来违反数据库规范化。
#1
0
Solution one is by far the better answer. Don't worry about how many rows are created. For some reason people get obsessed over how many rows tables have. The latter answer you will be violating database normalization by storing multiple values in a single record.
解决方案一是迄今为止更好的答案。不要担心创建了多少行。出于某种原因,人们会对表中有多少行感到困惑。后者的答案是,您将通过在单个记录中存储多个值来违反数据库规范化。