我需要跟踪表中每一行被查询的次数。我需要在很多表上这样做。
一种想法是"search_count“列
id | other data ... | search_count
1 | ... | 12
2 | ... | 90有没有比设置“搜索计数”列更有效的方法呢?我知道这会起作用,但它给了我一种糟糕的“代码气味”,因为我必须在每次查询(或触发器?)之后进行更新。我们将尽可能多地使用Piwik或Google Analytics,但它们不会完全准确,因为我们不仅仅有web服务器连接数据库。
该数据库是MySQL 5.x
谢谢
发布于 2011-06-15 07:59:15
在动态数据库中这样做会产生太多的死行……
并使用cron每天或每小时存储结果。
要计数的伪代码:
$ns = $memcache->get('count_ns');
$memcache->increment("count-$ns-$table-$id");在cron上:
$ns = $memcache->get('count_ns');
sleep(1); // allow processes to finish
$memcache->increment('count_ns');
while ($row = $rows->next()) {
if ($count = $memcache->get("count-$ns-$table-$id") {
// increment count
}
}https://stackoverflow.com/questions/6351247
复制相似问题