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

Query skips duplicate predicate

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 3.0.3
    • Querying
    • None
    • ALL
    • Hide

      Insert a document similar to this and run the query / explains outlined in the "Description".

      {
          "_id" : ObjectId("55a9adb08716e441387fbec6"),
          "batch_id" : "1437183404770",
          "create_date" : ISODate("2015-07-18T01:36:48.059Z"),
          "csv_fields" : {
              "phone1" : "1234567890",
              "deleted" : "0"
          },
          "status_records" : [ 
              {
                  "status" : "SKIPPED",
                  "date" : ISODate("2015-07-18T01:42:59.919Z"),
                  "notes" : [ 
                      "Marked as inactive", 
                      "Duplicate email", 
                      "\"clientpk\" not exported"
                  ]
              }, 
              {
                  "status" : "PENDING_PREPROCESSING",
                  "date" : ISODate("2015-07-18T01:36:48.059Z")
              }
          ]
      }
      

      Show
      Insert a document similar to this and run the query / explains outlined in the "Description". { "_id" : ObjectId("55a9adb08716e441387fbec6"), "batch_id" : "1437183404770", "create_date" : ISODate("2015-07-18T01:36:48.059Z"), "csv_fields" : { "phone1" : "1234567890", "deleted" : "0" }, "status_records" : [ { "status" : "SKIPPED", "date" : ISODate("2015-07-18T01:42:59.919Z"), "notes" : [ "Marked as inactive", "Duplicate email", "\"clientpk\" not exported" ] }, { "status" : "PENDING_PREPROCESSING", "date" : ISODate("2015-07-18T01:36:48.059Z") } ] }

    Description

      $size criteria is being skipped if an additional criteria with $eq is included.

      Given the following query:

      db.contacts.find({ "status_records.0.status": "SKIPPED",
                           "status_records.0.notes": { $size: 1 },
                           "status_records.0.notes": { $eq: "\"clientpk\" not exported" } })
      

      $size:1 is being excluded from the query, as can be seen by the generated plan:

      {
              "queryPlanner" : {
                      "plannerVersion" : 1,
                      "namespace" : "test.contacts",
                      "indexFilterSet" : false,
                      "parsedQuery" : {
                              "$and" : [
                                      {
                                              "status_records.0.notes" : {
                                                      "$eq" : "\"clientpk\" not exported"
                                              }
                                      },
                                      {
                                              "status_records.0.status" : {
                                                      "$eq" : "SKIPPED"
                                              }
                                      }
                              ]
                      },
                      "winningPlan" : {
                              "stage" : "KEEP_MUTATIONS",
                              "inputStage" : {
                                      "stage" : "FETCH",
                                      "filter" : {
                                              "status_records.0.notes" : {
                                                      "$eq" : "\"clientpk\" not exported"
                                              }
                                      },
                                      "inputStage" : {
                                              "stage" : "IXSCAN",
                                              "keyPattern" : {
                                                      "status_records.0.status" : 1
                                              },
                                              "indexName" : "status_records.0.status_1",
                                              "isMultiKey" : false,
                                              "direction" : "forward",
                                              "indexBounds" : {
                                                      "status_records.0.status" : [
                                                              "[\"SKIPPED\", \"SKIPPED\"]"
                                                      ]
                                              }
                                      }
                              }
                      },
                      "rejectedPlans" : [ ]
              },
              "serverInfo" : {
                      "host" : "localhost.localdomain",
                      "port" : 27017,
                      "version" : "3.0.3",
                      "gitVersion" : "b40106b36eecd1b4407eb1ad1af6bc60593c6105"
              },
              "ok" : 1
      }
      

      If I comment out the $eq criteria, there are no results (as would be expected) - here is it's plan:

      {
              "queryPlanner" : {
                      "plannerVersion" : 1,
                      "namespace" : "test.contacts",
                      "indexFilterSet" : false,
                      "parsedQuery" : {
                              "$and" : [
                                      {
                                              "status_records.0.notes" : {
                                                      "$size" : 1
                                              }
                                      },
                                      {
                                              "status_records.0.status" : {
                                                      "$eq" : "SKIPPED"
                                              }
                                      }
                              ]
                      },
                      "winningPlan" : {
                              "stage" : "KEEP_MUTATIONS",
                              "inputStage" : {
                                      "stage" : "FETCH",
                                      "filter" : {
                                              "status_records.0.notes" : {
                                                      "$size" : 1
                                              }
                                      },
                                      "inputStage" : {
                                              "stage" : "IXSCAN",
                                              "keyPattern" : {
                                                      "status_records.0.status" : 1
                                              },
                                              "indexName" : "status_records.0.status_1",
                                              "isMultiKey" : false,
                                              "direction" : "forward",
                                              "indexBounds" : {
                                                      "status_records.0.status" : [
                                                              "[\"SKIPPED\", \"SKIPPED\"]"
                                                      ]
                                              }
                                      }
                              }
                      },
                      "rejectedPlans" : [ ]
              },
              "serverInfo" : {
                      "host" : "localhost.localdomain",
                      "port" : 27017,
                      "version" : "3.0.3",
                      "gitVersion" : "b40106b36eecd1b4407eb1ad1af6bc60593c6105"
              },
              "ok" : 1
      }
      

      Attachments

        Activity

          People

            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            scardis Steve Ardis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: