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

Make distinct command on views use DISTINCT_SCAN

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization
    • ALL
    • Hide
      const coll = assertDropAndRecreateCollection(db, "coll");
      const viewName = "identityView";
      assert.commandWorked(db.createView(viewName, coll.getName(), []));
      assert.commandWorked(coll.createIndexes([{a: 1}]));
      
      // Performs DISTINCT_SCAN over 'a'.
      jsTestLog(coll.explain().distinct('a'));
      
      // Performs coll scan, while the rest of the work is done in agg.  jsTestLog(db[viewName].explain().distinct('a'));
      
      // Performs index scan on 'a', while the rest of the work is done in agg.
      jsTestLog(db[viewName].explain().distinct('a', {}, {hint: 'a_1'})); 
      Show
      const coll = assertDropAndRecreateCollection(db, "coll" ); const viewName = "identityView" ; assert .commandWorked(db.createView(viewName, coll.getName(), [])); assert .commandWorked(coll.createIndexes([{a: 1}])); // Performs DISTINCT_SCAN over 'a' . jsTestLog(coll.explain().distinct( 'a' )); // Performs coll scan, while the rest of the work is done in agg. jsTestLog(db[viewName].explain().distinct( 'a' )); // Performs index scan on 'a' , while the rest of the work is done in agg. jsTestLog(db[viewName].explain().distinct( 'a' , {}, {hint: 'a_1' }));

      While distinct command may generate DISTINCT_SCAN plans, it doesn't do so in the case of views (including identity views).

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            denis.grebennicov@mongodb.com Denis Grebennicov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: