Repeated values share one distinct bucket.

highlighted = computed this step

Duplicates fold

Repeated non-NULL values share one distinct bucket.

duplicates fold\text{duplicates fold}

Read folded duplicates

The compiler folds 2 repeated value cells into existing buckets.

folded duplicates=2\text{folded duplicates}=2

COUNT DISTINCT examples are tiny finite-table transforms; SQL dialect completeness, collations, type coercion, optimizer behavior, execution cost, indexing, and database-product claims are out of scope.

Duplicates fold into one bucket: input rowsidregionbuyer1eastann2eastann3eastNULL4eastbea5westcy6westcy7northNULL8northNULL group bucketskeysourceRowsrowCount[all_rows][0, 1, 2, 3, 4, 5, 6, 7]8 distinct non-NULL value bucketskeydistinctValuesvalueSourcesnullSourceRowsduplicatesFoldedcountDistinct[all_rows][ann, bea, cy][{value:ann, sourceRows:[0, 1]}, {value:bea, sourceRows:[3]}, {value:cy, sourceRows:[4, 5]}][2, 6, 7]23 COUNT DISTINCT output rowsdistinct_count3 COUNT DISTINCT factsfactvalueinputRowCount8groupCount1outputRowCount1valueColumnbuyernullSkipped3duplicateValuesFolded2allNullGroups0groupOrderfirst_seen_source_order

One bucket per value

The distinct bucket table shows one bucket for each unique non-NULL value.

one bucket per value\text{one bucket per value}

Summary

COUNT DISTINCT counts buckets, not repeated rows.

count buckets\text{count buckets}