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

histogramCE: $in, $nin, $or not estimated without an index

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • ALL
    • Hide
      db.foo.drop();
      
      let docs = [];
      for (let i = 0; i < 50; i++) {
          docs.push({a: i});
      }
      
      
      db.foo.insertMany(docs);
      db.foo.runCommand({analyze: "foo", key: "a"});
      db.adminCommand({setParameter: 1, planRankerMode: "histogramCE"});
      db.foo.find({a: {$in: [1,2]}}).count();
      db.foo.find({a: {$in: [1,2]}}).explain().queryPlanner.winningPlan.cardinalityEstimate;
      
      Show
      db.foo.drop(); let docs = []; for (let i = 0; i < 50; i++) { docs.push({a: i}); } db.foo.insertMany(docs); db.foo.runCommand({analyze: "foo" , key: "a" }); db.adminCommand({setParameter: 1, planRankerMode: "histogramCE" }); db.foo.find({a: {$in: [1,2]}}).count(); db.foo.find({a: {$in: [1,2]}}).explain().queryPlanner.winningPlan.cardinalityEstimate;

      $in, $nin, $or are not estimated with histogramCE, they fall back to heuristicCS.

      The same predicates are correctly estimated with an index, therefore there is no obvious reason that prevents them from being estimated without one – the information in the histograms should be sufficient. In all cases, a single column is involved, therefore the estimate of the $in should be the sum of the cardinalities of its constituent values.

            Assignee:
            timour.katchaounov@mongodb.com Timour Katchaounov
            Reporter:
            philip.stoev@mongodb.com Philip Stoev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: