Rows sharing a key form deterministic buckets.

highlighted = computed this step

GROUP BY buckets

After WHERE, rows with the same group key share a bucket.

same key, same bucket\text{same key, same bucket}

Read buckets

The compiler forms 3 region buckets in first-seen display order.

groups=3\text{groups}=3

HAVING examples are tiny finite group-filter transforms; SQL dialect completeness, optimizer behavior, indexing, and product claims are out of scope.

GROUP BY buckets: base rowsidregionstatusqty1eastopen22eastopen33westopen14westclosed45northNULL26northopen1 WHERE before groupingsourceinputwhereTruthgroupedRole0[1, east, open, 2]TRUEgrouped1[2, east, open, 3]TRUEgrouped2[3, west, open, 1]TRUEgrouped3[4, west, closed, 4]TRUEgrouped4[5, north, NULL, 2]TRUEgrouped5[6, north, open, 1]TRUEgrouped GROUP BY bucketskeysourceRowsrowCount[east][0, 1]2[west][2, 3]2[north][4, 5]2 Aggregate facts per groupkeysourceRowsaggregates[east][0, 1]{n:2, total_qty:5}[west][2, 3]{n:2, total_qty:5}[north][4, 5]{n:2, total_qty:3} HAVING result per groupkeypredicatetruthoutputRole[east]noneTRUEkept[west]noneTRUEkept[north]noneTRUEkept HAVING output groupsregionntotal_qtyeast25west25north23 HAVING factsfactvalueinputRowCount6whereKeptRows6whereDroppedRows0groupCount3aggregateCount2outputGroupCount3havingTrueCount3havingFalseCount0havingUnknownCount0groupOrderfirst_seen_after_wherepipelineWHERE_before_GROUP_BY_then_HAVING

Stable display order

Group order is deterministic here: the first visible row for a group fixes its display position.

first seen group order\text{first seen group order}

Summary

The bucket table shows exactly which source rows belong to each group.

bucket source rows\text{bucket source rows}