samplingCE inaccurate for queries with runtime field dependencies

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide
      db.adminCommand({setParameter:1, featureFlagCostBasedRanker: true, internalQueryCBRCEMode: "samplingCE"})
      db.a.drop()
      db.a.createIndex({a: 1})
      db.a.createIndex({a: 1, b:1})
      db.a.insertOne({field: 'a', a:0})
      db.a.explain().find({$expr: {$eq: [{$getField: {input: "$$ROOT", field: "$field"}}, 0]}}) // The cardinality estimate is 0 (only the top level `field` field is included in the sample, even though the query depends on the entire object)
      Show
      db.adminCommand({setParameter:1, featureFlagCostBasedRanker: true , internalQueryCBRCEMode: "samplingCE" }) db.a.drop() db.a.createIndex({a: 1}) db.a.createIndex({a: 1, b:1}) db.a.insertOne({field: 'a' , a:0}) db.a.explain().find({$expr: {$eq: [{$getField: {input: "$$ROOT" , field: "$field" }}, 0]}}) // The cardinality estimate is 0 (only the top level `field` field is included in the sample, even though the query depends on the entire object)
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      This check needs to use needsWholeDocument instead of checking if the returned set of field dependencies is empty, as a query needing the whole document is independent of it having static top-level field dependencies.

      Refactor ce::extractTopLevelFieldsFromMatchExpression to take into account DepsTracker::needWholeDocument, and modify the interface accordingly (eg. return boost::none if needsWholeDocument is set, instead of returning an empty set).

            Assignee:
            Unassigned
            Reporter:
            Kartal Kaan Bozdogan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: