Jump to content

Optimizing a MySql Query (Concept, not Code)


Recommended Posts

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?

  • 2 weeks later...
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.