MySQL Forums
Forum List  »  MyISAM

Re: I need Optimizaton of a Query - DISTINCT
Posted by: Rick James
Date: October 17, 2010 10:51PM

540x speedup -- even better than I would have guessed.

SELECT  DISTINCT u.id AS userid,
        IFNULL( c.id, a.catid ) AS catid,
        IFNULL( s.id, a.sectionid ) AS secid,
        a.id AS id,
        a.* ,                  -- some of this is duplicated
        a.introtext AS itext,
        a.fulltext AS mtext,
        u.name AS author,
        u.usertype,
        u.email AS authorEmail,
        a.created_by_alias AS authorAlias,
        a.created AS dsdate,
        c.name AS catName,
        CASE WHEN CHAR_LENGTH( a.alias ) THEN CONCAT_WS( ":", a.id, a.alias ) ELSE a.id END AS slug,
        CASE WHEN CHAR_LENGTH( c.alias ) THEN CONCAT_WS( ":", c.id, c.alias ) ELSE c.id END AS catslug
    FROM  
      ( SELECT  *            -- suggest listing only the rows needed
            FROM  jos_content
            WHERE  state = '1'
              AND  access <= 0
              AND  ( publish_up   = '0000-00-00 00:00:00' OR  publish_up   <= '2010-10-13 15:51:07' )
              AND  ( publish_down = '0000-00-00 00:00:00' OR  publish_down >= '2010-10-13 15:51:07' )
            ORDER BY  created DESC
            LIMIT  20 ) AS a
    LEFT JOIN  jos_users AS u ON u.id = a.created_by
    LEFT JOIN  `jos_categories` AS c ON c.id = a.catid
    LEFT JOIN  `jos_sections` AS s ON s.id = c.section
    WHERE  a.state = '1'
      AND  a.access <=0
      AND  ( c.access <=0 OR  a.sectionid =0 )
      AND  ( s.access <=0 OR  a.sectionid =0 )

That looks like the direction I was taking you.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: I need Optimizaton of a Query - DISTINCT
1581
October 17, 2010 10:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.