Jump to content

Better to Create a Redundant Column or Make a Second Call to the Database


ScrollMaster

Recommended Posts

MySql 5, PHP 5
Hello, I am working on a forum system and I have a question to ask. I had tried mysqlfreaks but there forum system is down.

I am working on generating all the posts for a thread.

I have two tables, a table for users and a table for posts.

I would like to know if it would be better to create a column with the userid and username in the post table so I do not have to make a call to the user table and extract that username that matches the userid.

I think that creating a redundant column would be a waste of space in the database but having it there would make the query faster.

So what do I do?
Option 1: Make the Call to the user table to find the user name to save database space
Option 2: Make a Redundant Column in the post table to save query time
Option 3: Someone tells me of a magical way of making a call to both database in one query?
Option 4: I write my code where it can access itself that the user table is so big that to make a call to it everytime for the posts is expensive and It should add that secound column to the post table.

Which Option should I choose?

I think you know the answer to your question. Putting redundant data in your posts table will create all kinds of problems and any speed increase will be negligible.

You can retrieve the post and username in one query with a simple join something like "select posttable.post, usertable.userid from posttable, usertable where posttable.userid=usertable.userid".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.