Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4272252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:33:09+00:00 2026-05-21T07:33:09+00:00

Hey I have a very slow MySQL query. I’m sure all I need to

  • 0

Hey I have a very slow MySQL query. I’m sure all I need to do is add the correct index but all the things I try don’t work.

The query is:

SELECT DATE(DateTime) as 'SpeedDate', avg(LoadTime) as 'LoadTime'
FROM SpeedMonitor
GROUP BY Date(DateTime);

The Explain for the query is:

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  SpeedMonitor    ALL                 7259978 Using temporary; Using filesort

And the table structure is:

CREATE TABLE `SpeedMonitor` (
  `SMID` int(10) unsigned NOT NULL auto_increment,
  `DateTime` datetime NOT NULL,
  `LoadTime` double unsigned NOT NULL,
  PRIMARY KEY  (`SMID`)
) ENGINE=InnoDB AUTO_INCREMENT=7258294 DEFAULT CHARSET=latin1;

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:33:10+00:00Added an answer on May 21, 2026 at 7:33 am

    You’re just asking for two columns in your query, so indexes could/should go there:

    • DateTime
    • LoadTime

    Another way to speed your query up could be split DateTime field in two: date and time.
    This way db can group directly on date field instead of calculating DATE(…).

    EDITED:
    If you prefer using a trigger, create a new column(DATE) and call it newdate, and try with this (I can’t try it now to see if it’s correct):

    CREATE TRIGGER upd_check BEFORE INSERT ON SpeedMonitor
    FOR EACH ROW
    BEGIN
      SET NEW.newdate=DATE(NEW.DateTime);
    END
    

    EDITED AGAIN:
    I’ve just created a db with the same table speedmonitor filled with about 900,000 records.
    Then I run the query SELECT newdate,AVG(LoadTime) loadtime FROM speedmonitor GROUP BY newdate and it took about 100s!!
    Removing index on newdate field (and clearing cache using RESET QUERY CACHE and FLUSH TABLES), the same query took 0.6s!!!
    Just for comparison: query SELECT DATE(DateTime),AVG(LoadTime) loadtime FROM speedmonitor GROUP BY DATE(DateTime) took 0.9s.
    So I suppose that the index on newdate is not good: remove it.
    I’m going to add as many records as I can now and test two queries again.

    FINAL EDIT:
    Removing indexes on newdate and DateTime columns, having 8mln records on speedmonitor table, here are results:

    • selecting and grouping on newdate column: 7.5s
    • selecting and grouping on DATE(DateTime) field: 13.7s

    I think it’s a good speedup.
    Time is taken executing query inside mysql command prompt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all, so basically I have a very simple layout with a header image,
Hey guys, i have the following problem: 1 process executes a very large query
Hey. I have a very large array and I want to find the Nth
Hey I have downloaded one of the xml editors from some site. But don't
Hey I have this code but it doesn't work because it is expecting a
Hey, I'm very newbie to xPath and time is against me, I don't have
Hey guys i have a ListActivity... a very simple at that... and it keeps
Hey there, i got this very annoying problem: I have a CheckBoxList getting items
Hey guys, I have a little issue here. I need my users to be
Hey all my fellow geeks out there! I need to save objects from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.