PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > performance: many rows vs. long columns
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
performance: many rows vs. long columns

Réponse
 
LinkBack Outils de la discussion
Vieux 03/11/2007, 12h37   #1
omeldoid@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut performance: many rows vs. long columns

hello. i was wondering what the best approach was: having a table
where each row has a field that holds more items (say 10), so that
each row gives me all the items associated with a certain request, or
a table that returns more rows with exactly one item per row
associated with that request?

an example: a given user may have a list of cities associated with
him; is it better to have a table where each username has exactly one
column that lists all the cities, or exactly one row for each city
associated with that user?

i see the second option's obvious advantages for possible
calculations, but would like to know more about the performance. is
there a general rule for situations like this?

thanks.

  Réponse avec citation
Vieux 03/11/2007, 13h15   #2
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: performance: many rows vs. long columns

omeldoid@gmail.com wrote:
> hello. i was wondering what the best approach was: having a table
> where each row has a field that holds more items (say 10), so that
> each row gives me all the items associated with a certain request, or
> a table that returns more rows with exactly one item per row
> associated with that request?


The advantage to have a column with X items is that you only need to fetch one
row, but the disadvantage is that you loose the relations between the items
and extra information and searches will get more complicated.


> an example: a given user may have a list of cities associated with
> him; is it better to have a table where each username has exactly one
> column that lists all the cities, or exactly one row for each city
> associated with that user?


I highly recommend you have one row for each link user to one city.
If the table you are thinking of has more info than just username and city,
then you create a link table which links the user to a city. As you should
avoid to duplicate data.


> i see the second option's obvious advantages for possible
> calculations, but would like to know more about the performance. is
> there a general rule for situations like this?


Having all in one column, would ease the databases load when using simple
SELECT, but you tenfold the load on your script, which has to do all the stuff
that the database had done fast with low CPU usage if you had a row for each
link user-city.
It's a higher risk that you make a bad code in your script than the code that
makes up the database server, so you would have the risk that you even let the
load on your script to be even higher.

The better design you have on your database, the better things will be in the
end, making shortcuts will just make things worse.

--

//Aho
  Réponse avec citation
Vieux 03/11/2007, 13h54   #3
omeldoid@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: performance: many rows vs. long columns

On Nov 3, 1:15 pm, "J.O. Aho" <u...@example.net> wrote:

> I highly recommend you have one row for each link user to one city.
> If the table you are thinking of has more info than just username and city,
> then you create a link table which links the user to a city. As you should
> avoid to duplicate data.


> Having all in one column, would ease the databases load when using simple
> SELECT, but you tenfold the load on your script, which has to do all the stuff
> that the database had done fast with low CPU usage if you had a row for each
> link user-city.
> It's a higher risk that you make a bad code in your script than the code that
> makes up the database server, so you would have the risk that you even let the
> load on your script to be even higher.


a highly informative answer. thank you very much.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h09.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09190 seconds with 11 queries