Jump to content

[SOLVED] WHERE optimization: group uniques/indexes together first, or go by column order?


lordvader

Recommended Posts

Let's say my table has lots of columns, and every 5th column is an index.

Then let's say I need results from severl indexes, and also from column #2 (which is not an index).

 

Is it better to group all the indexes at teh front of my WHERE, or should I just go in order of the table's columns?

To illustrate:

 

WHERE index_column_1 = whatever

AND index_column_5 = whatever

AND index_column_10 = whatever

AND column_2 = whatever

 

versus:

 

WHERE index_column_1 = whatever

AND column_2 = whatever

AND index_column_5 = whatever

AND index_column_10 = whatever

 

Thanks

Link to comment
Share on other sites

Use the EXPLAIN function in front of a query and see how it builds (phpmyadmin is best for this) and look at the result or post em here for each query type.  I do believe however it does work from left to right so if you are running faster queries on larger datasets first (indexed items) You reduce the total rows being checked as you go down the first WHERE item has all the table rows to check then the next might have half then a quarter etc.

 

example

EXPLAIN
Select * from `table`

 

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.