Reputation: 1536
I have one little question. Is MySQL JOIN heavy operation? For instance in one of my project I have about 10 joins in one query. Is this bad?
It is big project and I have quite a lot tables because I frequently hear that it's good idea to split your whole database into small parts. that's exactly what I did and the result is 10 joins. so what's the solution?
Upvotes: 1
Views: 854
Reputation: 94959
You join when you need to join, so the question whether this is a heavy operation or not, doesn't really matter.
In a good database you'd have one table per entity, for instance products, clients, orders. If you look more closely you see that an order consists of one header and many positions each referring to a product. So this must be two order tables: order_header and order_detail. Four tables for the example. You wouldn't further split this, like French clients and American clients or cheap products and expensive products, because a client's country is a mere attribute and whether a product is cheap depends on its price(s), and prices are also mere attributes; the entities remain client and product.
Having said this, "it's good idea to split your whole database into small parts" is a strange advice. You'd have one table per entity which may be just two tables for some address database maybe or a thousand tables for a big company's product database.
To answer the question: No, it's not bad to have ten joins in a query. You may want someone to look at your database design though, if you blindly followed the advice to create many tables.
Upvotes: 3