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

delete_many(field: { $size: 0 }) does a full collection scan

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL

      Using MongoDB 7.0.11, I have the following index in my app:

       

      index tm: 1, x: 1, y: 1

       

      When I run the following, Mongo does a full collection scan:

       

      delete_many(tm: { $size: 0 }) 

      However when I run the following equivalent code, Mongo uses the index correctly:

      delete_many(tm: []) 

       

      Perhaps the $size: 0 case can be optimized?

      Here is the query dump of the slow query from Atlas:

      {
        "type": "remove",
        "ns": "xxx.yyy",
        "appName": "zzz",
        "command": {
          "q": {
            "tm": {
              "$size": 0
            }
          },
          "limit": 0
        },
        "planSummary": "COLLSCAN",
        "keysExamined": 0,
        "docsExamined": 205908,
        "ndeleted": 0,
        "numYields": 265,
        "locks": {
          "ParallelBatchWriterMode": {
            "acquireCount": {
              "r": 266
            }
          },
          "FeatureCompatibilityVersion": {
            "acquireCount": {
              "w": 266
            }
          },
          "ReplicationStateTransition": {
            "acquireCount": {
              "w": 266
            }
          },
          "Global": {
            "acquireCount": {
              "w": 266
            }
          },
          "Database": {
            "acquireCount": {
              "w": 266
            }
          },
          "Collection": {
            "acquireCount": {
              "w": 266
            }
          }
        },
        "flowControl": {
          "acquireCount": 266
        },
        "readConcern": {
          "level": "local",
          "provenance": "implicitDefault"
        },
        "storage": {},
        "cpuNanos": 395985914,
        "remote": "10.20.24.203:1501",
        "durationMillis": 7384,
        "v": "7.0.11",
        "isTruncated": false
      } 

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: