Sha256: d0d5eb93dc5e19126651b8d6469e5ae8287e6f07fd6c7421423cfd6779b226ae
Contents?: true
Size: 1.34 KB
Versions: 6
Compression:
Stored size: 1.34 KB
Contents
# Union Logical OR ## Signature union(left: Relation, right: Relation) -> Relation ## Examples union(project(suppliers, [:city]), project(parts, [:city])) ## Description Computes the relation as the set union of `left` and `right`. The `left` and `right` relations must be union-compatible, meaning that they must have same heading (type inheritance is partly supported through ruby's own type system, so that the actual behavior is slighlty more permissive). ## Implementation notes Unlike SQL, this operator ALWAYS remove duplicates. There is no way, in Alf, to compute _bags_ of tuples and therefore no way to express something such as SQL's UNION ALL. The optimizer is not smart enough so far to discover when operands are actually disjoint and duplicate removal not needed (e.g. the SQL compiler never generates UNION ALL). Any patch improving this is welcome! Similarly, it is sometimes idiomatic in Alf to use `union` as a logical OR, as illustrated below. So far, the optimizer/compiler is not smart enough to translate the former in the latter (which is likely to have a better query plan, especially when using faithful SQL compilation and usual SQL DBMSs). Any patch is welcome here too! union( restrict(suppliers, city: 'Paris'), restrict(suppliers, city: 'London')) is equivalent to restrict(suppliers, eq(:city, 'Paris') | eq(:city, 'London'))
Version data entries
6 entries across 6 versions & 1 rubygems