Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm currently using Oracle 11g and let's say I have a table with the following columns (more or less)

Table1

  • ID varchar(64)
  • Status int(1)
  • Transaction_date date
  • tons of other columns

And this table has about 1 Billion rows. I would want to update the status column with a specific where clause, let's say


where transaction_date = somedatehere

What other alternatives can I use rather than just the normal UPDATE statement?

Currently what I'm trying to do is using CTAS or Insert into select to get the rows that I want to update and put on another table while using AS COLUMN_NAME so the values are already updated on the new/temporary table, which looks something like this:


INSERT INTO TABLE1_TEMPORARY (
    ID, 
    STATUS, 
    TRANSACTION_DATE, 
    TONS_OF_OTHER_COLUMNS)
SELECT
    ID
    3 AS STATUS,
    TRANSACTION_DATE,
    TONS_OF_OTHER_COLUMNS
FROM TABLE1
WHERE
    TRANSACTION_DATE = SOMEDATE 

So far everything seems to work faster than the normal update statement. The problem now is I would want to get the remaining data from the original table which I do not need to update but I do need to be included on my updated table/list.

What I tried to do at first was use DELETE on the same original table using the same where clause so that in theory, everything that should be left on that table should be all the data that i do not need to update, leaving me now with the two tables:


TABLE1 --which now contains the rows that i did not need to update
TABLE1_TEMPORARY --which contains the data I updated

But the delete statement in itself is also too slow or as slow as the orginal UPDATE statement so without the delete statement brings me to this point.


TABLE1 --which contains BOTH the data that I want to update and do not want to update
TABLE1_TEMPORARY --which contains the data I updated

What other alternatives can I use in order to get the data that's the opposite of my WHERE clause (take note that the where clause in this example has been simplified so I'm not looking for an answer of NOT EXISTS/NOT IN/NOT EQUALS plus those clauses are slower too compared to positive clauses)

I have ruled out deletion by partition since the data I need to update and not update can exist in different partitions, as well as TRUNCATE since I'm not updating all of the data, just part of it.

Is there some kind of JOIN statement I use with my TABLE1 and TABLE1_TEMPORARY in order to filter out the data that does not need to be updated?

I would also like to achieve this using as less REDO/UNDO/LOGGING as possible.

Thanks in advance.

share|improve this question
    
Cross-posted please don't do that. If you want your question migrated on another site, flag it for moderator attention and ask for that. We don't like duplicate questions here. –  Mat Nov 16 '13 at 12:00
    
@Mat Sorry I had no idea that was illegal. –  Avias Nov 16 '13 at 12:03
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.