Uploaded image for project: 'PHP Legacy Driver'
  1. PHP Legacy Driver
  2. PHP-374

Sparse indexes not being used properly in count or find functions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Gone away
    • Affects Version/s: 1.2.10
    • Fix Version/s: None
    • Component/s: pecl-mongo
    • Environment:
      MongoDB 2.0.4
      CentOS 6 64
      PHP 5.3.3
      OpenVZ 2.6.32-042stab053.5
      Apache/2.2.15
      MongoDB Driver 1.2.10

    • # Replies:
      4
    • Last comment by Customer:
      true

      Description

      When running queries against sparse indexes using the PHP driver, performance is poor.

      For example, running this query against 30 million elements responds instantly, using the mongo shell:

      db.items.find(

      {'sparse_field' : 22 }

      ).explain()
      {
      "cursor" : "BtreeCursor sparse_field_1",
      "nscanned" : 322,
      "nscannedObjects" : 322,
      "n" : 322,
      "millis" : 0,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "isMultiKey" : false,
      "indexOnly" : false,
      "indexBounds" :

      { "sparse_field" : [ [ 22, 22 ] ] }

      }

      On the other hand, running this in PHP instead:
      $db->items->count(array('sparse_field' => 22));

      Will take about 15 seconds to run. Using find will crash after hitting the 30 seconds timeout.

      Using:
      $count = $db->execute("db.items.count(

      { 'sparse_field' : 22}

      );");
      Will return the result instantly.

      The group function doesn't seem affected, as I was able to use grouping with instant results as well.

      I have many indexes, so I have cut this to only show that it is sparse:

      db.items.getIndexes()
      {
      "v" : 1,
      "key" :

      { "_id" : 1 }

      ,
      "ns" : "stats.items",
      "name" : "id"
      },
      {
      "v" : 1,
      "key" :

      { "sparse_field" : 1 }

      ,
      "ns" : "stats.items",
      "name" : "sparse_field_1",
      "sparse" : true
      }
      }

      I marked this item as critical because it is not possible to use the find function on a sparse index on a large database without crashing.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                6 years, 22 weeks, 3 days ago
                Date of 1st Reply: