What is going on with my user and max date query? OK query below.   Hitting about a half million rows and I am trying to grab the last time a user (uid) touched a page on our system denoted by LogDate.   I have used this query quite a few times but applying it to a bigger table seems to cause issues.   Let me review.


Keeping query is I can only grab about 8k rows or my query will just lock up - not getting much in logs.   
If I limit to 1000 it takes 2 seconds.   If I change it to 2k it takes 77 seconds.   8k takes about 88 seconds.   After that... nothing.
If I take out the Distinct part it is obviously faster.   However I still can't grab the rows I need so it doesn't matter.    I have tried adjusting Innob memory settings which seems to have zero effect.



SELECT DISTINCT
  `t1`.`uid`,
  `t1`.`LogDate` AS `touchdate`
FROM
  (
      `ref_source_page_log_report` `t1`
      LEFT JOIN `ref_source_page_log_report` `t2` ON (
          (
              (`t1`.`uid` = `t2`.`uid`)
              AND (
                  (
                      `t1`.`LogDate` &lt; `t2`.`LogDate`
                  )
                  OR (
                      (
                          `t1`.`LogDate` = `t2`.`LogDate`
                      )
                      AND (`t1`.`uid` &lt; `t2`.`uid`)
                  )
              )
          )
      )
  )
WHERE
  isnull(`t2`.`uid`)
LIMIT 10000
I've tried to rid of the excessive parentheses and backticks so I've got the next query: 

  SELECT 
    t1.uid,
    t1.LogDate AS touchdate
  FROM      ref_source_page_log_report AS t1
  LEFT JOIN ref_source_page_log_report AS t2 
         ON t1.uid = t2.uid 
        AND ( t1.LogDate &lt; t2.LogDate OR
            ( t1.LogDate = t2.LogDate AND t1.id &lt; t2.id ))
                 -- Here was the problem: ^^^^^^^^^^^^^ (uids instead of ids)
  WHERE t2.uid IS NULL
  LIMIT 10000