Solved

Optimizing a MySQL query created with Navicat GUI

Posted on 2011-03-07
4
1,668 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

808 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