Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 23rd, 2007, 11:22 AM
Authorized User
 
Join Date: Jun 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jlrolin Send a message via MSN to jlrolin
Default SQL Optimization - Query takes a long time

I need some help. I've optimized it to the best that I knew how, but
I'm not an SQL genius when it comes to multiple joins and subqueries.

Code:
SELECT 
    CO.CONF_TRACK_CD AS CONF_TRACK_CD, 
    CO.COURSE_OFFERING_ID AS COURSE_OFFERING_ID,
    CO.END_DATE AS END_DATE, 
    CO.END_TIME AS END_TIME,
    COALESCE(MAX_CAPACITY, 0) AS MAX_SPACE, 
    COALESCE(MAX_CAPACITY, 0) - COALESCE(REG.NUMREG, 0) AS NUM_LEFT, 
    CO.OFFERING_NAME AS OFFERING_NAME, 
    COALESCE(REG_PER.REGISTRATION_ID, 0) AS REGID, 
    CO.START_DATE AS START_DATE, 
    CO.START_TIME AS START_TIME

FROM  
  COURSE_OFFERING CO INNER JOIN
  COURSE ON CO.COURSE_ID = COURSE.COURSE_ID INNER JOIN
   (SELECT COUNT(REGISTRATION_ID) AS NUMREG, COURSE_OFFERING_ID
      FROM REGISTRATION
      WHERE DELETED_IND = 'N'
      GROUP BY COURSE_OFFERING_ID)REG ON 
   REG.COURSE_OFFERING_ID = CO.COURSE_OFFERING_ID INNER JOIN
   (SELECT REGISTRATION_ID, COURSE_OFFERING_ID, DELETED_IND
    FROM REGISTRATION
    WHERE PEOPLE_ID = '01_USER' AND DELETED_IND = 'N') REG_PER 
    ON REG_PER.COURSE_OFFERING_ID = CO.COURSE_OFFERING_ID

WHERE 
    (CO.EVENT_ID = 199552189) AND
    (CO.START_DATE = '04-02-2006') AND 
    (CO.DELETED_IND = 'N') AND 
    (CO.CONF_TRACK_CD IS NOT NULL) AND 
    (CO.CONF_TRACK_CD <> '')

ORDER BY CO.START_TIME
Main problem, the second subquery:

(SELECT REGISTRATION_ID, COURSE_OFFERING_ID, DELETED_IND
    FROM REGISTRATION
    WHERE PEOPLE_ID = '01_USER' AND DELETED_IND = 'N')

That query is a huge hit in performance, any suggestions?




________________________
ASP.NET 1.1 Developer
VB.NET Developer
__________________
________________________
ASP.NET 1.1/2.0 Developer
VB.NET Developer
 
Old March 20th, 2007, 01:59 AM
Authorized User
 
Join Date: Sep 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you provide the following information:
- indices on the table
- number of rows in each table
- primary key in each table

This way I can advise what to do.

http://geertverhoeven.blogspot.com
 
Old March 20th, 2007, 08:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

jlrolin,

Yes, that makes sense. you should be providing those info (as asked by GeertVerhoeven) along with your post to have a better solution provided here.

How about posting those info?

Cheers

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Long SQL Query (>1024) in VBA??? mlep Excel VBA 1 June 14th, 2007 08:41 PM
ISS Problem: Takes a long t ime to refresh/Connect rtr1900 Classic ASP Components 0 February 27th, 2006 05:58 AM
SP takes long time but reboot fixes it Mitch SQL Server 2000 2 January 6th, 2006 06:02 AM
Sub Report Takes long Time ketanpatel Crystal Reports 0 December 3rd, 2004 04:11 AM
Query optimization SubodhKumar SQL Language 1 October 22nd, 2003 06:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.