Note that there are some explanatory texts on larger screens.

plurals
  1. POIndex scan performance degradation when searching for higher values
    primarykey
    data
    text
    <p>My data set consists of documents containing a field with an array of integers. When i'm counting on objects whose field contains elements from some range it seems that index scan performance decreases with higher values indexBounds (but the same amount of values scanned by the range).</p> <p>Test data:</p> <pre><code>for (var i = 0; i &lt; 100000; i++) db.foo.insert({tts:(function(){var val = [];for(var j = 0; j &lt; 100; j++) {val[j] = j} return val;})()}); db.foo.ensureIndex({tts:1}); </code></pre> <p>Queries:</p> <pre><code>&gt; db.foo.find({tts:{$elemMatch:{$gte:10, $lte:10}}}).explain() { "cursor" : "BtreeCursor tts_1", "isMultiKey" : true, "n" : 100000, "nscannedObjects" : 100000, "nscanned" : 100000, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 1, "nChunkSkips" : 0, "millis" : 313, "indexBounds" : { "tts" : [ [ 10, 10 ] ] }, "server" : "localhost:27017" } &gt; db.foo.find({tts:{$elemMatch:{$gte:90, $lte:90}}}).explain() { "cursor" : "BtreeCursor tts_1", "isMultiKey" : true, "n" : 100000, "nscannedObjects" : 100000, "nscanned" : 100000, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 1, "nChunkSkips" : 0, "millis" : 1286, "indexBounds" : { "tts" : [ [ 90, 90 ] ] }, "server" : "localhost:27017" } </code></pre> <p>In fact I have near 200 values in this field and query gets up to 10 times slower when the requested range have the highest boundaries. (Each value in the field belongs to a unique range, all ranges select the same amount of objects (100000), querying is performed only for subranges of this ranges)</p> <p>Collection stats:</p> <pre><code>&gt; db.foo.stats() { "ns" : "test.foo", "count" : 100000, "size" : 122400128, "avgObjSize" : 1224.00128, "storageSize" : 140763136, "numExtents" : 12, "nindexes" : 2, "lastExtentSize" : 40071168, "paddingFactor" : 1, "systemFlags" : 1, "userFlags" : 0, "totalIndexSize" : 254845920, "indexSizes" : { "_id_" : 3262224, "tts_1" : 251583696 }, "ok" : 1 } </code></pre> <p>Is there a workaround for this problem?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload