• Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide
      db.adminCommand({
        setParameter: 1,
        internalQueryCBRCEMode: "samplingCE",
        internalQueryPlanRanker: "costBased",
        internalQueryStatsSampleRate: 1
      });
      db.a.drop();
      db.a.insertOne({});
      db.a.createIndex({ a: 1 });
      db.a.createIndex({ b: 1 });
      db.adminCommand({setParameter: 1, internalQueryStatsCacheSize: "0MB"}) // drop all the existing entries
      db.adminCommand({setParameter: 1, internalQueryStatsCacheSize: "1%"})  // restore the default
      db.a.find({ a: 0, b: 0 }).toArray();
      printjson(db.getSiblingDB("admin").aggregate([
        { $queryStats: {} },
        { $match: { "key.queryShape.cmdNs.coll": "a" } },
        { $project: { key: 1, cbr: "$metrics.queryPlanner.costBasedRanker" } },
      ]).toArray());
      

       
      Gives:

            ...
            nDocsSampled: {
              sum: Long('384'),
              max: Long('384'),
              min: Long('384'),
              sumOfSquares: Decimal128('147456')
            }
      

      Even though we don't actually sample more documents than there are in the collection (only 1 in this case).

      For reference, the commit right before SERVER-130972 returns the correct numbers:

       

            nDocsSampled: {
              sum: Long('1'),
              max: Long('1'),
              min: Long('1'),
              sumOfSquares: Decimal128('1')
            }

       

      Show
      db.adminCommand({ setParameter: 1, internalQueryCBRCEMode: "samplingCE" , internalQueryPlanRanker: "costBased" , internalQueryStatsSampleRate: 1 }); db.a.drop(); db.a.insertOne({}); db.a.createIndex({ a: 1 }); db.a.createIndex({ b: 1 }); db.adminCommand({setParameter: 1, internalQueryStatsCacheSize: "0MB" }) // drop all the existing entries db.adminCommand({setParameter: 1, internalQueryStatsCacheSize: "1%" }) // restore the default db.a.find({ a: 0, b: 0 }).toArray(); printjson(db.getSiblingDB( "admin" ).aggregate([ { $queryStats: {} }, { $match: { "key.queryShape.cmdNs.coll" : "a" } }, { $project: { key: 1, cbr: "$metrics.queryPlanner.costBasedRanker" } }, ]).toArray());   Gives: ... nDocsSampled: { sum: Long('384'), max: Long('384'), min: Long('384'), sumOfSquares: Decimal128('147456') } Even though we don't actually sample more documents than there are in the collection (only 1 in this case). For reference, the commit right before SERVER-130972 returns the correct numbers:         nDocsSampled: {         sum: Long('1'),         max: Long('1'),         min: Long('1'),         sumOfSquares: Decimal128('1')       }  
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      SERVER-130972 changes the semantics of SamplingEstimator::getSampleSize and now it always returns the requested sample size, even if the collection was too small to reach that size, and this ends up at $queryStats.

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

              Created:
              Updated: