Home » RDBMS Server » Performance Tuning » Distinct query taking long time to run (Oracle 11.2,Linux 6)
Distinct query taking long time to run [message #669760] |
Thu, 10 May 2018 14:07  |
 |
senmng
Messages: 22 Registered: April 2018
|
Junior Member |
|
|
I have this insert query in one of my proc to load the data into a target table where the distinct clause is making huge impact and taking too much time(since each table is having records more than 2 and 3 million records). Is their any way to optimize this select query with distinct?
Insert into target table
SELECT DISTINCT
tab1.col1 col1,
tab1.col2 col2,
tab2.col3 col3,
tab2.col4 col4,
tab3.col5 col5,
tab3.col6 col6,
tab3.col7 col7,
tab3.col8 col8,
tab3.col9 col9,
to_char(tab3.col7, 'YYYY-MM') col10,
to_char(tab3.col7, 'YYYY') col11,
to_char(tab3.col7, 'MM') col12,
CURRENT_DATE col13
FROM tab3@dblink t2
JOIN tab4@dblink ON tab3.col5 = tab4.col13
JOIN tab5@dblink ON tab4.col14 = tab5.col15
JOIN tab2@dblink ON tab5.col16 = tab2.col17
JOIN tab1 ON tab1.col18 = tab2.col3;
[EDITED by LF: removed superfluous info from Product, version, OS]
[Updated on: Fri, 11 May 2018 02:11] by Moderator Report message to a moderator
|
|
|
|
|
|
|
Re: Distinct query taking long time to run [message #669788 is a reply to message #669768] |
Fri, 11 May 2018 09:36   |
 |
msol25
Messages: 396 Registered: June 2011
|
Senior Member |
|
|
Hi,
The DISTINCT operator causes Oracle to fetch all rows satisfying the table join and then sort and filter out duplicate values.I hope you can use to resolve this using
SELECT <column_list>
FROM
( SELECT <column_list>
,ROW_NUMBER() OVER (PARTITION BY <column_list> ORDER BY <column_list>) As RNO
FROM <Table_Name>
)
WHERE RNO = 1
[Updated on: Fri, 11 May 2018 09:37] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Sat May 03 17:45:36 CDT 2025
|