Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.
        SELECT  

            *    #Case 1
            cp.* #Case 2

        FROM crawl_page AS cp
        LEFT JOIN artist AS a
            ON cp.cpURL LIKE CONCAT('%',a.artistPageID,'/',a.artistPageURL,'%')

        WHERE cpPageType = 'SONGS'
            AND cpPageAdded < (
                SELECT cpCrawlDate 
                FROM crawl_page 
                WHERE cpURL = 'http://www.example.com/page-52/'
            )

            AND a.artistID IS NULL  

        LIMIT 1

In this query when I use 1st case (selecting everything from both tables) time taken for query is fine about 0.468 sec.

But if I do case 2 (selecting only from main table) it takes hell much time 26 second.

It's not problem just to use case 1, but I can't get the idea how does it work and why?

Thanks

share|improve this question
1  
Have you tried executing the commands in different orders? (doing case 2 first, for example). MySQL will cache queries, so subsequent queries when the data hasn't changed will be much faster. –  GrandmasterB Jan 25 at 22:29
    
Sure I tried, I do them separately. –  George Garchagudashvili Jan 27 at 7:34
    
I dont see a reason for what you describe. You might want to do an EXPLAIN in mysql to see if there's anything different in the execution of the statement. –  GrandmasterB Jan 27 at 22:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.