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

$or queries only produce collscan for clustered collections

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • QI 2023-05-29, QI 2023-06-12

      The following code will execute a COLLSCAN.

      db.createCollection("c", { clusteredIndex: { key: { _id: 1 }, unique: true } }));
      db.c.createIndex({ a: 1 }); 
      db.c.insert({ b: "foo", a: 1, c: 2 });
      db.c.explain().find({ $or: [{ _id: 123 }, { a: 5 }] }).finish();  

      However, a better plan would be a OR stage with a CLUSTERED_IXSCAN and a IXSCAN stage. Currently, CLUSTERED_IXSCAN plans are not considered when we subplan the children of $or queries. We only try IXSCAN for the children and miss out on better plans. This will also address the bug in SERVER-61259. If we can support CLUSTERED_IXSCAN in the children of $or queries then we can support $text queries under $or, since we will not need to fallback on a collection scan.

            Assignee:
            gil.alon@mongodb.com Gil Alon
            Reporter:
            gil.alon@mongodb.com Gil Alon
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: