Giter Club home page Giter Club logo

Comments (1)

smallnewer avatar smallnewer commented on September 23, 2024

关于查询

测试1中的数据用来查询

db.a.find({jjc:{$gt:910000}}).explain()

结果:

/* 0 */
{
    "cursor" : "BtreeCursor jjc_1",
    "isMultiKey" : false,
    "n" : 90000,
    "nscannedObjects" : 90000,
    "nscanned" : 90000,
    "nscannedObjectsAllPlans" : 90000,
    "nscannedAllPlans" : 90000,
    "scanAndOrder" : false,
    "indexOnly" : false,
    "nYields" : 703,
    "nChunkSkips" : 0,
    "millis" : 65,
    "indexBounds" : {
        "jjc" : [ 
            [ 
                910000, 
                Infinity
            ]
        ]
    },
    "server" : "xxx:27017",
    "filterSet" : false,
    "stats" : {
        "type" : "FETCH",
        "works" : 90001,
        "yields" : 703,
        "unyields" : 703,
        "invalidates" : 0,
        "advanced" : 90000,
        "needTime" : 0,
        "needFetch" : 0,
        "isEOF" : 1,
        "alreadyHasObj" : 0,
        "forcedFetches" : 0,
        "matchTested" : 0,
        "children" : [ 
            {
                "type" : "IXSCAN",
                "works" : 90000,
                "yields" : 703,
                "unyields" : 703,
                "invalidates" : 0,
                "advanced" : 90000,
                "needTime" : 0,
                "needFetch" : 0,
                "isEOF" : 1,
                "keyPattern" : "{ jjc: 1 }",
                "isMultiKey" : 0,
                "boundsVerbose" : "field #0['jjc']: (910000.0, inf.0]",
                "yieldMovedCursor" : 0,
                "dupsTested" : 0,
                "dupsDropped" : 0,
                "seenInvalidated" : 0,
                "matchTested" : 0,
                "keysExamined" : 90000,
                "children" : []
            }
        ]
    }
}

当调整$gt大小时,发现n系列的都在变,符合条件的越多,n系列字段就越大,最终,总耗时mills就越大。以下是有意思的耗时

> var s = Date.now();db.a.find({jjc:{$gt:310000}});Date.now()-s;
1
> var s = Date.now();db.a.find({jjc:{$gt:110000}});Date.now()-s;
0
> var s = Date.now();db.a.find({jjc:{$gt:710000}});Date.now()-s;
0
> var s = Date.now();db.a.find({jjc:{$gt:110000}}).explain();Date.now()-s;
1816
> var s = Date.now();db.a.find({jjc:{$gt:310000}}).explain();Date.now()-s;
1378
> var s = Date.now();db.a.find({jjc:{$gt:710000}}).explain();Date.now()-s;
617
> var s = Date.now();db.a.find({jjc:{$gt:110000}}).count();Date.now()-s;
222
> var s = Date.now();db.a.find({jjc:{$gt:110000}}).count();Date.now()-s;
128
> var s = Date.now();db.a.find({jjc:{$gt:110000}}).count();Date.now()-s;
128
> var s = Date.now();db.a.find({jjc:{$gt:310000}}).count();Date.now()-s;
107
> var s = Date.now();db.a.find({jjc:{$gt:710000}}).count();Date.now()-s;
45
> 

发现结果的多少会影响count的耗时,90W的时候,count耗时就已经达到100ms了。

from bugs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.