count on indexed field are very slow

38 views
Skip to first unread message

li ning

unread,
Jan 8, 2018, 5:16:27 AM1/8/18
to mongodb-user
mongodb version 3.2

collection info:

{
"sharded" : false,
"primary" : "cmgo-mm0g8irt_0",
"ns" : "log.quest",
"count" : 3914521,
"size" : 274016470,
"avgObjSize" : 70,
"storageSize" : 129208320,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
"creationString" : "allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
"type" : "file",
"uri" : "statistics:table:log/collection-90--923250816215833925",
"LSM" : {
"bloom filter false positives" : 0,
"bloom filter hits" : 0,
"bloom filter misses" : 0,
"bloom filter pages evicted from cache" : 0,
"bloom filter pages read into cache" : 0,
"bloom filters in the LSM tree" : 0,
"chunks in the LSM tree" : 0,
"highest merge generation in the LSM tree" : 0,
"queries that could have benefited from a Bloom filter that did not exist" : 0,
"sleep for LSM checkpoint throttle" : 0,
"sleep for LSM merge throttle" : 0,
"total size of bloom filters" : 0
},
"block-manager" : {
"allocations requiring file extension" : 10754,
"blocks allocated" : 10848,
"blocks freed" : 103,
"checkpoint size" : 129093632,
"file allocation unit size" : 4096,
"file bytes available for reuse" : 188416,
"file magic number" : 120897,
"file major version number" : 1,
"file size in bytes" : 129208320,
"minor version number" : 0
},
"btree" : {
"btree checkpoint generation" : 7647,
"column-store fixed-size leaf pages" : 0,
"column-store internal pages" : 0,
"column-store variable-size RLE encoded values" : 0,
"column-store variable-size deleted values" : 0,
"column-store variable-size leaf pages" : 0,
"fixed-record size" : 0,
"maximum internal page key size" : 368,
"maximum internal page size" : 4096,
"maximum leaf page key size" : 2867,
"maximum leaf page size" : 32768,
"maximum leaf page value size" : 67108864,
"maximum tree depth" : 4,
"number of key/value pairs" : 0,
"overflow pages" : 0,
"pages rewritten by compaction" : 0,
"row-store internal pages" : 0,
"row-store leaf pages" : 0
},
"cache" : {
"bytes currently in the cache" : 68558525,
"bytes read into cache" : 1485804703694,
"bytes written from cache" : 302952787,
"checkpoint blocked page eviction" : 0,
"data source pages selected for eviction unable to be evicted" : 2723,
"hazard pointer blocked page eviction" : 504,
"in-memory page passed criteria to be split" : 114,
"in-memory page splits" : 57,
"internal pages evicted" : 1124,
"internal pages split during eviction" : 1,
"leaf pages split during eviction" : 64,
"modified pages evicted" : 144,
"overflow pages read into cache" : 0,
"overflow values cached in memory" : 0,
"page split during eviction deepened the tree" : 1,
"page written requiring lookaside records" : 0,
"pages read into cache" : 52059749,
"pages read into cache requiring lookaside entries" : 0,
"pages requested from the cache" : 1669136039,
"pages written from cache" : 10805,
"pages written requiring in-memory restoration" : 0,
"unmodified pages evicted" : 52065187
},
"compression" : {
"compressed pages read" : 52058622,
"compressed pages written" : 10608,
"page written failed to compress" : 0,
"page written was too small to compress" : 197,
"raw compression call failed, additional data available" : 0,
"raw compression call failed, no additional data available" : 0,
"raw compression call succeeded" : 0
},
"cursor" : {
"bulk-loaded cursor-insert calls" : 0,
"create calls" : 680,
"cursor-insert key and value bytes inserted" : 289592189,
"cursor-remove key bytes removed" : 0,
"cursor-update value bytes updated" : 0,
"insert calls" : 3914521,
"next calls" : 19577463,
"prev calls" : 1,
"remove calls" : 0,
"reset calls" : 43171873,
"restarted searches" : 0,
"search calls" : 3322824344,
"search near calls" : 152946,
"truncate calls" : 0,
"update calls" : 0
},
"reconciliation" : {
"dictionary matches" : 0,
"fast-path pages deleted" : 0,
"internal page key bytes discarded using suffix compression" : 11516,
"internal page multi-block writes" : 20,
"internal-page overflow keys" : 0,
"leaf page key bytes discarded using prefix compression" : 0,
"leaf page multi-block writes" : 72,
"leaf-page overflow keys" : 0,
"maximum blocks required for a page" : 2,
"overflow values written" : 0,
"page checksum matches" : 1301,
"page reconciliation calls" : 211,
"page reconciliation calls for eviction" : 44,
"pages deleted" : 0
},
"session" : {
"object compaction" : 0,
"open cursor count" : 7
},
"transaction" : {
"update conflicts" : 0
}
},
"nindexes" : 3,
"totalIndexSize" : 127320064,
"indexSizes" : {
"_id_" : 39694336,
"s_1_r_1_d_1" : 29474816,
"d_1_s_1_st_1_i_1" : 58150912
},
"ok" : 1
}

index:
/* 1 */ { "v" : NumberInt("1"), "key" : { "_id" : NumberInt("1") }, "name" : "_id_", "ns" : "log.quest" }, /* 2 */ { "v" : NumberInt("1"), "key" : { "s" : NumberInt("1"), "r" : NumberInt("1"), "d" : NumberInt("1") }, "name" : "s_1_r_1_d_1", "ns" : "log.quest" }, /* 3 */ { "v" : NumberInt("1"), "key" : { "d" : NumberInt("1"), "s" : NumberInt("1"), "st" : NumberInt("1"), "i" : NumberInt("1") }, "name" : "d_1_s_1_st_1_i_1", "ns" : "log.quest" }

count
db.quest.count({i:10021,st:1,s:10001,d:{$gte:new Date("2017-11-1 00:00:00"),$lte:new Date("2017-11-28 23:59:59")}}) consume 12 seconds
count with hint
db.quest.count({i:10021,st:1,s:10001,d:{$gte:new Date("2017-11-1 00:00:00"),$lte:new Date("2017-11-28 23:59:59")}},{hint:"d_1_s_1_st_1_i_1"}) consume 7 seconds

why the count is so slow?

Rhys Campbell

unread,
Jan 9, 2018, 2:56:24 AM1/9/18
to mongodb-user
Reply all
Reply to author
Forward
0 new messages