The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > UNIX and Linux Applications
.
google unix.com



UNIX and Linux Applications Discuss UNIX and Linux software applications. This includes SQL, Databases, Middleware, MOM, SOA, EDA, CEP, BI, BPM and similar topics.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Oracle: fixing an outer join on subquery... Elric of Grans High Level Programming 0 03-16-2009 12:43 AM
Alternative to date +%s Data469 HP-UX 6 03-31-2008 03:28 PM
Using awk (or an alternative) michaeltravisuk Shell Programming and Scripting 5 03-08-2007 11:37 PM
.NET Alternative goon12 UNIX for Dummies Questions & Answers 3 04-06-2005 12:07 PM
cut -f (or awk alternative) gefa Shell Programming and Scripting 6 03-02-2005 01:26 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-05-2009
whoknows whoknows is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
Cool Alternative for slow SQL subquery

Hi -- I have the following SQL query in my UNIX shell script -- but the subquery in the second section is very slow. I know there must be a way to do this with a union or something which would be better. Can anyone offer an alternative to this query? Thanks.
Code:
select
        count(*)
from
        employee_tbl
where
        employee_status_cd = 'C'
        or
        (
                employee_type_cd NOT IN ('TMGR', 'DIR')
                or
                (
                        employee_type_cd = 'MGMT'
                        and pay_grade_cd NOT BETWEEN '11' and '29'
                )
        )
        or
        (
                employee_type_cd = 'C'
                and comp_pay_pct = 0
                and employee_id in (select PT.employee_id
                from
                        payroll_tbl PT
                where
                        PT.specl_comp_cd = '21')
        )
;

Last edited by jim mcnamara; 10-05-2009 at 11:25 AM.. Reason: USE CODE TAGS please!
  #2 (permalink)  
Old 10-05-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Did you run tkprof? ( alter session set sql_trace true then run tkprof on the dump?
if the subselect returns thousands of hits from the db, or PT.specl_comp_cd is not indexed and the table contains millions of rows then you have a problem. Is employee id indexed in the payroll_tbl?
  #3 (permalink)  
Old 10-07-2009
whoknows whoknows is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
I don't have permissions to run sql_trace. Employee_id is the key field but it is not indexed.
Reply

Bookmarks

Tags
select, sql, sub-query

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0