2
我有一個SQL查詢在那裏我算select count(*)錯誤的結果,緩存還是什麼?
SELECT count(*) AS `nr` FROM `ordine` WHERE (ditta_id = '3') AND (YEAR(`data`) = '2012') AND (stato = 'approvato' or stato = 'consegnato') LIMIT 1
我更新了一些列改變stato到「approvato」的行數,有時數()給了我正確的號碼,有時它給我的老字號
這裏是我的一塊日誌:
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是指標
我使用ž最終框架1.11.11和MySQL 5.1.49-3
您是不是要改變已經符合計數標準的行的值?你沒有顯示足夠的信息來真正評估這一點。 – dldnh 2012-03-26 09:48:37
http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/ – Vytautas 2012-03-26 09:50:12
@Vytautas - 兩個查詢都有'COUNT(*)',所以相同的行爲由NULL或NOT NULL沒有區別。 – MatBailie 2012-03-26 10:03:55