Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Performance tuning of a query with oracle functions and group by

Rithu RajFeb 21 2018 — edited Feb 22 2018

Hi,

I would like to optimize the performance of the below query,

SELECT TO_NUMBER(TO_CHAR(date_col, 'iyyy')) AS paid_in_year,

                               TO_NUMBER(TO_CHAR(date_col, 'ww')) AS paid_in_week,

                               EXTRACT(DAY FROM ((date_col - date_col2) DAY(4) TO SECOND)) AS input_to_paid_days,

                               COUNT(id) AS ID,

   date_col2 as PAID_DATE

                          FROM big_table

                         WHERE extract(year from date_col2) >= extract(year from sysdate) - 2

                           AND col1 != 'NWLK'

                           AND col2 = '02'

                         GROUP BY TO_NUMBER(TO_CHAR(date_col, 'iyyy')),

                               TO_NUMBER(TO_CHAR(date_col, 'ww')),

                               EXTRACT(DAY FROM ((date_col - date_col2) DAY(4) TO SECOND)),date_col2

The table referred in the query is a very huge table. Please help me in fixing this.

I understand that it has got more oracle functions in it and and a group by that makes the query to run slower.

But please assist in restructuring the SQL. This is my base query and I have even more logical calculations run over it to get the final result.

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2018
Added on Feb 21 2018
13 comments
1,345 views