Unix Technical Forum

Good Table Design Advice Wanted

This is a discussion on Good Table Design Advice Wanted within the MySQL forums, part of the Database Server Software category; --> Hello, I'm looking for a few tips on good table design before I start work on a new database. ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:32 AM
Ciaran
 
Posts: n/a
Default Good Table Design Advice Wanted

Hello, I'm looking for a few tips on good table design before I start
work on a new database.

Question 1. Assuming a query is as effecient as possible, does the
number of rows in the table significantly effect query speed?
Consequently, would it be better to store unrelated data which has
identical structure in separate tables as below?

Example A:::::::::::::::::::::::::

MAINTABLE:
type | name | desc
___________________
car | ford | red
car | nissan | blue
album | white album | beatles
album | masterplan | oasis


Example B::::::::::::::::::::::::

CAR TABLE (1):
name | desc
___________________
ford | red
nissan | blue


ALBUM TABLE (2):
name | desc
___________________
white album | beatles
masterplan | oasis



If working with large amounts of data, is there a huge difference
between example 1 and example 2 above?



Question 2.
Does the amount of irrelevant content in the records effect query
time? In other words, when creating something like a product search
engine, would it be faster to store only keys and titles in the main
table for searching and store longer data like descriptions, comments
& reviews in a separate table that can be looked up after the user
makes a choice?


Thanks for any advice!
Ciarán

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:32 AM
Evan Keel
 
Posts: n/a
Default Re: Good Table Design Advice Wanted


"Ciaran" <cronoklee@hotmail.com> wrote in message
news:5f558a76-0fd7-449b-ba35-e5feba988e6e@e4g2000hsg.googlegroups.com...
>Hello, I'm looking for a few tips on good table design before I start
>work on a new database.


Since you will also be doing inserts and deletes why don't you start with
normalized tables and tune from there?

Evan


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:32 AM
Terry Carmen
 
Posts: n/a
Default Re: Good Table Design Advice Wanted

>
> MAINTABLE:
> type | name | desc
> ___________________
> car | ford | red
> car | nissan | blue
> album | white album | beatles
> album | masterplan | oasis
>
>
> Example B::::::::::::::::::::::::
>
> CAR TABLE (1):
> name | desc
> ___________________
> ford | red
> nissan | blue



Just because they're different kinds of objects (physical, not software)
doesn't mean they need to be in separate tables. They could both be
inventory items, for example.

Now if they represent really different things, like employee vehicles
and albums for a playlist, then, yes, they belong in different tables.

Knowing whether or not they belong in separate tables would require
knowing what the items actually represent in the intended business model.

Terry


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:32 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Good Table Design Advice Wanted

Ciaran wrote:
> Hello, I'm looking for a few tips on good table design before I start
> work on a new database.
>
> Question 1. Assuming a query is as effecient as possible, does the
> number of rows in the table significantly effect query speed?
> Consequently, would it be better to store unrelated data which has
> identical structure in separate tables as below?
>
> Example A:::::::::::::::::::::::::
>
> MAINTABLE:
> type | name | desc
> ___________________
> car | ford | red
> car | nissan | blue
> album | white album | beatles
> album | masterplan | oasis
>
>
> Example B::::::::::::::::::::::::
>
> CAR TABLE (1):
> name | desc
> ___________________
> ford | red
> nissan | blue
>
>
> ALBUM TABLE (2):
> name | desc
> ___________________
> white album | beatles
> masterplan | oasis
>
>
>
> If working with large amounts of data, is there a huge difference
> between example 1 and example 2 above?
>
>
>
> Question 2.
> Does the amount of irrelevant content in the records effect query
> time? In other words, when creating something like a product search
> engine, would it be faster to store only keys and titles in the main
> table for searching and store longer data like descriptions, comments
> & reviews in a separate table that can be looked up after the user
> makes a choice?
>
>
> Thanks for any advice!
> Ciarán
>
>


First of all, study up on database normalization.

Bear in mind that efficiency and normalization are cross-purpose. The
more normalized the database is, the less duplication of data - but also
the less efficient queries will typically be.

But now is not the time to worry about efficiency, and I doubt you'll
see much difference until you get into large databases - i.e. 10M rows
or more.

So don't prematurely optimize. Use good normalization techniques to
build your database. Use good programming techniques writing your code.
Then, later, if you have performance problems, identify the cause of
the problem and fix it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:32 AM
Ciaran
 
Posts: n/a
Default Re: Good Table Design Advice Wanted

Thanks guys, reading up on normalization definitely helped a lot. I
kind of know that in my first question, it's more logical to separate
unrelated data even if it could be stored in the same table but I'm
still interested in the answer to my second question.
For example normalization rule 2NF reads:
"Remove subsets of data that apply to multiple rows of a table and
place them in separate tables."
But what if the there is data that is unique yet not immediately
relevant?

I get the overall impression that it's row size, not row quantity that
effects efficiency, in which case the answer would be "yes, it's
better to separate unique but immediately redundant fields."
Am I right to guess this?

Cheers,
Ciarán
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:32 AM
Terry Carmen
 
Posts: n/a
Default Re: Good Table Design Advice Wanted

Ciaran wrote:
> I get the overall impression that it's row size, not row quantity that
> effects efficiency, in which case the answer would be "yes, it's
> better to separate unique but immediately redundant fields."
> Am I right to guess this?


Performance is difficult to predict and is effected by a huge number of
non-obvious data and database characteristics.

