The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
INSERT SELECT takes a long time to run
Discuss INSERT SELECT takes a long time to run in the MySQL Help forum on Dev Shed. INSERT SELECT takes a long time to run MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 7th, 2013, 08:11 PM
|
 |
A Change of Season
|
|
|
|
|
INSERT SELECT takes a long time to run
Hello;
I was wondering if I can somehow optimise this query. It takes such a long time to execute. So long that the browser times out!
EXPLAIN
Thank you.
Code:
INSERT INTO allotments_new
(package_id,
room_id,
hotel_id,
date_added,
day_date,
day_rate,
number_of_rooms,
status,
supplier_id,
day_of_the_week)
SELECT packages.id,
packages.room_id,
packages.hotel_id,
Curdate(),
annual_calendar.day_date,
low,
'0',
'b',
hotels.beta_supplier,
Dayname(annual_calendar.day_date)
FROM packages
INNER JOIN hotels
ON hotels.hotel_id = packages.hotel_id
AND hotels.status = 'active'
INNER JOIN hotelrooms
ON hotelrooms.room_id = packages.room_id
AND hotelrooms.status = 'active'
LEFT OUTER JOIN calendars_new
ON calendars_new.hotel_id = hotels.hotel_id
AND calendars_new.day_date BETWEEN
'2013-02-08' AND '2014-02-08'
LEFT OUTER JOIN allotments_new
ON allotments_new.package_id = packages.id
AND allotments_new.day_date BETWEEN
'2013-02-08' AND '2014-02-08'
AND calendars_new.day_date = allotments_new.day_date
LEFT OUTER JOIN annual_calendar
ON annual_calendar.day_date = calendars_new.day_date
AND annual_calendar.day_date BETWEEN
'2013-02-08' AND '2014-02-08'
WHERE packages.status = 'active'
AND packages.hotel_id > 1800
AND allotments_new.day_date IS NULL
Last edited by zxcvbnm : February 7th, 2013 at 09:13 PM.
|

February 8th, 2013, 03:46 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
|
for calendars_new and allotments_new, create composite indexes on (hotel_id,day_date) and (package_id,day_date) respectively
but i'm only guessing as i'm not a performance expert
|

February 10th, 2013, 07:04 PM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by r937 for calendars_new and allotments_new, create composite indexes on (hotel_id,day_date) and (package_id,day_date) respectively
but i'm only guessing as i'm not a performance expert | OH!!!!!It took 5 seconds!!!
Rudy  Rudy  Rudy  Rudy 
|

February 10th, 2013, 07:39 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by zxcvbnm | it's nice to be appreciated
even if it's just a bromance

|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|