AskSQL API Reference (core v0.10.0)
    Preparing search index...

    Function rewriteDistinctCount

    • Rewrites the $addToSet + $size distinct count, which the guard refuses because the array must fit in one 16MB document, into a grouped count that spills to disk instead:

      [{$group: {_id: null, r: {$addToSet: "$region"}}}, {$project: {n: {$size: "$r"}}}] -> [{$match: {region: {$exists: true}}}, {$group: {_id: "$region"}}, {$count: "n"}]

      Requires a global group holding that one accumulator, with the array read exactly once.

      Parameters

      • pipeline: readonly unknown[]

      Returns unknown[] | null