Bag Semantics and Join Multiplicities
Calculate how multiplicities combine in SQL-style bag operations and identify where duplicate elimination changes later aggregates.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Projection can add several counts together
A bag assigns a nonnegative integer multiplicity to each row value. If two rows differ only in a field that is projected away, both contribute to the projected value. A matching join multiplies left and right multiplicities for each compatible pair before equal output values are aggregated. Two identical occurrences on one side and three on the other can therefore contribute six results. A set would retain only one distinct tuple.
Duplicate elimination changes the plan’s meaning
Applying DISTINCT before a join can alter an aggregate afterward. Pushing it earlier is valid only under additional facts such as a key or an objective insensitive to multiplicity. This also matters for incremental computation, where a deleted occurrence need not remove the entire value. Join cardinality sums these counts. Database provenance generalizes the arithmetic of alternative and joint derivations.[1][2]