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:
- Create or replace procedure P_MS_MOVEMEDIATASK (
- I _time DATE
- )
- AS
- V_time DATE;
- V_beginTime DATE;
- V_monthday VARCHAR2 (4 );
- V_month VARCHAR2 (2 );
- V_count NUMBER;
- V_ SQL VARCHAR2 (5000 );
- V_ret VARCHAR2 (10 );
- V_errMsg VARCHAR2 (500 );
- V_total NUMBER;
- BEGIN
- V_beginTime:=SYSDATE;
- -- Transfer Data 31 days ago
- V_time:=I _time;
- -- Retrieve the monthday of the transferred data
- V_monthday:=To_char(V_time, 'mmdd ');
- -- Use the month for transferring data to different tables by month
- V_month:=To_char(V_time, 'mm ');
- --
- Select count (1)
- INTO v_count
- FROM T_MS_MEDIA_TASK T
- WHERET. MONTHDAY=V_monthday;
- V_total:=V_count;
- WHILE (v_count>0) LOOP
- -- Set the RESERVE79 field of the data to be transferred to 0.
- UPDATE T_MS_MEDIA_TASK T
- SETT. RESERVE79='0'
- WHERET. MONTHDAY=V_monthday
- AND ROWNUM<= 50000; -- up to 50000 entries can be submitted each time
- -- Insert the data to be transferred into the history table and insert dynamic SQL statements to different historical tables on a monthly basis.
- V_ SQL:='Insert into t_ms_media_task_his'| V_month
- ...
- ...
- Execute immediate v_ SQL;
- -- Delete transferred data
- Delete from T_MS_MEDIA_TASK T
- WHERET. MONTHDAY=V_monthday
- ANDT. RESERVE79='0';
- COMMIT;
- -- Get the number of data records to be transferred
- Select count (1)
- INTO v_count
- FROM T_MS_MEDIA_TASK T
- WHERET. MONTHDAY=V_monthday;
- End loop;
- EXCEPTION
- ...
- END P_MS_MOVEMEDIATASK;
- /