Jump to content

MySQL performance with large tables


rcouser

Recommended Posts

Hi,

I need help with mysql performance with large tables. I have the following tables:

Person (8,021 Records)
---
ID (Primary Key)
Title (varchar)
FirstName (varchar)
Surname (varchar)
ContactDetails (text)
PersonCode (int)

Booking (79,378 Records)
---
ID (Primary Key)
StartDate (datetime)
FinishDate (datetime)
BookingCode (int)
RunCode (int)
BookingTypeCode (int)
PersonBooking (171,563)
---
ID (Primary Key)
PersonCode (int)
BookingCode (int)
IsDriver (varchar) 

 

It is taking 8.4983 sec just to display 31 results with the query below, anyone any idea how I could speed this up.

Kind Regards.

 

SELECT t1.BookingCode, t1.IsDriver, t2.RunCode, t2.Duration, t2.BookingTypeCode, DATE_FORMAT(t2.StartDate, '%a') AS StartDay, DATE_FORMAT(t2.StartDate, '%H:%i') AS StartTime FROM person_booking t1 
LEFT JOIN booking t2 ON t1.BookingCode = t2.BookingCode 
WHERE t1.PersonCode = 21280 
AND (t2.StartDate >= '2012-07-02' AND t2.StartDate < '2012-07-09') 
ORDER BY t2.StartDate 

Link to comment
Share on other sites

show us the EXPLAIN PLAN,

 

what INDEXES you person_booking and booking tables have?... most likely you need to have indexes on the fields BookingCode of your table Bookings and in the fields PersonCode and BookingCode in your table PersonBooking... (it is named PersonBooking or person_booking?)...

 

in an additional observations:

- is there any reason for you to use an ID field in your table Booking?... is not enough to use just the BookingCode as PK?

- the ID field on the table PersonBooking could be dropped too

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.