If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Id or name?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-11, 14:39
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
Exclamation Id or name?

Hi everyone)
I'm newbie in database optimization and I have some questions about it:
First of all, what is better for table that contains messages like posts or tweets or comments: author_id | message or author_fullname | message ? I know that first variant is better, but I don't know why it is better. While displaying the message to the user, you will show the authors name, not id, right? It means you'll need one more request to get the information about author like name, age, etc. So isn't it better to keep the information about author in messages table to avoid one more request?

How size of a table affects on speed? I thought that if table is well-sorted, retrieving data will be ok despite the size of table. Is it wrong belief?
Reply With Quote
  #2 (permalink)  
Old 01-08-11, 18:17
SimonMT SimonMT is offline
Registered User
 
Join Date: Sep 2006
Posts: 265
The only reason to use name or subset of the name is if it is useful. There are times for ease of entry to use shortened names "Oil on canvas" OOC or "Oil on board" OOB. The difference boils down to recognition.

Simon
Reply With Quote
  #3 (permalink)  
Old 01-08-11, 22:24
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
Question

So it is still better to use ids than names, right?
Reply With Quote
  #4 (permalink)  
Old 01-08-11, 22:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by Acute View Post
So it is still better to use ids than names, right?
no, not right

you can't make absolute statements like that -- it depends on the situation
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-08-11, 22:55
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
Question

So my situation is:
I want to display microblogs like in twitters. To be more precise authors name, age, sex, posting date and the message of all friends will be displayed to the user.
So, my question is how my database should be structured? author_id | message and then retrieve one more time the user information using the id,
or use author_id | author_name | author_sex | author_age | message to avoid extra querying?

Thanks in advance

Last edited by Acute; 01-08-11 at 23:00.
Reply With Quote
  #6 (permalink)  
Old 01-09-11, 01:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
use the join query
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 01-13-11, 01:01
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
Hi, guys)
I have read about JOIN and that is really what I need. However, I've heard that JOINs slow down everything(do they?) and it would be good to use VIEWs. But in my situation the WHERE clause is always different, so how to use VIEW if my WHERE clause is always different??? (in my site each time when registered user logs in, his/her friends activity should be displayed(like in fb or twitter), so the WHERE clause is like "WHERE friend1 = $currentUser")
Reply With Quote
  #8 (permalink)  
Old 01-13-11, 07:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by Acute View Post
However, I've heard that JOINs slow down everything(do they?)
no, you heard wrong, i'm afraid

Quote:
Originally Posted by Acute View Post
so how to use VIEW if my WHERE clause is always different???
one way would be to declare the view without the WHERE clause

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On