COUNT DISTINCT starts from visible input rows.

highlighted = computed this step

Input rows

Start with visible rows. Some buyer cells repeat, and some are NULL.

input rows first\text{input rows first}

Read the input

The pinned table has 8 source rows.

rows=8\text{rows}=8

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.

Input rows: 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

No hidden data

Every count later comes from exactly these displayed rows.

no hidden rows\text{no hidden rows}

Summary

COUNT DISTINCT begins with ordinary rows, not a prebuilt set.

rows then distinct\text{rows then distinct}