Why can't you just join the trap?

I'm trying to figure out what a fan trap is.

I don't understand why you can't know how the sales rep is processed?

Can't you just join the Sales Rep, Branch and Account tables and find out? What am I missing? enter image description here

0


source to share


1 answer


You can join fan trap tables / relationships. This is only a trap if you think the summary table / relations means something that it doesn't. Of course, if you want the table / relationship you think it is, that means you are missing it and need to be added.

Works_for(rep,branch) -- (rows where) rep *rep* works for branch *branch*
Manages(branch,account) --(rows where) some branch *branch* rep manages account *account*

/* (rows where)
    rep *rep* works for branch *branch*
AND some branch *branch* rep manages account *account*
*/
Works_for NATURAL JOIN Manages

      

If you think this connection should contain

/* (rows where)
    rep *rep* works for branch *branch*
AND rep *rep* manages account *account*
*/
Works_for_and_manages(rep, branch, account)

      

then you are trapped.



The two join predicates (statement patterns) are not equivalent (do not have the same truth value for each row in every situation) when this β€œfan” pattern is power constrained. Therefore, their tables do not always have the same meaning.

You might see that they will be equivalent if there is only one employee in each branch - who should manage all accounts. But then the Cardinals wouldn't be fans. However, it is much more likely that the two predicates are not equivalent, so you cannot construct either predicate / table / relationship from the other, and better design has Works_for

and

Manager(rep, account) -- (rows where) rep *rep* manages account *account*`

      

Then Manages

there is SELECT branch, account FROM Works_for NATURAL JOIN Manager

. That is, the lines where for some *rep*, [rep *rep* works for branch *branch* AND rep *rep* manages account *account*]

.

(Tables resulting from relational operators have predicates resulting from certain relevant logical operators. JOIN

Matches AND

, UNION

- OR

, etc. Thus, we can justify that the query expression returns the desired rows.)

0


source







All Articles