Sha256: 6215ad2f834c27e75c3abe6fda80f8abfa71dd828072e6c9544ed2e7d7569cdc

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

# Intersect

Logical AND

## Signature

intersect(left: Relation, right: Relation) -> Relation

## Examples

intersect(
  restrict(suppliers, eq(:city, 'Paris')),
  restrict(suppliers, gt(:status, 10)))

## Description

Computes the relation as the set intersection of `left` and `right`.

The `left` and `right` relations must be intersect-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 INTERSECT ALL.

It is sometimes idiomatic in Alf to use `intersect` as a logical AND, as
illustrated below. So far, the optimizer/compiler is not smart enough to
translate the former into the latter (which is likely to have a better query
when using faithful SQL compilation and available SQL DBMSs). Any patch is
welcome here too!

intersect(
  restrict(suppliers, eq(:city, 'Paris')),
  restrict(suppliers, gt(:status, 10)))

is equivalent to

restrict(suppliers, eq(:city, 'Paris') & gt(:status, 10))

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alf-shell-0.16.4 doc/txt/intersect.txt
alf-shell-0.16.3 doc/txt/intersect.txt
alf-shell-0.16.2 doc/txt/intersect.txt
alf-shell-0.16.1 doc/txt/intersect.txt
alf-shell-0.16.0 doc/txt/intersect.txt
alf-shell-0.15.0 doc/txt/intersect.txt