选择count(*)错误的结果,缓存还是什么?

时间:2012-03-26 09:41:39

标签: mysql sql zend-framework

我有一个SQL查询,其中我计算行数

SELECT count(*) AS `nr` FROM `ordine` WHERE (ditta_id = '3') AND (YEAR(`data`) = '2012') AND (stato = 'approvato' or stato = 'consegnato') LIMIT 1

我将一些行更改stato更新为'approvato',有时count()给我正确的数字,有时它给我旧数字

这是我的日志:

2012-03-23T10:42:45+01:00 DEBUG (7): Row id = 1809
2012-03-23T10:42:45+01:00 DEBUG (7): SELECT count(*) AS `nr` FROM `ordine` WHERE (ditta_id = '3') AND (YEAR(`data`) = '2012') AND (stato = 'approvato' or stato = 'consegnato') LIMIT 1
2012-03-23T10:42:45+01:00 DEBUG (7): Result = 140
...change stato into 'approvato' thus count must give me 141 next time, requery the row, check changes are saved


2012-03-23T10:44:52+01:00 DEBUG (7): Row id = 1810
2012-03-23T10:44:52+01:00 DEBUG (7): SELECT count(*) AS `nr` FROM `ordine` WHERE (ditta_id = '3') AND (YEAR(`data`) = '2012') AND (stato = 'approvato' or stato = 'consegnato') LIMIT 1
2012-03-23T10:44:52+01:00 DEBUG (7): Result = 140 ?!!! why not 141?

ditta_id,agente_id,stato是索引

我正在使用Zend Framework 1.11.11和MySQL 5.1.49-3

1 个答案:

答案 0 :(得分:3)

对于您更新的行,我假设以下其中一项是真的......

  • ditta_id不是'3'
  • YEAR(data)不是'2012'
  • stato已经'approvato'
  • stato已经'consegnato'
  • stato中的新值有拼写错误

您是否可以在更改stato字段之前和之后向我们显示这些字段?