Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-12287

Query containing $regex operator: performance regression

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.5
    • Affects Version/s: 2.5.4
    • Component/s: Performance, Querying
    • Labels:
    • Environment:
      Linux ip-10-0-0-15 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

      Some queries using $regex operator (e.g. "starts with") are slower in 2.6 than in 2.4. This has been noticeable on the mongo-perf suite regex test.
      $explain suggests the number of scanned objects for all the query plans in 2.6 is double than in 2.4.

      > for (var i=0; i < 1000;++i) { db.goo.insert({"_id":i.toString()}); }
      Insert WriteResult({ "ok" : 1, "n" : 1 })
      > db.goo.find( { "_id": { $regex: "^1" }}).explain()
      

      $explain output for 2.4.8

      {
              "cursor" : "BtreeCursor _id_ multi",
              "isMultiKey" : false,
              "n" : 111,
              "nscannedObjects" : 111,
              "nscanned" : 112,
              "nscannedObjectsAllPlans" : 111,
              "nscannedAllPlans" : 112,
              "scanAndOrder" : false,
              "indexOnly" : false,
              "nYields" : 0,
              "nChunkSkips" : 0,
              "millis" : 0,
              "indexBounds" : {
                      "_id" : [
                              [
                                      "1",
                                      "2"
                              ],
                              [
                                      /^1/,
                                      /^1/
                              ]
                      ]
              },
              "server" : "ip-10-0-0-15:27017"
      }
      

      $explain output for trunk (hash 5432e4836aec87fe9b53efe19d3bfff90ef0f6ef)

      {
              "cursor" : "BtreeCursor _id_",
              "isMultiKey" : false,
              "n" : 111,
              "nscannedObjects" : 111,
              "nscanned" : 112,
              "nscannedObjectsAllPlans" : 210,
              "nscannedAllPlans" : 211,
              "scanAndOrder" : false,
              "indexOnly" : false,
              "nYields" : 1,
              "nChunkSkips" : 0,
              "millis" : 0,
              "indexBounds" : {
                      "_id" : [
                              [
                                      "1",
                                      "2"
                              ],
                              [
                                      /^1/,
                                      /^1/
                              ]
                      ]
              },
              "server" : "ip-10-0-0-15:27017"
      }
      

            Assignee:
            davide.italiano Davide Italiano
            Reporter:
            davide.italiano Davide Italiano
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: