BioBob Posted September 22, 2009 Share Posted September 22, 2009 This is more of a CONCEPT issue than actual coding question. I have a rather complex query. Lot of conditional statements. One of the statements, when I run it by itself and totally exclude the rest of the statements runs just snappy. But when I include this statement into the whole query, it runs slower than I want. About half a second. Especially considering when I run the whole script without this, I get results back in about 0.01 seconds, for BOTH the whole query without one of the AND statements, and the AND statement when it is run by itself. Put em together and VOILA! Half Second Query Time So, the question becomes this: Can the ORDER of where AND clauses are in a Query affect its performance? And if so, where should I put the query in the complex statement, beginning or end? Select * From somewhere WHERE (simple statement, like indexed user_name = 'Whatever') AND (complex statement with subselects n stuff like that) VS (complex statement with subselects n stuff like that) AND (simple statement, like indexed user_name = 'Whatever') Does it make any difference as to the order of the conditional statements? Quote Link to comment https://forums.phpfreaks.com/topic/175061-optimizing-a-mysql-query-concept-not-code/ Share on other sites More sharing options...
fenway Posted October 2, 2009 Share Posted October 2, 2009 Everything can affect performance. Show us both statements, table structures, and EXPLAIN output for both. Quote Link to comment https://forums.phpfreaks.com/topic/175061-optimizing-a-mysql-query-concept-not-code/#findComment-929122 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.