Jump to content

[SOLVED] Question on query efficiency


baconbeastnz

Recommended Posts

Hi there, I am hoping to be in a high load environment ( :) ) . Which would be more efficient.

 

For each photo I want to show associated comments.

 

So I could in table photo album have a comma seperated list of the comment ID's which relate to the comment table. This simply requires finding each row id.

 

OR I could simply search the comment table where pictureID = 7. This requires searching on the comment table which will grow huge.

 

So i guess my question is, when you specify a row id of the unique identifier does SQL actually search or does it just grab, as opposed to finding one with pictureID 7 (which is not a unique identifier) it would have to search...?

Link to comment
Share on other sites

"So i guess my question is, when you specify a row id of the unique identifier does SQL actually search or does it just grab, as opposed to finding one with pictureID 7 (which is not a unique identifier) it would have to search...?"

 

 

 

A unique constraint is basically just an index that requires only 1 of each entry to be present.

 

 

As such, in your terms, yes MySQL would just "grab" a unique row, but, with indexes it could also just "grab" non-unique rows.

 

 

So yes, as fenway said, stick with a normalized database.  The only time you should ever stray from normalizing your database is if it provides a needed performance boost, and there's no other way to achieve that.  (For example, in this situation you should just use indexes.)

 

 

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.