LEFT OUTER JOIN of Large Tables - Performance issue [message #650654] |
Thu, 28 April 2016 13:22 |
anil_mk
Messages: 146 Registered: August 2006 Location: Bangalore, India
|
Senior Member |
|
|
Hi All,
Please find below sample table creation script with data loading.
Each time "FOR" loop is inserting 100000 records
--Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit
DROP TABLE TST_1
/
CREATE TABLE TST_1 AS SELECT * FROM DBA_OBJECTS WHERE 1=2
/
BEGIN
FOR I IN 1..400 LOOP
INSERT INTO TST_1 SELECT * FROM DBA_OBJECTS;
END LOOP;
commit;
END;
/
CREATE INDEX INDX_TST_1_OBJID ON TST_1 (OBJECT_ID)
/
DROP TABLE TST_2
/
CREATE TABLE TST_2 AS SELECT * FROM DBA_OBJECTS WHERE 1=2
/
BEGIN
FOR I IN 1..300 LOOP
INSERT INTO TST_2 SELECT * FROM DBA_OBJECTS;
END LOOP;
COMMIT;
END;
/
/*
SQL> @@ "load_test_data.sql"
Table dropped.
Table created.
PL/SQL procedure successfully completed.
Index created.
Table dropped.
Table created.
PL/SQL procedure successfully completed.
SQL>
*/
I am running below query using LEFT OUTER JOIN which is taking 10-15 mins to fetch result set.
Please help me to improve performance of query.
SELECT A.* FROM TST_1 A
LEFT OUTER JOIN TST_2 B
ON (A.OBJECT_ID=B.OBJECT_ID);
Thanks,
Anil MK
|
|
|
|
|
|
|
Re: LEFT OUTER JOIN of Large Tables - Performance issue [message #650662 is a reply to message #650661] |
Thu, 28 April 2016 22:00 |
John Watson
Messages: 8960 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Quote:The query which I have given requires columns from both tables, I have just created sample tables. So your actual problem is with different tables and a different query. I do not see how tuning the query you have provided would help tune the query that you have not provided.
|
|
|
|
Re: LEFT OUTER JOIN of Large Tables - Performance issue [message #650676 is a reply to message #650661] |
Fri, 29 April 2016 05:34 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
So, to summarize the input which you provided: you have tables TST_1 with 40 million rows and TST_2 with 30 million rows.
You want to join them on the column which is not unique in either of them, so the result set will contain 12 billion (12*10^9 = 400*30M = 40M*300) rows. I would expect this is going to take some time.
Maybe you should take a step back and redefine the data processing if it leads to such high numbers of rows; as you did not post anything useful about it, I cannot comment more.
By the way, the left join is irrelevant in the posted case as all OBJECT_IDs are present in both tables.
|
|
|
Re: LEFT OUTER JOIN of Large Tables - Performance issue [message #652333 is a reply to message #650676] |
Tue, 07 June 2016 08:15 |
|
Kevin Meade
Messages: 2103 Registered: December 1999 Location: Connecticut USA
|
Senior Member |
|
|
In the case of not needing one of the tables in the query, the optimizer already knows how to do this. Assuming conditions are correct
1. the table join cannot add or delete rows to the result
2. the query does not need any columns from the table in order to do the query
Then there is a feature as of 10.2.0.2.0 that does Dunsel Join Removal (Oracle calls it Join Elimination).
Usually, it requires constraints, and you would be fetching data from the child table.
|
|
|