Navigation
This version of the documentation is archived and no longer supported.

indexStats

Definition

indexStats

The indexStats command aggregates statistics for the B-tree data structure that stores data for a MongoDB index.

Warning

This command is not intended for production deployments.

The command can be run only on a mongod instance that uses the --enableExperimentalIndexStatsCmd option.

To aggregate statistics, issue the command like so:

db.runCommand( { indexStats: "<collection>", index: "<index name>" } )

Output

The db.collection.indexStats() method and equivalent indexStats command aggregate statistics for the B-tree data structure that stores data for a MongoDB index. The commands aggregate statistics firstly for the entire B-tree and secondly for each individual level of the B-tree. The output displays the following values.

indexStats.index

The index name.

indexStats.version

The index version. For more information on index version numbers, see the v option in db.collection.ensureIndex().

indexStats.isIdIndex

If true, the index is the default _id index for the collection.

indexStats.keyPattern

The indexed keys.

indexStats.storageNs

The namespace of the index’s underlying storage.

indexStats.bucketBodyBytes

The fixed size, in bytes, of a B-tree bucket in the index, not including the record header. All indexes for a given version have the same value for this field. MongoDB allocates fixed size buckets on disk.

indexStats.depth

The number of levels in the B-tree, not including the root level.

indexStats.overall

This section of the output displays statistics for the entire B-tree.

indexStats.overall.numBuckets

The number of buckets in the entire B-tree, including all levels.

indexStats.overall.keyCount

Statistics about the number of keys in a bucket, evaluated on a per-bucket level.

indexStats.overall.usedKeyCount

Statistics about the number of used keys in a bucket, evaluated on a per-bucket level. Used keys are keys not marked as deleted.

indexStats.overall.bsonRatio

Statistics about the percentage of the bucket body that is occupied by the key objects themselves, excluding associated metadata.

For example, if you have the document { name: "Bob Smith" } and an index on { name: 1 }, the key object is the string Bob Smith.

indexStats.overall.keyNodeRatio

Statistics about the percentage of the bucket body that is occupied by the key node objects (the metadata and links pertaining to the keys). This does not include the key itself. In the current implementation, a key node’s objects consist of: the pointer to the key data (in the same bucket), the pointer to the record the key is for, and the pointer to a child bucket.

indexStats.overall.fillRatio

The sum of the bsonRatio and the keyNodeRatio. This shows how full the buckets are. This will be much higher for indexes with sequential inserts.

indexStats.perLevel

This section of the output displays statistics for each level of the B-tree separately, starting with the root level. This section displays a different document for each B-tree level.

indexStats.perLevel.numBuckets

The number of buckets at this level of the B-tree.

indexStats.perLevel.keyCount

Statistics about the number of keys in a bucket, evaluated on a per-bucket level.

indexStats.perLevel.usedKeyCount

Statistics about the number of used keys in a bucket, evaluated on a per-bucket level. Used keys are keys not marked as deleted.

indexStats.perLevel.bsonRatio

Statistics about the percentage of the bucket body that is occupied by the key objects themselves, excluding associated metadata.

indexStats.perLevel.keyNodeRatio

Statistics about the percentage of the bucket body that is occupied by the key node objects (the metadata and links pertaining to the keys).

indexStats.perLevel.fillRatio

The sum of the bsonRatio and the keyNodeRatio. This shows how full the buckets are. This will be much higher in the following cases:

  • For indexes with sequential inserts, such as the _id index when using ObjectId keys.
  • For indexes that were recently built in the foreground with existing data.
  • If you recently ran compact or --repair.

Example

The following is an example of db.collection.indexStats() and indexStats output.

