문제

In FD, I do not understand the following: X->Y, how come X could be different as long as the Y is the same?

X   Y
--  --
1   10
2   10
3   10

I was told that this is still X->Y and that it only matters if Y changed. I do not get it..

도움이 되었습니까?

해결책

Functional dependency happens in a relation when the relation "is a function". Formally, this means that if you have an FD like X -> Y then each value of X must relate to exactly 1 value of Y. If we invert that statement, we get a "test" for a failure to have an FD:

If there exists a value `x` in `X` such that there are two values 
of `Y`, `y1` and `y2`, where both

  (x, y1) and (x, y2)

are in the relation, if `NOT (y1 == y2)` then `Y` is not 
functionally dependent on `X`

With a bit of thought it's easy to see that this test passes for the relation you've written down.


A more intuitive notion of X -> Y comes from intuition about mathematical functions. A function can be thought of as a machine which consumes input and produces output under the rule that the output of some particular input is always the same no matter how many times you run the machine. Relations model functions when they have functional dependencies. A functional dependency just states that the tuples in your relation could have the form

(x, f(x))

for some mathematical function f.

In the case of your relation, that function f is simple:

f(x) = 10           "constant function"

Examples:
f(1)  = 10
f(2)  = 10
f(10) = 10

Another notion of FD comes from "drawing diagrams". To do this, think of all the values of X as being laid out in a line next to all the values of Y

x1    y1
x2    y2
x3    y3
x4    y4
x5    y5
...

A relation occurs when we draw lines from the X column to the Y column connecting two values. Each line corresponds to a tuple.

x1----y1      is the relation        { (x1, y1), (x2, y2) }
x2----y2

A relation is functional X -> Y if each value of X has either 0 or 1 lines associated with it.

x1----y1   is the relation { (x1, y1)
x2----y2                   , (x2, y2)
x3--| y3                   , (x3, y4)
x4--+-y4                   , (x4, y4) }

When this is the case we can turn these lines into "arrows"

x1---->y1
x2---->y2
x3--|  y3
x4--+->y4

and have the property where if we follow the arrows from base to point we always have a unique path forward---we don't have to "split up". In a non-functional relation we "split up"; for instance, if we flip the relation and look to see if Y is functional on X we flip the arrows

x1<----y1
x2<----y2
x3<--| y3
x4<--+-y4

and now see that as we leave y4 traveling left we'd have to "split" to follow the arrow to both x3 and x4. This means that Y -> X does not hold.

다른 팁

You should probably read the wikipedia page about functional dependencies: the first three lines are probably enough to clarify your doubt:

In relational database theory, a functional dependency is a constraint between two sets of attributes in a relation from a database. Given a relation R, a set of attributes X in R is said to functionally determine another set of attributes Y, also in R, (written X → Y) if, and only if, each X value is associated with precisely one Y value; R is then said to satisfy the functional dependency X → Y.

However, in your example X must have different values since it is the key, whereas Y could be any value and it just happens to be always 10.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top