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

  • Home
  • SEARCH
  • 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 7983367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:56:19+00:00 2026-06-04T10:56:19+00:00

Can someone help me please or explain to me on how to make my

  • 0

Can someone help me please or explain to me on how to make my query faster ? This query take almost 10seconds (on my local machine) with almost 1GB data.

Here is my explain and explain resuls

    explain select p.delivery_date, p.delivery_hour, p.resource_id, p.participant_id, p.price, p.date_posted, hour(p.date_posted) as hour_date_posted, date(p.date_posted) as date_date_posted
    ,s.mw
from prices_report as p
left join schedules_report s
on s.delivery_date = p.delivery_date
                    AND s.type_id = p.type_id
            and s.delivery_hour = p.delivery_hour
                    and s.resource_id = p.resource_id
                    and s.participant_id = p.participant_id
                    and hour(s.date_posted) = hour(p.date_posted)
                    and date(s.date_posted) = date(p.date_posted)
WHERE p.delivery_date = '2012-05-22'
AND p.type_id = 'GEN'
ORDER BY p.delivery_date, p.resource_id, p.delivery_hour, p.participant_id, p.type_id, p.date_posted

enter image description here

explain results :
id : 1
select type : simple
table : p
type : ref
possible keys : idx1
key : idx1
key_len : 4
ref : const
rows : 40258
extra : using where

id : 1
select type : simple
table : s
type : ref
possible keys : idx1
key : idx1
key_len : 63
ref : const,APC_DB.p.delivery_hour,APC_DB.p.participant_id,APC_DB.p.resource_id,const
rows : 99
extra :

table structure :

  CREATE TABLE `prices_report` (
  `id` int(11) NOT NULL auto_increment,
  `delivery_date` date default NULL,
  `delivery_hour` int(2) default NULL,
  `participant_id` varchar(10) default NULL,
  `resource_id` varchar(15) default NULL,
  `type_id` varchar(10) default NULL,
  `price` float default NULL,
  `date_posted` datetime NOT NULL,
  `date_created` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `IDX1` USING BTREE (`delivery_date`,`resource_id`,`delivery_hour`,`participant_id`,`type_id`,`date_posted`)
) ENGINE=MyISAM AUTO_INCREMENT=5261441 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;


CREATE TABLE `schedules_report` (
  `id` int(11) NOT NULL auto_increment,
  `delivery_date` date default NULL,
  `delivery_hour` int(2) default NULL,
  `participant_id` varchar(15) default NULL,
  `resource_id` varchar(20) default NULL,
  `type_id` varchar(10) default NULL,
  `mw` float default NULL,
  `loss_factor` float default NULL,
  `date_posted` datetime NOT NULL,
  `date_created` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `IDX1` USING BTREE (`delivery_date`,`delivery_hour`,`participant_id`,`resource_id`,`type_id`,`date_posted`)
) ENGINE=MyISAM AUTO_INCREMENT=43369 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

Million thanks

  • 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-06-04T10:56:20+00:00Added an answer on June 4, 2026 at 10:56 am

    The problem seems to be the “fuzzy matching”:

    LEFT JOIN ... ON ...
    and hour(s.date_posted) = hour(p.date_posted)
    and date(s.date_posted) = date(p.date_posted)
    

    forces MySQL to calculate hour(s.date_posted) and date(s.date_posted) for all rows in s, every time it touches a row in p.

    Give this a try:

    and s.date_posted
      BETWEEN DATE_SUB(p.date_posted, INTERVAL TIME_TO_SEC(MAKETIME(0,MINUTE(p.date_posted),SECOND(p.date_posted))) SECOND)
      AND DATE_ADD(DATE_SUB(p.date_posted, INTERVAL TIME_TO_SEC(MAKETIME(0,MINUTE(p.date_posted),SECOND(p.date_posted))) SECOND), INTERVAL 1 HOUR)
    

    Edit:

    If you can live with leap seconds being calculated wrongly, this can be written as a more human readable

    and s.date_posted
      BETWEEN DATE_SUB(p.date_posted, INTERVAL 60*MINUTE(p.date_posted)+SECOND(p.date_posted) SECOND)
      AND DATE_ADD(DATE_SUB(p.date_posted, INTERVAL 60*MINUTE(p.date_posted)+SECOND(p.date_posted) SECOND), INTERVAL 1 HOUR)
    

    Edit 2:
    Repetition of part of the calculated value in the upper limit of the BETWEEN is on purpouse: MySQL will calculate it only once.

    Edit 3:
    Now seeing your SHOW CREATE TABLE, I understand you don’t have a separate index on date_posted, but just a combined index. You might want to try

    ALTER TABLE `schedules_report` ADD INDEX(date_posted)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please help explain why I can't get this to work? I properly
Can someone explain to me this code new Object[]{PLease,Help}; Ive never seen code like
can someone please help me. why does this return an error: Dim stuff As
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Im a beginner to css, please can someone help me get this element to
Can someone please help quickly mute or unmute the stage volume in Flash CS3
Can someone please help me with using Regex with NSPredicate? NSString *regex = @(?:[A-Za-z0-9]);
Can someone please help me figure out a way to achieve the following (see
Can someone please help me to force my website to redirect to using www.
Please can someone help? I have the following code which uploads a file to

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.