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

[HistCE] Negation, $type estimated incorrectly if multiple data types are present together

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • QO 2025-02-03
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      If the dataset contains two different number types and the predicate contains a string literal, negation is estimated incorrectly:

       

      
      db.foo.drop();
      let number_docs = [];
      number_docs.push({a: 1});
      number_docs.push({a: 2.5});
      db.foo.insert(number_docs);
      db.foo.createIndex({a:1});
      db.foo.runCommand({analyze: "foo", key: "a"});
      db.foo.find({  "a" : {  "$ne" : "ABC" } }).explain().queryPlanner.winningPlan.cardinalityEstimate; <- returns 1 incorrectly
      db.foo.find({  "a" : {  "$ne" : "ABC" } }).count(); <- returns 2 correctly 

      In other words, only one of the two datatypes present in the dataset is taken into account when estimating the predicate.

      This is not a off-by-one issue, as if the table had 20K values, the estimate would be incorrect by 10K.

            Assignee:
            Unassigned Unassigned
            Reporter:
            philip.stoev@mongodb.com Philip Stoev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: