Jump to content

Recommended Posts

From my experience if you have one index on each field, as opposed to having one on both, it will not use the index.

 

I recently had an issue where I was not indexing on both fields (and instead had two indexes on each individual field) and my query was taking literally 90 seconds. I added the index on both fields and it cut it down to like 800ms.

Link to comment
https://forums.phpfreaks.com/topic/194818-index-question/#findComment-1026653
Share on other sites

Well, 5.1 has index_merge, so you can sometimes get around the "one index per table" issue.

 

Also:

 

This increases performace also for InnoDB. And another thing to consider is order of columns in index defintion.

 

WHERE column1 = ? AND column2 = ? will use index created on (column1,column2) but not on (column2, column1).

That's not actually true -- the optimizer will handle this quite easily.  The order only matter when there are not equality constraints; in that case, the constant needs to go first.  That is:

 

WHERE column1 = ? AND column2 >= ?  will use the index

 

BUT

 

WHERE column1 >= ? AND column2 = ?  won't.

Link to comment
https://forums.phpfreaks.com/topic/194818-index-question/#findComment-1028551
Share on other sites

so if i have a table with multiple single column indexes and i do something like:

 

select * from table where column1 = value1 and column2 = value2 etc etc.

 

and there is an index for column 1 and column 2, MySQL will only use the index on one of them and not both?

Link to comment
https://forums.phpfreaks.com/topic/194818-index-question/#findComment-1030204
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.