Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Optimizing a MySQL query created with Navicat GUI

Posted on 2011-03-07
4
Medium Priority
?
1,841 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 1000 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 1000 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

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. . .
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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