Click here to Skip to main content
16,020,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi hope you are well

I am currently facing an issue with the performance of my SQL script, the script returns what is required, when the data count gets to around 10 000 records then it starts slowing down sometimes taking up to 2 minutes to return a the count.

How could i improve my script to improve the speed?

So basically what i am trying to a achieve is i am trying to do a count of a particular process(Pro_id),based on a status

What i wanted to achieve is splitting each status into their own column rather than having them in their own row.

I have built in sub queries to do this but once data counts start getting to 10 000-12 000 records its taking sometime to return data and I am using this to monitor status so needs to be as quick as possible

What I have tried:

SQL
select int_desc "Interface",
       NVL((select count(*)
       from queue, "interface" where
       "interface" = interface_key
       and que_from_cde in
       (
        select queue_key from queue
       WHERE que_filepath like '\\MyNet\TESTING\' || "interface" ||  batch || '\%'
       and pro_id = 36 and status_id = 3
       )
       and pro_id in (80)
       and status_id = 1
       and que_interface_key = c.que_interface_key
       group by int_desc,status_id),0) as "Pending",
       NVL((select count(*)
       from queue,"interface" where
       que_interface_key = interface_key(+)
       and que_from_cde in
       (
       select queue_key from queue
       WHERE que_filepath like '\\MyNet\TESTING\' || interface || batch|| '\%'
       and pro_id = 36 and status_id = 3
       )
       and pro_id in (80)
       and status_id = 2
       and que_interface_key = c.que_interface_key
       group by int_desc,status_id),0) as "Processing",
       NVL((select count(*)
       from queue,"interface" where
       que_interface_key = interface_key(+)
       and que_from_cde in
       (
       select queue_key from queue
       WHERE que_filepath like '\\MyNet\TESTING\' || interface ||  batch|| '\%'
       and pro_id = 36 and status_id = 3
       )
       and pro_id in (80)
       and status_id = 3
       and que_interface_key = c.que_interface_key
       group by int_desc,status_id),0) as "Sucessful",
       NVL((select count(*)
       from queue,"interface" where
       que_interface_key = interface_key(+)
       and que_from_cde in
       (
       select queue_key from queue
       WHERE que_filepath like '\\MyNet\TESTING\' || interface ||  batch|| '\%'
       and pro_id = 36 and status_id = 3
       )
       and pro_id in (80)
       and status_id = 4
       and que_interface_key = c.que_interface_key
       group by int_desc,status_id),0) as "Failed",
       NVL((select count(*)
       from queue,"interface" where
       que_interface_key = interface_key(+)
       and que_from_cde in
       (
       select queue_key from queue
       WHERE que_filepath like '\\MyNet\TESTING\' || interface ||  batch|| '\%'
       and pro_id = 36 and status_id = 3
       )
       and pro_id in (80)
     and status_id = 5
 and que_interface_key = c.que_interface_key
    group by int_desc,status_id),0) as "Duplicate/In Progress"
      from queue c,"interface" where
      que_interface_key = interface_key(+)
     and queue_key in
     (
     select queue_key from queue
    WHERE que_filepath like '\\MyNet\TESTING\' || interface ||  batch|| '\%'
   and pro_id = 36
      )
      and c.status_id = 3
    group by int_desc,"interface"
Posted
Updated 28-Jul-16 2:04am

1 solution

Here's a starter, perhaps:

You keep executing this same SQL statement:
select queue_key from queue
       WHERE que_filepath like '\\MyNet\TESTING\' || interface ||  batch|| '\%'
       and pro_id = 36 and status_id = 3
What about executing it once and putting the results in a temp table? Thus, when you do the remainder of your work by queering the temp table and you don't have to keep (if you have no indices, scanning!) entire tables over and over again for the same result.

If you'll be doing this a lot, instead of a temp table you may consider a VIEW.

Try that for a starter.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900