Monday, September 29, 2014

Solving Time-out by specific data reorg.

When I query SAL_HIST table with the condition CUSTOMER_NO = 9570001111 - this is big customer, which result in 705,043 rows in above 30 seconds. This response time always causes time-out. 
I have tested this method of reorganization of specific data for solving the problem. Of course some considerations are required. 
The main concern is that the service must be not interrupted. After the test I learned bellows.  

 
 - total block access cost lowered about half than before. This surely depends on the placement shape of data. 
  - size of index increased some amount, making considering rebuild.

====================================
--Total block get cost Bf-Af compare
====================================


DEACON > select /*+index(s SAL_HIST_N2) */
  2         EQP_MDL_CD,count(*)
  3  from SAL_HIST s
  4  where CUSTOMER_NO in (
9570001111)
  5  group by EQP_MDL_CD
  6  ;


Execution Plan
----------------------------------------------------------
Plan hash value: 4068265589

--------------------------------------------------------------------------------------------
| Id  | Operation                    | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |             |  2296 | 27552 |   146K  (1)| 00:29:23 |
|   1 |  HASH GROUP BY               |             |  2296 | 27552 |   146K  (1)| 00:29:23 |
|   2 |   TABLE ACCESS BY INDEX ROWID| SAL_HIST    |   831K|  9747K|   146K  (1)| 00:29:22 |
|*  3 |    INDEX RANGE SCAN          | SAL_HIST_N2 |   831K|       |  2372   (1)| 00:00:29 |
--------------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

   3 - access("CUSTOMER_NO"=9570001111)

<BEFORE>
Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
      99708  consistent gets
      58677  physical reads
       7912  redo size
      20618  bytes sent via SQL*Net to client
       1023  bytes received via SQL*Net from client
        112  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
       1664  rows processed


<AFTER>
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
      44944  consistent gets
       6884  physical reads
     105744  redo size
      21627  bytes sent via SQL*Net to client
       1023  bytes received via SQL*Net from client
        112  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
       1664  rows processed


============================
--Index cost 
Bf-Af compare
============================


DEACON > select /*+index(s SAL_HIST_N2) */
  2         count(*)
  3  from SAL_HIST s
  4  where CUSTOMER_NO in (
9570001111)
  5  ;


  COUNT(*)
----------
    705043


1개의 행이 선택되었습니다.

경   과: 00:00:00.39

Execution Plan
----------------------------------------------------------
Plan hash value: 3221291908

---------------------------------------------------------------------------------
| Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |             |     1 |     7 |  2372   (1)| 00:00:29 |
|   1 |  SORT AGGREGATE   |             |     1 |     7 |            |          |
|*  2 |   INDEX RANGE SCAN| SAL_HIST_N2 |   831K|  5685K|  2372   (1)| 00:00:29 |
---------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("CUSTOMER_NO"=9570001111)

<BEFORE>
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
       5624  consistent gets
          0  physical reads
          0  redo size
        243  bytes sent via SQL*Net to client
        253  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed


<AFTER>
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
       7170  consistent gets
          0  physical reads
          0  redo size
        243  bytes sent via SQL*Net to client
        253  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed


======================
-- Data Reorg. Script
======================


declare
  v_cnt   number := 0;
 
begin

  for rec in (
           select *
           from SAL_HIST
           where CUSTOMER_NO = 
9570001111 for update
           ) loop
 
  delete SAL_HIST
  where SALE_ID = rec.SALE_ID;
 
  insert into SAL_HIST values (
            rec.SALE_ID                       ,
            rec.CUSTOMER_NO                   ,
            rec.SALE_DATE                     ,
            .
            .  );
    
end loop;
commit;

  dbms_output.put_line(v_cnt || '   rows executed.');

exception
  when others then raise;
end;
/

No comments:

Post a Comment