If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Slow performance of SQL statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-20-06, 23:43
qxz qxz is offline
Registered User
 
Join Date: Apr 2002
Posts: 84
Question Slow performance of SQL statement

Dear All,

I have the following SQL statement in MySQL that needs to join some tables. It seems that it is not quite efficient, which caused the program to be slow. Is there anyway to fine tune it? Thanks!

----------------------------------------------------------------------
SELECT REPORT_DATE, MAINT_COUNTRY_CODE, REPORT_TYPE_NAME, REPORT_TITLE, REPORT_DESC, REPORT_RATING, REPORT_ID, MAINT_SECTOR_NAME FROM TBL_REPORT JOIN TBL_MAINT_COUNTRY ON TBL_REPORT.REPORT_COUNTRY = TBL_MAINT_COUNTRY.MAINT_COUNTRY_ID JOIN TBL_REPORT_TYPE ON TBL_REPORT.REPORT_REPORT_TYPE = TBL_REPORT_TYPE.REPORT_TYPE_ID INNER JOIN TBL_MAINT_SECTOR ON MAINT_SECTOR_ID=REPORT_SECTOR_ID WHERE (REPORT_REPORT_TYPE = '8' OR REPORT_REPORT_TYPE='6') AND RPT_SECTOR_ID = '1' AND REPORT_STATUS = 'A' ORDER BY REPORT_DATE DESC"
Reply With Quote
  #2 (permalink)  
Old 05-21-06, 07:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yes, there is an easy way to optimize this query -- make sure you have declared an index on each join column (note: primary key counts as an index)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On