I would recommend creating a correct, easy-to-maintain database schema,
then worrying about performance problems if you have any.

All the performance problem I've ever run into on other large systems
(I'm new to MySQL) have been correctable by:

* Creating appropriate indexes and primary key constraints
* Writing efficient queries
* Selecting the right database engine or database type
* And in one case, coming to the realization that the best solution
for every problem that uses data isn't always a DBMS. Sometimes it's a
small, tight C application.

De-normalizing the database in the interest of performance has never
been helpful. It's possible that it might be in some application,
however I'd try everything else first.

Whoever has to work with your code will thank you.

Terry
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 11:32 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Good Table Design Advice Wanted

Ciaran wrote:
> Thanks guys, reading up on normalization definitely helped a lot. I
> kind of know that in my first question, it's more logical to separate
> unrelated data even if it could be stored in the same table but I'm
> still interested in the answer to my second question.
> For example normalization rule 2NF reads:
> "Remove subsets of data that apply to multiple rows of a table and
> place them in separate tables."
> But what if the there is data that is unique yet not immediately
> relevant?
>
> I get the overall impression that it's row size, not row quantity that
> effects efficiency, in which case the answer would be "yes, it's
> better to separate unique but immediately redundant fields."
> Am I right to guess this?
>
> Cheers,
> Ciarán
>


As I said before. DON'T PREMATURELY OPTIMIZE.

Build a good design. If you have a performance problem, find the cause
of your problem. Now is NOT the time to be considering problems you
almost certainly won't have!

And a poorly defined database is much worse in the long haul than one
'designed to be optimized'.

Additionally, normalization has nothing to do with relevance of data.
It strictly deals with relationships between data.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 11:32 AM
Evan Keel
 
Posts: n/a
Default Re: Good Table Design Advice Wanted


"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:PfadnW9TZc-dkDLanZ2dnUVZ_vfinZ2d@comcast.com...
> Ciaran wrote:
> > Thanks guys, reading up on normalization definitely helped a lot. I
> > kind of know that in my first question, it's more logical to separate
> > unrelated data even if it could be stored in the same table but I'm
> > still interested in the answer to my second question.
> > For example normalization rule 2NF reads:
> > "Remove subsets of data that apply to multiple rows of a table and
> > place them in separate tables."
> > But what if the there is data that is unique yet not immediately
> > relevant?
> >
> > I get the overall impression that it's row size, not row quantity that
> > effects efficiency, in which case the answer would be "yes, it's
> > better to separate unique but immediately redundant fields."
> > Am I right to guess this?
> >
> > Cheers,
> > Ciarán
> >

>
> As I said before. DON'T PREMATURELY OPTIMIZE.
>
> Build a good design. If you have a performance problem, find the cause
> of your problem. Now is NOT the time to be considering problems you
> almost certainly won't have!
>
> And a poorly defined database is much worse in the long haul than one
> 'designed to be optimized'.
>
> Additionally, normalization has nothing to do with relevance of data.
> It strictly deals with relationships between data.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
>


You are correct when you say " normalization has nothing to do with
relevance of data" , but normalization has all to do with one fact in one
place, especially 2nd and 3rd normal form and that is where the OP should
start. Also, normalization is about intra-table column dependencies and not
really about relationships among tables.

Evan


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 11:32 AM
Evan Keel
 
Posts: n/a
Default Re: Good Table Design Advice Wanted


"Ciaran" <cronoklee@hotmail.com> wrote in message
news:b3a27a8f-caa5-4353-8d20-bdae28f05404@s13g2000prd.googlegroups.com...
Thanks guys, reading up on normalization definitely helped a lot. I
kind of know that in my first question, it's more logical to separate
unrelated data even if it could be stored in the same table but I'm
still interested in the answer to my second question.
For example normalization rule 2NF reads:
"Remove subsets of data that apply to multiple rows of a table and
place them in separate tables."
But what if the there is data that is unique yet not immediately
relevant?

I get the overall impression that it's row size, not row quantity that
effects efficiency, in which case the answer would be "yes, it's
better to separate unique but immediately redundant fields."
Am I right to guess this?

Cheers,
Ciarán


2nd normal form -- if an column is not dependent on the full key, maybe a
new table?

Evan


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 11:32 AM
Ciaran
 
Posts: n/a
Default Re: Good Table Design Advice Wanted

On Feb 10, 5:48 pm, "Evan Keel" <evank...@sbcglobal.net> wrote:
> "Ciaran" <cronok...@hotmail.com> wrote in message
>
> news:b3a27a8f-caa5-4353-8d20-bdae28f05404@s13g2000prd.googlegroups.com...
> Thanks guys, reading up on normalization definitely helped a lot. I
> kind of know that in my first question, it's more logical to separate
> unrelated data even if it could be stored in the same table but I'm
> still interested in the answer to my second question.
> For example normalization rule 2NF reads:
> "Remove subsets of data that apply to multiple rows of a table and
> place them in separate tables."
> But what if the there is data that is unique yet not immediately
> relevant?
>
> I get the overall impression that it's row size, not row quantity that
> effects efficiency, in which case the answer would be "yes, it's
> better to separate unique but immediately redundant fields."
> Am I right to guess this?
>
> Cheers,
> Ciarán
>
> 2nd normal form -- if an column is not dependent on the full key, maybe a
> new table?
>
> Evan




Thanks Evan, that's that I suspected. It makes sense that there should
be as little redundant data as possible for the most important
queries.
Thanks for the reply,
Ciarán
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:14 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com