Marcus wrote:
Quote:
Hello,
I've read numerous articles on the web advocating avoiding joins in
MySQL whenever possible for performance reasons. I was curious as to
just how slow a simple equi-join would be, so I ran some tests using the
benchmark code from this site:
http://www.developerfusion.co.uk/show/2058/ |
First of all, don't believe everything you read on the internet! There
are a lot of people who have no real knowledge of what's going on
espousing all kinds of things.
To answer your question, this goes back to basics of DB theory and
normalization. There are 5 levels of normalization (in theory).
As you go to higher normalization levels, you get higher diversity and
less duplication of data. But at the same time it means you will
typically have more tables, requiring more joins. This means that
performance will often times be slower, requiring more CPU cycles (of
course, there are exceptions to this - but those are typically rare).
For instance, in first normal form you may have everything in one table,
requiring no joins. However, you would also have a massive duplication
of data. Take a bank, for instance. If a customer has a savings
account and a checking account, the customer's name, address, etc. would
have to be saved in each account's record.
Going to second normal form, you would have two tables - a customer
table, an account table. The account table would contain the customer's
id, requiring a single join.
But what if you have a joint account (two customers)? This doesn't work
as well. Yes, you could stay in second normal form and have multiple
entries in the account table for customer ids, but this has it's limits.
(There are other ways also, but they each have their advantages and
disadvantages)
Going to third normal form adds a third table containing a customer id
and an account id, linking the other two tables. This would require two
joins to get customer information for an account (or vice versa), making
it slower but more flexible.
The bottom line is - proper database design is not always easy and has
to consider the design of the entire database as well as the access
required by the program(s) using it. You can't say joins by themselves
are good or bad. They need to be taken in the context of the entire system.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================