lordvader Posted August 4, 2008 Share Posted August 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 4, 2008 Share Posted August 4, 2008 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` Quote Link to comment Share on other sites More sharing options...
lordvader Posted August 4, 2008 Author Share Posted August 4, 2008 Thanks, will try the Explain. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.