That's a tricky question. I've taken courses in set theory and relational algebra at school, and I can definitely say that they have aided my understanding of relational databases. But just learning set theory by itself probably won't help a lot. Relational algebra, which requires a little basic set theory, is a better formalism for modeling relational databases (by design), and it's a great thing to learn if you're planning on using them a lot. It will help with not only query optimization but also database design, which can seem like a black art without examining the theoretical underpinnings. Database normal forms, for example, can be succinctly describes as simple expressions in relational algebra.
If you're only doing simple SQL querying and no complex queries or database design, then the effort to learn relational algebra may not be justified by the benefit.
It's worth mentioning that real-world relational databases are not actually sets, but rather bags or multisets. Applying set theory to bags tends to cause headaches from the impedance mismatch.
manpreet
Best Answer
2 years ago
I am learning database right now -- and some of the queries are getting just plain crazy. I know that during query optimization you may sometimes rewrite queries in different ways to minimize certain things. I am looking at a correllated subquery example and see that it results in the same resultset as a LEFT JOIN.
I am thinking that possibly mathematically (set theory) they may be related, and if someone comfortable with set theory would be able to see that easily.
My question is: What kind of return on investment would I see from learning set theory? Would I see any return on investment? Would it be faster to learn database just by writing more queries, or should I spend time on set theory? I don't want to fall down a rabbit hole. I want to be good with database, but I need to get there as fast as possible.