Solved

Optimizing a MySQL query created with Navicat GUI

Posted on 2011-03-07
4
1,770 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 41

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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…

631 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