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
  1. Projection can add several counts together
  2. Duplicate elimination changes the plan’s meaning

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]

References

  1. CMU 15-445/645, Introduction to Database Systems: Lectures ↩
  2. PostgreSQL Global Development Group, PostgreSQL Documentation ↩