Jump to content

Recommended Posts

I got a question which I will use an example which everyone can understand, let's say you have a forum.  Now you want to show the post count of a user.  Now there are two ways of doing it, slow and taxing on the server vs faster and instant.

 

A.  Count all the posts of a user

B.  Have a column strictly for post count

 

Now, if someone was going to go B., it would be quicker.  The actual question is, let's say you have multiple instances where going the B. route would be more efficient, is having 5-20 extra columns a bad thing in a database table? 

 

Is there such thing as too many columns, as going the B. way would be much more efficient?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/190343-extra-columns-slow-down-sql/
Share on other sites

It mostly depends on how often you would do this operation (displaying post-count). Also remember, that keeping this value updated also requires some resources.

As far as extra columns slowing down the database... not really unless you do SELECT * a lot. You can also do vertical partitioning by moving some of the columns to another table in 1-to-1 relation with your users table.

 

And yeah, there is a maximum limit of columns in MySQL table. It's in manual... somewhere... I always have problems finding it... :P It's more than 200 AFAIR.

yes, I was thinking another table just for something like this.

 

And yeah I understand that it'd have to be constantly updated.

 

In the example for instance, every post would require atleast 2 query's, one for the post and than one to update the count

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.