Get the App
SLTechnology News&Howtos  ›  Database  › 

How to understand the mongodb execution plan

Shulou Source: shulou.com Published: 2022-05-31 14:37:05 09月29日 Update

This article introduces the relevant knowledge of "how to understand the mongodb implementation plan". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

= Mongodb concurrent batch kill session =

Concurrent, batch kill session

1. Drop all session kill with query time longer than 1000s.

Db.currentOp () .inprog.forEach (function (item) {if (item.secs_running > 1000 & & item.op = = "query") db.killOp (item.opid)})

2. Kill all jack.bear queries that contain collections

Db.currentOp () .inprog.forEach (function (item) {if (item.ns = = "jack.bear" & & item.op = = "query") db.killOp (item.opid)})

3. Kill the operations that meet the three conditions of item.op== "query" & & item.secs_running > 60 & & item.ns== "jack.bear".

Db.currentOp () .inprog.forEach (function (item) {if (item.waitingForLock) {var lock_info = item ["opid"]; if (item.op== "query" & & item.secs_running > 60 & & item.ns== "cswuyg.cswuyg") {db.killOp (item.opid)})

4. Kill the operations that meet the two conditions of item.op = = "query" & & item.secs_running > 1000

Db.currentOp () .inprog.forEach (function (item) {

Var lock_info = item ["opid"]

If (item.op = = "query" & & item.secs_running > 1000) {

Print ("kill", item.opid)

Db.killOp (item.opid)

}

})

# MongoDB execution Plan #

Stage classification

COLLSCAN: scan entire collection IXSCAN: index scan FETCH: retrieve and select document based on the index

SHARD_MERGE: merge the returned data of each shard

SORT: indicates that it is sorted in memory (consistent with the previous version of scanAndOrder:true)

LIMIT: use limit to limit the number of returns

SKIP: skip IDHACK with skip: check against _ id

SHARDING_FILTER: query sharded data through mongos

COUNT: use db.coll.explain (). Count () and the like for count

COUNTSCAN:count does not use the stage return when using Index for count

COUNT_SCAN:count returns SUBPLA from stage when using Index for count: stage return from $or query that does not use the index

TEXT: stage returns PROJECTION when querying with full-text index: limit the return of stage when fields are returned

= re-index =

Re-index:

Db.tableName.dropIndex ("indexName")

Db.tableName.ensureIndex ({"key1": 1, "key2": 1}, {"name": "indexName"}, {background:true})

Db.COLLECTION_NAME.ensureIndex ({"uuid":-1}, {background:true})

Db.COLLECTION_NAME.getIndexes ()

= = View execution plan = =

Db.collection_name.find ({}) .explain (true)

Specific query conditions should be set in find {} before the exact execution plan can be found.

When MongoDB looks at the execution plan, the ideal state is:-- 20180604

This is the end of "how to understand the mongodb implementation Plan". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Index query condition content data time more knowledge practical accurate consistent learned next full text memory dilemma fields reality situation article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Linux MariaDB Shulou Technology