Jump to content

What exactly is Indexing?


chantown

Recommended Posts

Hi, I have read that indexing will make your queries faster, but it requires more hard drive space.

 

What exactly is it , and how should I do it for my situation?

 

I am building a forum much like SMF.

Usually I am selecting many things, so much of my queries are SELECT * FROM ...where topic_id = ... stuff like that

 

Since I am selecting * all the time (all the columns I need to select), should I index EVERY column?

 

Do I index the stuff being DRAWN or the stuff being SEARCHED?

 

Like, how do I determine what to index or what not to index

 

many thanks!

Link to comment
Share on other sites

It's not a simple question.  But in general, you should index at least one column from the "WHERE" conditions of your queries.

 

For example, if you are always searching "where topic_id = ...", then you will very likely get a more efficient system by creating an index on topic_id.

 

In nearly all cases, you should index the stuff SEARCHED.  But in some rare cases you can in fact benefit from indexing the stuff DRAWN.  I would not worry about that yet though.

 

To find if you need an index or not, try timing your queries.  If the query is looking slow, take a look at the "where" clause and consider what index would narrow down the possible values enough to make the query fast.

Link to comment
Share on other sites

When I refresh a page to get the updated stuff on my forum (time of posts, usernames, topic titles), I find that when i use "top" in my Linux, the MYSQL Process uses 3.9% of CPU power. Is this normal? And will it decrease when I index?

 

(I have a pentium D 3.0 Dual core 4 GB ram)

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.