{
    "index" : "type_1_traits_1",
    "version" : 1,
    "isIdIndex" : false,
    "keyPattern" : {
        "type" : 1,
        "traits" : 1
    },
    "storageNs" : "test.animals.$type_1_traits_1",
    "bucketBodyBytes" : 8154,
    "depth" : 2,
    "overall" : {
        "numBuckets" : 45513,
        "keyCount" : {
            "count" : NumberLong(45513),
            "mean" : 253.89602970579836,
            "stddev" : 21.784799875240708,
            "min" : 52,
            "max" : 290,
            "quantiles" : {
                "0.01" : 201.99785091648775,
                // ...
                "0.99" : 289.9999655156967
            }
        },
        "usedKeyCount" : {
            "count" : NumberLong(45513),
            // ...
            "quantiles" : {
                "0.01" : 201.99785091648775,
                // ...
                "0.99" : 289.9999655156967
            }
        },
        "bsonRatio" : {
            "count" : NumberLong(45513),
            // ...
            "quantiles" : {
                "0.01" : 0.4267797891997124,
                // ...
                "0.99" : 0.5945548174629648
            }
        },
        "keyNodeRatio" : {
            "count" : NumberLong(45513),
            // ...
            "quantiles" : {
                "0.01" : 0.3963656628236211,
                // ...
                "0.99" : 0.5690457993930765
            }
        },
        "fillRatio" : {
            "count" : NumberLong(45513),
            // ...
            "quantiles" : {
                "0.01" : 0.9909134214926929,
                // ...
                "0.99" : 0.9960755457453732
            }
        }
    },
    "perLevel" : [
        {
            "numBuckets" : 1,
            "keyCount" : {
                "count" : NumberLong(1),
                "mean" : 180,
                "stddev" : 0,
                "min" : 180,
                "max" : 180
            },
            "usedKeyCount" : {
                "count" : NumberLong(1),
                // ...
                "max" : 180
            },
            "bsonRatio" : {
                "count" : NumberLong(1),
                // ...
                "max" : 0.3619082658817758
            },
            "keyNodeRatio" : {
                "count" : NumberLong(1),
                // ...
                "max" : 0.35320088300220753
            },
            "fillRatio" : {
                "count" : NumberLong(1),
                // ...
                "max" : 0.7151091488839834
            }
        },
        {
            "numBuckets" : 180,
            "keyCount" : {
                "count" : NumberLong(180),
                "mean" : 250.84444444444443,
                "stddev" : 26.30057503009355,
                "min" : 52,
                "max" : 290
            },
            "usedKeyCount" : {
                "count" : NumberLong(180),
                // ...
                "max" : 290
            },
            "bsonRatio" : {
                "count" : NumberLong(180),
                // ...
                "max" : 0.5945548197203826
            },
            "keyNodeRatio" : {
                "count" : NumberLong(180),
                // ...
                "max" : 0.5690458670591121
            },
            "fillRatio" : {
                "count" : NumberLong(180),
                // ...
                "max" : 0.9963208241353937
            }
        },
        {
            "numBuckets" : 45332,
            "keyCount" : {
                "count" : NumberLong(45332),
                "mean" : 253.90977675813994,
                "stddev" : 21.761620836279018,
                "min" : 167,
                "max" : 290,
                "quantiles" : {
                    "0.01" : 202.0000012563603,
                    // ...
                    "0.99" : 289.99996486571894
                }
            },
            "usedKeyCount" : {
                "count" : NumberLong(45332),
                // ...
                "quantiles" : {
                    "0.01" : 202.0000012563603,
                    // ...
                    "0.99" : 289.99996486571894
                }
            },
            "bsonRatio" : {
                "count" : NumberLong(45332),
                // ...
                "quantiles" : {
                    "0.01" : 0.42678446958950583,
                    // ...
                    "0.99" : 0.5945548175411283
                }
            },
            "keyNodeRatio" : {
                "count" : NumberLong(45332),
                // ...
                "quantiles" : {
                    "0.01" : 0.39636988227885306,
                    // ...
                    "0.99" : 0.5690457981176729
                }
            },
            "fillRatio" : {
                "count" : NumberLong(45332),
                // ...
                "quantiles" : {
                    "0.01" : 0.9909246995605362,
                    // ...
                    "0.99" : 0.996075546919481
                }
            }
        }
    ],
    "ok" : 1
}

Additional Resources

For more information on the command’s limits and output, see the following:

←   top whatsmyuri  →