Re: [OT]DB structure efficiency

From: Idan Sofer (idan_at_nonexisting.hamakor.org.il)
Date: Thu 10 Jun 2004 - 20:06:05 IDT


Amir Hardon wrote:

>For example what will be better, storing all items information in one table
>with one column for category, or having a separate items table for each
>category.
>My guess is that separate tables will be faster for use but will consume more
>disk space.
>
>
It's a good example where a premature optimization may become the root
of all evil. a category on most cases is a _property_ of an
item(column), it does not define it's class(table name).

Besides being hard to manage(adding a new category is going to be pretty
rough), in some cases it might actually be slower. think about setting a
query for getting how many items you have in each category. usally that
is something like:

SELECT COUNT(id),category FROM items GROUP BY category

Perhaps with a join if category refers to an identifer in another table,
and if you have an index on category it should be quite efficent. what
happends if you want the same thing when each category is in seperate
table? you have to call N queries, which is likely to be less efficent.

Think about other cases, say, when refering to an item identifier from
another table etc..

=================================================================
To unsubscribe, send mail to linux-il-request_at_linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request_at_linux.org.il



This archive was generated by hypermail 2.1.7 : Thu 10 Jun 2004 - 20:20:40 IDT