Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Have large table (Sybase) rows = 6276225. I'm pulling call status and my query is very slow.

In effect what I’m trying to do is pull data for any event after my variable. While querying for just one acct, the query takes around 15 sec, anything larger and my query runs forever.

How can I speed up my query?

declare 
@RSP varchar (2)
SET
@RSP = 'WN'

select
a.contact_list_name,
a.agent_login_name,
a.account_number,
a.ov_phone_number,
a.time_of_contact,
a.response_status

from table a

where  a.time_of_contact >=
                      (SELECT 
                       b.time_of_contact
                      FROM table b
                      WHERE  a.account_number = b.account_number
                             and a.ov_phone_number = b.ov_phone_number
                             and a.time_of_contact >= b.time_of_contact
                             and b.contact_list_name ='Prime_list'
                             and b.response_status = @RSP)
share|improve this question
    
A non-correlated query could be faster but 15 seconds is still too much for one account. Please post the table schema and the explain plan. –  Jakub Kania Apr 27 '13 at 10:03
1  
@jason: 1: post the schema for table a and b, including indexes definitions. 2: How long will it take to run JUST the subquery. 3: Post the exection plans for both the full query and the subquery. –  MTIhai Apr 30 '13 at 8:24
    
@jason - Sybase is a company, not a database. Which Sybase product are you using? –  Michael Gardner May 1 '13 at 11:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.