Solved

Optimizing a MySQL query created with Navicat GUI

Posted on 2011-03-07
4
1,600 Views
Last Modified: 2012-05-11
Using the Navicat for MySQL query gui, I made this

SELECT SS_Student_Schedules.Id AS StudentID, SS_Student_Schedules.ClassCode as CourseID, SS_Class_Master_Local.Period_1 as Period, SS_Class_Master_Local.Sect as Section FROM (SS_Student_Schedules INNER JOIN SS_Class_Master_Local ON (SS_Student_Schedules.ClassSect = SS_Class_Master_Local.Sect) AND (SS_Student_Schedules.ClassCode = SS_Class_Master_Local.Class) AND (SS_Student_Schedules.Schl = SS_Class_Master_Local.School)) INNER JOIN DG_Student_Master ON SS_Student_Schedules.Id = DG_Student_Master.StudId WHERE (((DG_Student_Master.CurStatus)='C' Or (DG_Student_Master.CurStatus)='R' Or (DG_Student_Master.CurStatus)='O'))

It pulls the correct data, but it is extremely slow. Is there anything I can do to optimize it? Thank you!
0
Comment
Question by:smetterd
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
Muhammad Wasif earned 250 total points
ID: 35062693
To optimize query we need the structure of the involved tables. Did you try EXPLAIN to identify the bottlenecks?

Some basic rules to optimize a query
1. Avoid temporary tables
2. INDEX columns which are being used in WHERE and in JOIN
3. Select only those columns which are required

Google to find other query optimization tips.
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 250 total points
ID: 35062971
Can you try this?
SELECT SS_Student_Schedules.Id        AS StudentID, 
       SS_Student_Schedules.ClassCode AS CourseID, 
       SS_Class_Master_Local.Period_1 AS Period, 
       SS_Class_Master_Local.Sect     AS Section 
  FROM SS_Student_Schedules 
       INNER JOIN SS_Class_Master_Local 
         ON SS_Student_Schedules.ClassSect = SS_Class_Master_Local.Sect 
            AND SS_Student_Schedules.ClassCode = SS_Class_Master_Local.Class 
            AND SS_Student_Schedules.Schl = SS_Class_Master_Local.School 
       INNER JOIN DG_Student_Master 
         ON SS_Student_Schedules.Id = DG_Student_Master.StudId 
 WHERE DG_Student_Master.CurStatus IN ('C','R','O')

Open in new window

0
 
LVL 2

Author Comment

by:smetterd
ID: 35065074
Thank you, I will check on these items in the a.m. when I get to work. It already sheds some light since I am importing from an ODBC connection from COBOL into MySQL via Navicat. No keys are made, so I suspect I will have to add them. Stay tuned, and thanks again.
0
 
LVL 2

Author Closing Comment

by:smetterd
ID: 35073256
I implemented both suggestions, ran it, and BAM! FAST! Thank you!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now