Index Creation at mongoDB

Wissenswertes
2 Kommentare

Leider nur auf Englisch verfügbar.

Vorheriger Beitrag
32. Wispri: Test-Automatisierung – verdammt wertvoll
Nächster Beitrag
33. Wispri: Die Revolution der Aufgaben

Related Posts

2 Kommentare. Hinterlasse eine Antwort

The {price:1, date:1} index could be used if you had an exact match on price rather than a range. Something like find({color:’red’}).sort({date:-1}) would be a good example. The issue is that the index can be used for sorting or selecting but not both, unless they are on the same field. The index can only be used for sorting if given a start point and an end point reading the index (conceptually like a sorted list) would yield documents in the correct order. In your example finding all objects with prices between 500 and 1500, they would not read be in the date order with a {price:1, date:1} index.

Things to look for in explain output:

1)$minkey/$maxkey ranges: This means that the index is not being used for queries on this field. If this is the first field in the index that means we are doing a table scan.

2) scanAndOrder: This means that the index is not being used for sorting. This is not terrible if there is a small limit and the query only matches a few objects. The runtime to find the top-k (top-30 here) objects out of n results is about n * log(k).

Hopefully that helps clear things up. Please get in touch if you have further questions.

Antworten

Thanks Mathias for clarification. In the mongodb user group I posted another issue I came across when working on that example. It’s the performance of the count() operation.

Please check http://groups.google.com/group/mongodb-user/browse_thread/thread/f1a14d9096ed0c5d for that.

To put it short: The count() command on a query takes very long time if there’s a huge dataset behind, for the case that the number returned is very big (in my example it was about 400,000 of 500,000), even if there is an index on that field.

Is that reasonable or am I doing something wrong? Unfortunately I can’t view explain() on count()…

Antworten

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Bitte füllen Sie dieses Feld aus
Bitte füllen Sie dieses Feld aus
Bitte gib eine gültige E-Mail-Adresse ein.
Sie müssen den Bedingungen zustimmen, um fortzufahren

Menü