AmpersandTarski / Ampersand

Build database applications faster than anyone else, and keep your data pollution free as a bonus.
http://ampersandtarski.github.io/
GNU General Public License v3.0
40 stars 8 forks source link

Code generator bug for `V[Account*Contractsoort];contract~ - V[Account*WTRcat];wtrCategorie~` #312

Closed stefjoosten closed 8 years ago

stefjoosten commented 8 years ago

@hanjoosten , In the code below, I cannot see how the difference operator is implemented. In fact, I believe the code for this EDif-expression is not correct. If I am right, that would explain funny results in my prototypes. Can you please verify whether I am right or contradict me by claiming that the code below is a correct translation of V[Account*Contractsoort];contract~ - V[Account*WTRcat];wtrCategorie~? I have compiled with Ampersand v3.4.0[master:2b90afa], build time: 11-Feb-16 12:40:47 West-Europa (standaardtijd).

/* case: EDif (l,r) V[Account*Contractsoort];contract~ - V[Account*WTRcat];wtrCategorie~ ([Account*Dienstverband]) */
/* Optimized case for: <expr1> intersect with the complement of <expr2>.
where 
  <expr1> = V[Account*Contractsoort];contract~ ([Account*Dienstverband])
  <expr2> = V[Account*WTRcat];wtrCategorie~ ([Account*Dienstverband])
   V[Account*Contractsoort];contract~ /\\ -(V[Account*WTRcat];wtrCategorie~) ([Account*Dienstverband])
 */
select
distinct
       t1.src as src, t1.tgt as tgt
from (/* case: (ECps es), with two or more elements in es.V[Account*Contractsoort];contract~ */
      select
      distinct
             fence0.src as src, fence1.tgt as tgt
      from (/* case: (EDcV (Sign s t))   V[ "[Account*Contractsoort]" ] */
            select
            distinct
                   fst."Account" as src, snd."Contractsoort" as tgt
            from "Account" as fst,
                 "Contractsoort" as snd
            where fst."Account" IS NOT NULL AND snd."Contractsoort" IS NOT NULL)
           as fence0,
           (/* Flipped: EDcD contract[Dienstverband*Contractsoort] */
            select
            distinct
                   "tgt_contract" as src, "Dienstverband" as tgt
            from "Dienstverband"
            where "Dienstverband" IS NOT NULL AND "tgt_contract" IS NOT NULL)
           as fence1
      where fence0.tgt = fence1.src)
     as t1
     left
     join (/* case: (ECps es), with two or more elements in es.V[Account*WTRcat];wtrCategorie~ */
           select
           distinct
                  fence0.src as src, fence1.tgt as tgt
           from (/* case: (EDcV (Sign s t))   V[ "[Account*WTRcat]" ] */
                 select
                 distinct
                        fst."Account" as src, snd."WTRcat" as tgt
                 from "Account" as fst,
                      "WTRcat" as snd
                 where fst."Account" IS NOT NULL AND snd."WTRcat" IS NOT NULL)
                as fence0,
                (/* Flipped: EDcD wtrCategorie[Dienstverband*WTRcat] */
                 select
                 distinct
                        "tgt_wtrCategorie" as src, "Dienstverband" as tgt
                 from "Dienstverband"
                 where "Dienstverband" IS NOT NULL AND "tgt_wtrCategorie" IS NOT NULL)
                as fence1
           where fence0.tgt = fence1.src)
          as t2
     on t1.src = t2.src AND t1.tgt = t2.tgt
where t2.src IS NULL OR t2.tgt IS NULL
hanjoosten commented 8 years ago

I have done a thourogh visual inspection of this code, and find no anomalities whatsoever. I didn't go into the details of the expressions:

  <expr1> = V[Account*Contractsoort];contract~ ([Account*Dienstverband])
  <expr2> = V[Account*WTRcat];wtrCategorie~ ([Account*Dienstverband])

Iff the above expressions are calculated right, then the entire sql query is correct. (and fast :) )

stefjoosten commented 8 years ago

OK! Thx