How to compare two huge tables in Oracle? [message #181970] |
Wed, 12 July 2006 07:02  |
anil_bogala
Messages: 3 Registered: May 2006 Location: Hyderabad
|
Junior Member |
|
|
Dears,
I have two tables with huge data with them. I want to compare both the tables (row by row comparison). So I have fired a query like the following:
SELECT * FROM TAB1
MINUS
SELECT * FROM TAB1@DBLINK;
SELECT * FROM TAB1@DBLINK;
MINUS
SELECT * FROM TAB1;
But the tables are having very huge data (25 Crores). So I am getting the following error after a long time:
ORA-01652: unable to extend temp segment by 512 in tablespace TEMP1
Is there any other way to compare these tables (row by row)?
Please let me know if any alternatives are there??
Regards,
Anil.
|
|
|
|
Re: How to compare two huge tables in Oracle? [message #181979 is a reply to message #181970] |
Wed, 12 July 2006 07:26   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Firstly, the process will run much quicker of you can get both tables onto the same database. At the moment you're having to drag the entire table acros the database link before you an do anything with it.
Do you need to compare the entire row, or can you do a comparison on a limited subset of columns? If so then using that list of columns instead of 'SELECT *' will speed things up somewhat, and resuce the emount of TEMP storage you need.
I strongly suspect that a row by row process will be substantially slower than your current approach, and that you should make your temp tablespace huge (or set it to auto extend) and let it run.
If there is a unique key for each table, then what you could do is:
Open a cursor on each table, ordered by the unique key.
Get the first row from each cursor.
Loop
If the unique keys are the same, do a column by column comparison of the rows.
If the unique keys are different, then discard the row with the lowest unique key value and fetch the next record from that cursor.
End Loop;
|
|
|
|
|
Re: How to compare two huge tables in Oracle? [message #182075 is a reply to message #182073] |
Wed, 12 July 2006 21:50   |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
@JRowbottoms advice is solid gold. Use it.
It performs almost exactly the same algorithm as the MINUS SQL (internally), but it will perform the sort of the remote table on the remote database! Not on the local database.
The problem with the MINUS is that the remote table is shipped across and THEN sorted, so you need enough temp space locally to sort both tables.
There is no guarantee that the two-cursor approach will work - you may not even have enough space to sort one table, let alone both. It will get you a darn site closer though.
Ross Leishman
|
|
|
|
|
|