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

Avoid a scan of either IDX or a collection if the filter is $alwaysFalse:

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • QO 2023-10-16, QO 2023-10-30, QO 2023-11-13, QO 2023-11-27
    • 56

      For the case that a find() has an $alwaysFalse: 1 condition (after Boolean optimization) the query should not be inspecting any documents at all. Instead the planner should generate a plan returning an empty set. The corresponding test is:

      db.test.drop();
      var explain = db.test.find({$alwaysFalse: 1}).explain("executionStats");
      assert.eq(0, explain.executionStats.totalDocsExamined, explain);
      db.test.insert({a: 1});
      var explain = db.test.find({$alwaysFalse: 1}).explain("executionStats");
      assert.eq(0, explain.executionStats.totalDocsExamined, explain);

       

            Assignee:
            c.alonso@mongodb.com Carlos Alonso Pérez
            Reporter:
            peter.volk@mongodb.com Peter Volk
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: