0

I'm currently trying to optimize a sql select statement. I would like to know if there's a simpler way to implement this sql statement and improve its performance.

I would also like to know if I can improve the performance of this statement using indexing, partitioning, clustering, tuning data buffer cache, using in-memory column store, etc.

select
        ps_partkey,                                                        
        sum(ps_supplycost * ps_availqty) value                                                                                
from
        partsupp,
        supplier,
        nation
where
        ps_suppkey = s_suppkey
        and s_nationkey = n_nationkey
        and n_name = 'FRANCE'  
group by
        ps_partkey having
                sum(ps_supplycost * ps_availqty) > (
                        select
                                sum(ps_supplycost * ps_availqty) * 0.0005
                        from
                                partsupp,
                                supplier,
                                nation
                        where
                                ps_suppkey = s_suppkey
                                and s_nationkey = n_nationkey
                                and n_name = 'FRANCE'
                )
order by
        value desc;

1 Answer 1

2

Can you use different query as follows and check for the performance?

Select distinct ps_partkey, value
  from
(select
        ps_partkey,                                                        
        sum(ps_supplycost * ps_availqty)  over (partition by ps_partkey) value,
        sum(ps_supplycost * ps_availqty)  over () as totalvalue 
  from partsupp
       join supplier on ps_suppkey = s_suppkey
       join nation on s_nationkey = n_nationkey
 where n_name = 'FRANCE')
Where value > totalvalue * 0.0005

Note: It is recommended to use standard ANSI joins

Sign up to request clarification or add additional context in comments.

5 Comments

Partsupp, supplier and nation are the names of the tables that we're using. The code above needs to be corrected.
After correcting the code there is a very slight improvement in the performance. Thanks for the help.
Thanks! The code works now but is there any way to further increase the performance.
If you have an index on the` ps_partkey, ps_suppkey, s_suppkey, s_nationkey, n_nationkey, and n_name` then it will be much faster.
@Tajesh . if such an index(s) are built, I'd say that it may be much faster, but it's not a certainty. If the index is not sufficiently selective, the optimizer may very well decide that a FTS is still more efficient that the extra reads required for an index access. Only testing on a target system will tell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.