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?

Link to comment
Share on other sites

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".
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.