Incorrect histogram CE of $type for int values

XMLWordPrintableJSON

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

      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
              Reporter:
              Timour Katchaounov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated: