How to evaluate relations in a DAG?
Excellent question.  This is known as the problem of answering reachability queries in a graph, and in particular, in a directed acyclic graph (dag).  Basically, you want to know whether y is reachable from x by following edges in the graph -- that's known as a reachability query.  (And symmetrically, you also want to know whether x is reachable from y -- that's a second reachability query.)  Answering reachability queries efficiently is challenging: there are good algorithms for trees, but dags are harder.

One approach is to do a depth-first search from x and see if y is reachable.  However, in the worst case you might end up traversing the entire graph; the worst-case running time is $O(V+E)$.  That's fine if the graph is small, but might take an uncomfortably long time if the graph is large.  So there's been a lot of work on determining whether or not you can do some preprocessing or precomputation on the graph to make it easier to later answer reachability queries more efficiently than that.  If the graph is static (doesn't change), this is known as the reachability problem in dags; if the graph is also changing, then this is known as the dynamic reachability problem for dags.  These problems have been studied in both the CS theory and the databases communities.

Here are some resources to get you started in learning about the state of the art on this problem:


https://cstheory.stackexchange.com/q/37074/5038
https://cstheory.stackexchange.com/q/25298/5038
https://cstheory.stackexchange.com/q/21503/5038
https://cstheory.stackexchange.com/q/5176/5038
https://cstheory.stackexchange.com/q/18787/5038
https://cstheory.stackexchange.com/q/14343/5038
An incrementally-condensed transitive-reduction of a DAG, with efficient reachability queries




Finally, note that MySQL is a relational database, which is intended for relational data -- i.e., data in a tabular structure.  I believe there are also graph-based databases, intended for data with a graph structure.  I don't know much about that subject, but it's possible they might have built-in support that eases some kinds of queries and computations on graphs.