Which type of schema is the best one?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eshwarz
Forum Newbie
Posts: 1
Joined: Fri Nov 05, 2010 5:33 pm

Which type of schema is the best one?

Post by eshwarz »

Hi people,

I have social networking site, which store friends in it. For that i have schema as shown in the image

Image

Type 1:

This is the basic method of storing friends, it consists of userid and friendid, but let us say a user has 500 friends on average, in that case for total users of 10,000 database contains 5,000,000 which seems pretty much scary to me.

Type 2

This schema will have only 1 row per each user, and all friendids are stored seperated by comma, for quering friends of a user we just need to select that row and explode it.

Problem is...

1.Is the second schema reliable?
2.Does it break any rules of database?
3.Is querying faster than first schema?
4.Any demerits of this schema?

Please help me .
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Which type of schema is the best one?

Post by s.dot »

type 1
querying for data is much easier

type 2 is irrational and not normalized

the amount of database table rows is largely irrelevant with proper indexing
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply