numbers集合里有2000个{"_id":XXXX, "num":XXX}这样的文档。执行如下查询语句
db.numbers.find({num:{"$gt":1995}}).explain("executionStats") //execution-stats 3.0以后新增的
输出以下:
{
"queryPlanner" : {
"plannerVersion" : 1.0,
"namespace" : "user.numbers",
"indexFilterSet" : false,
"parsedQuery" : {
"num" : {
"$gt" : 1995.0
}
},
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"num" : {
"$gt" : 1995.0
}
},
"direction" : "forward"
},
"rejectedPlans" : [
]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 4.0,
"executionTimeMillis" : 3.0, //执行时间
"totalKeysExamined" : 0.0, //整个扫描的索引数量
"totalDocsExamined" : 2000.0, //扫描的文档数量,没加索引就全表扫描的
"executionStages" : {
"stage" : "COLLSCAN",
"filter" : {
"num" : {
"$gt" : 1995.0
}
},
"nReturned" : 4.0,
"executionTimeMillisEstimate" : 0.0,
"works" : 2002.0,
"advanced" : 4.0,
"needTime" : 1997.0,
"needYield" : 0.0,
"saveState" : 15.0,
"restoreState" : 15.0,
"isEOF" : 1.0,
"invalidates" : 0.0,
"direction" : "forward",
"docsExamined" : 2000.0
}
},
"serverInfo" : {
"host" : "DESKTOP-ALJ721J",
"port" : 27017.0,
"version" : "4.0.1",
"gitVersion" : "54f1582fc6eb01de4d4c42f26fc133e623f065fb"
},
"ok" : 1.0
}
db.numbers.createIndex({num:1}) //创建索引
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1.0, //创建这个索引之前的索引数量
"numIndexesAfter" : 2.0, //现在的索引数量
"ok" : 1.0//是否成功
}
db.numbers.getIndexes()//获取该集合的索引信息
[
{
"v" : 2.0,
"key" : {
"_id" : 1.0 //自动创建的那个索引
},
"name" : "_id_",
"ns" : "user.numbers"
},
{
"v" : 2.0, //版本?
"key" : { //索引的key
"num" : 1.0
},
"name" : "num_1", //索引的名字
"ns" : "user.numbers" //namespace
}
]
再执行
db.numbers.find({num:{"$gt":1995}}).explain("executionStats")
{
"queryPlanner" : {
"plannerVersion" : 1.0,
"namespace" : "user.numbers",
"indexFilterSet" : false,
"parsedQuery" : {
"num" : {
"$gt" : 1995.0
}
},
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"num" : 1.0
},
"indexName" : "num_1", //使用的索引名字
"isMultiKey" : false,
"multiKeyPaths" : {
"num" : [
]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2.0,
"direction" : "forward",
"indexBounds" : {
"num" : [
"(1995.0, inf.0]"
]
}
}
},
"rejectedPlans" : [
]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 4.0,
"executionTimeMillis" : 1.0,
"totalKeysExamined" : 4.0, //四个索引
"totalDocsExamined" : 4.0, //扫描了4个文档
"executionStages" : {
"stage" : "FETCH",
"nReturned" : 4.0,
"executionTimeMillisEstimate" : 0.0,
"works" : 5.0,
"advanced" : 4.0,
"needTime" : 0.0,
"needYield" : 0.0,
"saveState" : 0.0,
"restoreState" : 0.0,
"isEOF" : 1.0,
"invalidates" : 0.0,
"docsExamined" : 4.0,
"alreadyHasObj" : 0.0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 4.0,
"executionTimeMillisEstimate" : 0.0,
"works" : 5.0,
"advanced" : 4.0,
"needTime" : 0.0,
"needYield" : 0.0,
"saveState" : 0.0,
"restoreState" : 0.0,
"isEOF" : 1.0,
"invalidates" : 0.0,
"keyPattern" : {
"num" : 1.0
},
"indexName" : "num_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"num" : [
]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2.0,
"direction" : "forward",
"indexBounds" : {
"num" : [
"(1995.0, inf.0]"
]
},
"keysExamined" : 4.0,
"seeks" : 1.0,
"dupsTested" : 0.0,
"dupsDropped" : 0.0,
"seenInvalidated" : 0.0
}
}
},
"serverInfo" : {
"host" : "DESKTOP-ALJ721J",
"port" : 27017.0,
"version" : "4.0.1",
"gitVersion" : "54f1582fc6eb01de4d4c42f26fc133e623f065fb"
},
"ok" : 1.0
}
db.stats()
{
"db" : "user",
"collections" : 2.0, //2个集合
"views" : 0.0,
"objects" : 2002.0, //2002个对象,就是2002个文档
"avgObjSize" : 35.14485514485514, // 平均对象大小
"dataSize" : 70360.0, //实际数据大小
"storageSize" : 81920.0, // 预留空间大小
"numExtents" : 0.0,
"indexes" : 3.0, //索引数量
"indexSize" : 81920.0, //索引大小:数据库性能只有在所有使用的索引都加载到内存里才是最好的。
"fsUsedSize" : 66884751360.0,
"fsTotalSize" : 214748364800.0,
"ok" : 1.0
}
db.numbers.stats()
{
"ns" : "user.numbers",
"size" : 70000.0,
"count" : 2000.0,
"avgObjSize" : 35.0,
"storageSize" : 45056.0,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1.0
},
"creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),assert=(commit_timestamp=none,read_timestamp=none),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=,ignore_in_memory_cache_size=false,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_custom=(prefix=,start_generation=0,suffix=),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:collection-2--5450386311258653606",
"LSM" : {
"bloom filter false positives" : 0.0,
"bloom filter hits" : 0.0,
"bloom filter misses" : 0.0,
"bloom filter pages evicted from cache" : 0.0,
"bloom filter pages read into cache" : 0.0,
"bloom filters in the LSM tree" : 0.0,
"chunks in the LSM tree" : 0.0,
"highest merge generation in the LSM tree" : 0.0,
"queries that could have benefited from a Bloom filter that did not exist" : 0.0,
"sleep for LSM checkpoint throttle" : 0.0,
"sleep for LSM merge throttle" : 0.0,
"total size of bloom filters" : 0.0
},
"block-manager" : {
"allocations requiring file extension" : 5.0,
"blocks allocated" : 5.0,
"blocks freed" : 0.0,
"checkpoint size" : 32768.0,
"file allocation unit size" : 4096.0,
"file bytes available for reuse" : 0.0,
"file magic number" : 120897.0,
"file major version number" : 1.0,
"file size in bytes" : 45056.0,
"minor version number" : 0.0
},
"btree" : {
"btree checkpoint generation" : 2570.0,
"column-store fixed-size leaf pages" : 0.0,
"column-store internal pages" : 0.0,
"column-store variable-size RLE encoded values" : 0.0,
"column-store variable-size deleted values" : 0.0,
"column-store variable-size leaf pages" : 0.0,
"fixed-record size" : 0.0,
"maximum internal page key size" : 368.0,
"maximum internal page size" : 4096.0,
"maximum leaf page key size" : 2867.0,
"maximum leaf page size" : 32768.0,
"maximum leaf page value size" : 67108864.0,
"maximum tree depth" : 3.0,
"number of key/value pairs" : 0.0,
"overflow pages" : 0.0,
"pages rewritten by compaction" : 0.0,
"row-store internal pages" : 0.0,
"row-store leaf pages" : 0.0
},
"cache" : {
"bytes currently in the cache" : 270581.0,
"bytes read into cache" : 0.0,
"bytes written from cache" : 78132.0,
"checkpoint blocked page eviction" : 0.0,
"data source pages selected for eviction unable to be evicted" : 0.0,
"eviction walk passes of a file" : 0.0,
"eviction walk target pages histogram - 0-9" : 0.0,
"eviction walk target pages histogram - 10-31" : 0.0,
"eviction walk target pages histogram - 128 and higher" : 0.0,
"eviction walk target pages histogram - 32-63" : 0.0,
"eviction walk target pages histogram - 64-128" : 0.0,
"eviction walks abandoned" : 0.0,
"eviction walks gave up because they restarted their walk twice" : 0.0,
"eviction walks gave up because they saw too many pages and found no candidates" : 0.0,
"eviction walks gave up because they saw too many pages and found too few candidates" : 0.0,
"eviction walks reached end of tree" : 0.0,
"eviction walks started from root of tree" : 0.0,
"eviction walks started from saved location in tree" : 0.0,
"hazard pointer blocked page eviction" : 0.0,
"in-memory page passed criteria to be split" : 0.0,
"in-memory page splits" : 0.0,
"internal pages evicted" : 0.0,
"internal pages split during eviction" : 0.0,
"leaf pages split during eviction" : 0.0,
"modified pages evicted" : 0.0,
"overflow pages read into cache" : 0.0,
"page split during eviction deepened the tree" : 0.0,
"page written requiring lookaside records" : 0.0,
"pages read into cache" : 0.0,
"pages read into cache after truncate" : 1.0,
"pages read into cache after truncate in prepare state" : 0.0,
"pages read into cache requiring lookaside entries" : 0.0,
"pages requested from the cache" : 2048.0,
"pages seen by eviction walk" : 0.0,
"pages written from cache" : 4.0,
"pages written requiring in-memory restoration" : 0.0,
"tracked dirty bytes in the cache" : 0.0,
"unmodified pages evicted" : 0.0
},
"cache_walk" : {
"Average difference between current eviction generation when the page was last considered" : 0.0,
"Average on-disk page image size seen" : 0.0,
"Average time in cache for pages that have been visited by the eviction server" : 0.0,
"Average time in cache for pages that have not been visited by the eviction server" : 0.0,
"Clean pages currently in cache" : 0.0,
"Current eviction generation" : 0.0,
"Dirty pages currently in cache" : 0.0,
"Entries in the root page" : 0.0,
"Internal pages currently in cache" : 0.0,
"Leaf pages currently in cache" : 0.0,
"Maximum difference between current eviction generation when the page was last considered" : 0.0,
"Maximum page size seen" : 0.0,
"Minimum on-disk page image size seen" : 0.0,
"Number of pages never visited by eviction server" : 0.0,
"On-disk page image sizes smaller than a single allocation unit" : 0.0,
"Pages created in memory and never written" : 0.0,
"Pages currently queued for eviction" : 0.0,
"Pages that could not be queued for eviction" : 0.0,
"Refs skipped during cache traversal" : 0.0,
"Size of the root page" : 0.0,
"Total number of pages currently in cache" : 0.0
},
"compression" : {
"compressed pages read" : 0.0,
"compressed pages written" : 3.0,
"page written failed to compress" : 0.0,
"page written was too small to compress" : 1.0,
"raw compression call failed, additional data available" : 0.0,
"raw compression call failed, no additional data available" : 0.0,
"raw compression call succeeded" : 0.0
},
"cursor" : {
"bulk-loaded cursor-insert calls" : 0.0,
"create calls" : 2.0,
"cursor operation restarted" : 0.0,
"cursor-insert key and value bytes inserted" : 73937.0,
"cursor-remove key bytes removed" : 0.0,
"cursor-update value bytes updated" : 0.0,
"cursors cached on close" : 0.0,
"cursors reused from cache" : 2004.0,
"insert calls" : 2000.0,
"modify calls" : 0.0,
"next calls" : 4103.0,
"prev calls" : 1.0,
"remove calls" : 0.0,
"reserve calls" : 0.0,
"reset calls" : 4045.0,
"search calls" : 14.0,
"search near calls" : 31.0,
"truncate calls" : 0.0,
"update calls" : 0.0
},
"reconciliation" : {
"dictionary matches" : 0.0,
"fast-path pages deleted" : 0.0,
"internal page key bytes discarded using suffix compression" : 5.0,
"internal page multi-block writes" : 0.0,
"internal-page overflow keys" : 0.0,
"leaf page key bytes discarded using prefix compression" : 0.0,
"leaf page multi-block writes" : 1.0,
"leaf-page overflow keys" : 0.0,
"maximum blocks required for a page" : 1.0,
"overflow values written" : 0.0,
"page checksum matches" : 0.0,
"page reconciliation calls" : 2.0,
"page reconciliation calls for eviction" : 0.0,
"pages deleted" : 0.0
},
"session" : {
"cached cursor count" : 2.0,
"object compaction" : 0.0,
"open cursor count" : 0.0
},
"transaction" : {
"update conflicts" : 0.0
}
},
"nindexes" : 2.0,
"totalIndexSize" : 65536.0,
"indexSizes" : {
"_id_" : 28672.0,
"num_1" : 36864.0
},
"ok" : 1.0
}