Detach data using Partition Exchange

Source: Internet
Author: User

We have a core table t_ms_mdeia_task related to daily operations of an application. This table is a List partition made on a daily basis. The partition key is monthday, and the column value is similar to 'mmdd'. There are 366 partitions in total.

The daily data volume is more than 3 million, and the application requires only 31 days to be saved. All the previous data is migrated to the History Table for query. That is to say, we need to migrate data from the previous day to the hist table every day. Of course, the hist table is also partitioned.

The application side used the stored procedure to delete and insert large batches. For such operations, the process is very complex and affects the database performance.

View the submission process:

  1. Create or replace procedure P_MS_MOVEMEDIATASK (
  2. I _time DATE
  3. )
  4. AS
  5. V_time DATE;
  6. V_beginTime DATE;
  7. V_monthday VARCHAR2 (4 );
  8. V_month VARCHAR2 (2 );
  9. V_count NUMBER;
  10. V_ SQL VARCHAR2 (5000 );
  11. V_ret VARCHAR2 (10 );
  12. V_errMsg VARCHAR2 (500 );
  13. V_total NUMBER;
  14. BEGIN
  15. V_beginTime:=SYSDATE;
  16. -- Transfer Data 31 days ago
  17. V_time:=I _time;
  18. -- Retrieve the monthday of the transferred data
  19. V_monthday:=To_char(V_time, 'mmdd ');
  20. -- Use the month for transferring data to different tables by month
  21. V_month:=To_char(V_time, 'mm ');
  22. --
  23. Select count (1)
  24. INTO v_count
  25. FROM T_MS_MEDIA_TASK T
  26. WHERET. MONTHDAY=V_monthday;
  27. V_total:=V_count;
  28. WHILE (v_count>0) LOOP
  29. -- Set the RESERVE79 field of the data to be transferred to 0.
  30. UPDATE T_MS_MEDIA_TASK T
  31. SETT. RESERVE79='0'
  32. WHERET. MONTHDAY=V_monthday
  33. AND ROWNUM<= 50000; -- up to 50000 entries can be submitted each time
  34. -- Insert the data to be transferred into the history table and insert dynamic SQL statements to different historical tables on a monthly basis.
  35. V_ SQL:='Insert into t_ms_media_task_his'| V_month
  36. ...
  37. ...
  38. Execute immediate v_ SQL;
  39. -- Delete transferred data
  40. Delete from T_MS_MEDIA_TASK T
  41. WHERET. MONTHDAY=V_monthday
  42. ANDT. RESERVE79='0';
  43. COMMIT;
  44. -- Get the number of data records to be transferred
  45. Select count (1)
  46. INTO v_count
  47. FROM T_MS_MEDIA_TASK T
  48. WHERET. MONTHDAY=V_monthday;
  49. End loop;
  50. EXCEPTION
  51. ...
  52. END P_MS_MOVEMEDIATASK;
  53. /
  • 1
  • 2
  • 3
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.