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

Incorrect histogram CE of $type for int values

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization

      Histogram CE produces an incorrect estimate for 'int' values because it incorrectly determines that the type of the value is double and returns the counter for double instead of that for integer. The code in question (checked via GDB) is in 

      estimateCardinalityRangeViaTypeCounts()

      Test case:
       

      const collName = 'wrong_int_count';
      const coll = db[collName];
      coll.drop();
      coll.insertMany(Array.from({length: 9999}, (_, i) => {
          const doc = {mixed: 3.14};
          return doc;
      }));
      coll.insertMany(Array.from({length: 427}, (_, i) => {
          const doc = {mixed: i};
          return doc;
      }));
      coll.createIndexes([{mixed: 1}]);
      coll.runCommand({analyze: collName, key: "mixed", numberBuckets: 10});
      db.adminCommand({setParameter: 1, planRankerMode: "histogramCE"});
      coll.find({mixed: {$type: 'int'}}).count();
      coll.find({mixed: {$type: 'double'}}).count();
      coll.find({mixed: {$type: 'int'}}).explain().queryPlanner.winningPlan;
      coll.find({mixed: {$type: 'double'}}).explain().queryPlanner.winningPlan;
      

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            timour.katchaounov@mongodb.com Timour Katchaounov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: