Solved

Optimizing a MySQL query created with Navicat GUI

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help With Simple Database Design 7 57
Display SQL 2008 last modified/update Database 11 46
Duplicated data in GROUP_CONCAT 2 16
mysql qry 1 20
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Read about achieving the basic levels of HRIS security in the workplace.
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…

740 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