2012-05-08 37 views
1

這是一個有點怪異的。 我正在遍歷相當大的數據庫,使用查詢來檢查某些元素是否存在。在沒有提示的情況下在數據庫中運行這個查詢大約需要137秒,但是提示下降到0(這是更好的)。當通過PHPMongoDB提示似乎不起作用

$collection->find($params)->hint(array("responses" => 1))->count(); 

使用它和分析查詢我得到這樣的:

{ 「TS」:ISODate( 「2012-05-08T10:11:24.682Z」),「 op「:」command「,」ns「: 」ey_gsat。$ cmd「,」command「:{」count「:」survey_answers「,」query「:{ 」respond.93「:{」$ exists「 true「,」respond.96「:{」$ exists「: true},」respond.99「:{」$ exists「:true},」102「:{ 」$ exists「:true}, 「response.105」:{「$ exists」:true}, 「responses.108」:{「$ exists」:true},「r 「response」.11「」:{「$ exists」 :true},「responses.114」:{「$ exists」:true},「respond.117」:{ 「$ exists」:true},「responses.120 「:{」$ exists「:true}, 」responses.1「:{」$ exists「:true}}},」ntoreturn「:1, 」responseLength「:48,」millis「:137,」client 「:‘127.0.0.1’,‘用戶’ :‘’}

有當通過PHP運行實際使用索引沒有查詢的跡象。我在這個網站上有很多像這樣的查詢,所以137毫秒都加起來,因此我想優化它們。任何想法可能是錯誤的?

+0

我只能說*** ***新技術*** – Petah

+1

PHP驅動程序故意去掉提示,這是否在shell中工作? – kristina

+0

我仔細檢查了所有的場景,並且儘可能多的提示似乎加快了平常的查詢查詢,只要我添加count它會忽略索引。是期望的行爲?有什麼方法可以利用索引來加速我的計算嗎? –

回答

0

這是一個已知的計數限制:https://jira.mongodb.org/browse/SERVER-2677。您可能想要關注/投票處理該問題。不幸的是,沒有解決方法。您可能希望儘可能查看緩存計數或估計總數。

+0

非常感謝! –