[Dbix-class] Operator Overloads in DBIC?

Darren Duncan darren at darrenduncan.net
Sat May 14 09:26:16 GMT 2016


On 2016-03-07 4:25 AM, Paul Bennett wrote:
> I have most of a spec (and a tiny bit of pseudocode) prepared for
> adding operator overloads to Result Sets, to make it easier to write &
> reuse pieces of queries in a style more like Relational Algebra &
> Tuple-Relational Calculus. For instance, '/' for relational division,
> '*' for fiber product, 'x' for explicit cross join, '|' for left
> semijoin, '||' for left outer join, '.' for full outer join, '>' for
> left antijoin, '+' for union, '&' for intersection, '-' for "except",
> and so on.

Paul,

Firstly:  What are the exact semantics you would use for your relational 
division, since there is more than one operation historically that has been 
given that name?  I mean, express it in terms of other relational 
algebra/calculus.  On a related note, it has been argued that this operation 
isn't very useful in practice; do you see a use for it or are you just being a 
completionist?

Secondly:  Have you considered using other symbols for these operators?  The 
ones you chose don't in my mind bear much resemblance to their meaning, or I 
otherwise prefer not to use math operators for set operations.

I recommend you use short alphanum names instead, or Unicode symbols, like this:

     ⊎ addition
     ∖ except
     ∩ intersect
     ∪ union
     ∆ symmetric difference
     ⨝ natural join (or ⋈ alternately)
     ⋊ semijoin
     ⋉ semijoin
     ⊿ antijoin
     ⨯ cross product
     ⟕ half outer join
     ⟖ half outer join
     ⟗ full outer join

Basically, the word versions are what people would normally use, they are easier 
to type but in particular are more explicit on meaning, where your overloaded 
symbolics mostly are not; the Unicode are for people who want a concise mathy 
look and have a Perl version supporting Unicode operators.

Note that the addition and union only differ for multisets; for sets they are 
the same operation.

-- Darren Duncan




More information about the DBIx-Class mailing list