MySQL Forums
Forum List  »  Performance

Re: speed of query/can index help?
Posted by: Rick James
Date: June 27, 2009 10:39AM

select count('syslogD.syslogD_key') from syslogD;
The stuff in the () is irrelevant. Suggest this instead:
select count(*) from syslogD;

If it is MyISQM, the COUNT(*) will be very fast. If it is InnoDB, it will be slower -- it has to traverse some index.

FULLTEXT seems irrelevant.

select  syslogD.sev, syslogD.msgNum, count('syslogD.sev'),
        syslogD.message
    from  syslogD
    where  day='26'
    group by  msgNum;
is better written as
select  s.sev, s.msgNum, count(*),
        s.message
    from  syslogD AS s
    where  day=26  -- assuming 'day' is numeric, not a string
    group by  msgNum; -- this is suspect
Why are you grouping by one thing, but have 3 non-aggregrates in the SELECT? This is usually a mistake. Also, if msgNum is unique, the GROUP BY does nothing and the COUNT(*) will always be 1. Assuming the above is correct, then this might be optimal:
INDEX (day, msgNum)

Perhaps you wanted:
select  s.sev, s.msgNum, count(*),
        s.message
    from  syslogD AS s
    where  day=26
    group by  s.sev, s.msgNum, s.message;
    order by  s.sev, s.msgNum, s.message;
The index you need should start with 'day', and should (in this case) continue with the group by fields (in the same order):
INDEX (day, sev, msgNum, message)


To assist in analyzing slow SELECTs, please provide
* SHOW CREATE TABLE tbl\G
* SHOW TABLE STATUS LIKE 'tbl'\G
* EXPLAIN SELECT ...\G
and surround them with [ code ] and [ / code ]

Options: ReplyQuote


Subject
Views
Written By
Posted
4066
June 26, 2009 06:15PM
1894
June 26, 2009 08:56PM
1970
June 27, 2009 03:04AM
Re: speed of query/can index help?
1825
June 27, 2009 10:39AM
1784
June 30, 2009 12:26AM
1930
June 30, 2009 10:36PM
1739
July 01, 2009 08:22PM


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.