目前我使用UPDATE pages SET hits = hits+1 WHERE id=:id
PDO 来增加页面点击量,但在分析脚本时,它平均需要 30 毫秒到 65 毫秒来更新。
是否有更快的增量方法,hits
也是表中的一个索引:这是一个示例转储:
[queries] => Array
(
[0] => Array
(
[sql] => SELECT * FROM `settings`
[time] => 0.22602081298828
)
[1] => Array
(
[sql] => SELECT * FROM `menu_links` WHERE `active`="1" ORDER BY position ASC
[time] => 0.2291202545166
)
[2] => Array
(
[sql] => SELECT * FROM `pages` WHERE `url`=:field AND active='1'
[time] => 0.27203559875488
)
[3] => Array
(
[sql] => SELECT * FROM `pages` WHERE `menu_link`=:field AND active='1'
[time] => 0.24008750915527
)
[4] => Array
(
[sql] => UPDATE pages SET hits = hits+1 WHERE id=:id
[time] => 31.989107131958
)
)
更新
似乎使用 LIMIT 1 子句加快了 10-15 毫秒
[4] => Array
(
[sql] => UPDATE `pages` SET hits = hits+1 WHERE id=1 LIMIT 1
[time] => Between 15 & 25ms
)
使用 LOW_PRIORITY
[4] => Array
(
[sql] => UPDATE LOW_PRIORITY `pages` SET hits = hits+1 WHERE id=1 LIMIT 1
[time] => Between 17 & 30ms
)