Random question: Which is faster/better

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Random question: Which is faster/better

Post by aliasxneo »

This is something I've been pondering for awhile.

Let's say I have some items that I want to categorize. I have a categories table that contains the category id and name. Would it be better if I:

A) Added a field called 'category' to the items table that contains the category id it belongs too
B) Created a new table that contains a game id and a category id ti show which game belong to which category

Is either one more appropriate or faster?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Option B would allow you to have a game in more than one category, whereas option A would limit each game to a single category...

As for speed, I doubt either would be substantially faster, but I am not the person to answer that kind of question...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

General rule of thumb: the more joins your query has, the more slower it runs. Thus second option will be somewhat slower, but it will provide additional functionality which first option coudn't provide.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Joins, though somewhat slower for larger data sets, can be made efficient with proper indexing and table normalization.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I will always choose normalization over performance. Hardware is simply cheaper than man power (aka the cost of maintaining and developing a poorly structured database).
Post Reply