4._Array_Processing_활용
2012.05.13 21:43
1. Array Processing이란?
- 한번의 SQL 수행으로 다량의 ROW를 동시에 INSERT/UPDATE/DELETE 할 수 있다.
- 네트워크를 통한 데이터베이스 Call 감소 궁극적으로 SQL수행 시간과 CPU 사용량을 줄임
public class JavaArrayProcessing{
public static void insertData( Connection con
, PreparedStatement st
, String param1
, String param2
, String param3
, long param4) throws Exception{
st.setString(1, param1);
st.setString(2, param2);
st.setString(3, param3);
st.setLong(4, param4);
st.addBatch();
}
public static void execute(Connection con, String input_month)
throws Exception {
long rows = 0;
String SQLStmt1 = "SELECT 고갤번호,납입월"
+ " ,지로,자동이체,신용카드, 핸드폰, 인터넷"
+ " FROM 월요금납부실적"
+ " WHERE 납입월 = ?";
String SQLStmt2 = "INSERT INTO 납입방법별_월요금집계"
+ " (고객번호,납입월,납입방법코드, 납입금액)"
+ " VALUES(?,?,?,?)";
con.setAutoCommit(false);
PreparedStatement stmt1 = con.prepareStatement(SQLStmt1);
PreparedStatement stmt2 = con.prepareStatement(SQLStmt2);
stmt1.setFetchSize(1000);
stmt1.setString(1, input_month);
ResultSet rs = stmt1.executeQuery();
while(rs.next()){
String 고객번호= rs.getString(1);
String 납입월 = rs.getString(2);
long 지로 = rs.getLong(3);
long 자동이체 rs.getLong(4);
long 신용카드 = rs.getLong(5);
long 핸드폰 = rs.getLong(6);
long 인터넷 = rs.getLong(7);
if(지로 > 0) insertData (con, stmt2, 고객번호, 납입월, "A", 지로);
if(자동이체 > 0) insertData (con, stmt2, 고객번호, 납입월, "B", 자동이체);
if(신용카드 > 0) insertData (con, stmt2, 고객번호, 납입월, "C", 신용카드);
if(핸드폰 > 0) insertData (con, stmt2, 고객번호, 납입월, "D", 핸드폰);
if(인터넷 > 0) insertData (con, stmt2, 고객번호, 납입월, "E", 인터넷);
if(++rows%1000 == 0) stmt2.executeBatch();
}
rs.close();
stmt1.close();
stmt2.executeBatch();
stmt2.close();
con.commit();
con.setAutoCommit(true);
}
static Connection getConnection() throws Exception {....}
static void releaseConnection(Connection con) throws Exception{ ..... }
public static void main (String[] args) throws Exception{
Connection con = getConnection();
execute(con,"200903");
releaseConnection(
}
}
- insert 건수 : 150,000 건 30,000 * 5건
- 수행 시간 : 1.21초
SELECT 고객번호,납입월,지로,자동이체,신용카드,핸드폰,인터넷
FROM 월요금납부실적 WHERE 납입월 = :1
call count cpu elapsed disk query current rows
------- ------ ------ ---------- ------ ------- --------- -------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.01 0.00 0 71 0 0
Fetch 31 0.00 0.04 0 169 0 30000
------- ------ ------ ---------- ------ ------- --------- -------
total 33 0.01 0.04 0 240 0 30000
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 54
Rows Row source Operation
----- -----------------------------------------------------------
30000 TABLE ACCESS FULL 월요금납부실적 (cr=169 pr=0 pw=0 time=90083 us)
*************************************************************************
INSERT INTO 납입방법별_월요금집계
(고객번호, 납입월, 납입방법코드, 납입금액)
VALUE(:1, :2, :3, :4)
call count cpu elapsed disk query current rows
------- ------ ------ ---------- ------ ------- --------- -------
Parse 1 0.00 0.00 0 0 0 0
Execute 30 0.18 0.27 0 71 5094 150000
Fetch 0 0.00 0.00 0 169 0 0
------- ------ ------ ---------- ------ ------- --------- -------
total 31 0.18 0.27 2 923 5094 150000
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 54
- Insert : Execute = 30건, 150,000건 => Insert 매번 5,000건씩 Array Processing 한것임
- Select 역시 Fetch 할때 1000개 단위로 Array Fetch 하도록 조정 하였음 (Fetch가 31인것을 확인할수 있음)
| PL/SQL (Recursive) | JAVA | JAVA (Array 처리) | One-SQL |
Parse Call | 5 | 150,000 | 1 | 1 |
Execute Call | 150,000 | 150,000 | 30 | 1 |
총 소요시간 | 7.26초 | 126.82초 | 1.21초 | 0.9초 |
- Array Processing 효과를 그대화 하려면 연속된 일련의 처리과정을 모두 Array 단위로 진행해야 한다.
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
66 | 부록 | 남송휘 | 2012.06.05 | 2708 |
65 | 8._IO_효율화_원리 | 운영자 | 2012.06.05 | 4426 |
64 |
3._Deterministic_함수_사용_시_주의사항
![]() | 정찬호 | 2012.05.29 | 4351 |
63 | 2._Cursor_Sharing | 운영자 | 2012.05.28 | 6276 |
62 | 7._Result_캐시 | 운영자 | 2012.05.27 | 4426 |
61 |
3._Single_Block_vs._Multiblock_IO
![]() | 정찬호 | 2012.05.22 | 4229 |
60 |
2._Memory_vs._Disk_IO
![]() | 정찬호 | 2012.05.22 | 4446 |
59 |
1._블록_단위_IO
![]() | 정찬호 | 2012.05.22 | 4209 |
58 |
6장._IO_효율화_원리
![]() | 정찬호 | 2012.05.22 | 4085 |
57 |
1._Library_Cache_Lock_Pin
![]() | 남송휘 | 2012.05.21 | 4290 |
56 |
6._RAC_캐시_퓨전
![]() | 남송휘 | 2012.05.21 | 17797 |
55 | 5._Direct_Path_IO | 남송휘 | 2012.05.21 | 7932 |
54 |
4._Prefetch
![]() | 남송휘 | 2012.05.21 | 3889 |
53 | 8._PLSQL_함수_호출_부하_해소_방안 | 남송휘 | 2012.05.21 | 3773 |
52 | 5._Fetch_Call_최소화 [1] | 박영창 | 2012.05.15 | 6065 |
51 |
7._PLSQL_함수의_특징과_성능_부하
![]() | 남송휘 | 2012.05.14 | 6935 |
50 | 6._페이지_처리의_중요성 | 남송휘 | 2012.05.14 | 3379 |
» | 4._Array_Processing_활용 | 시와처 | 2012.05.13 | 4041 |
48 |
3._데이터베이스_Call이_성능에_미치는_영향
![]() | 시와처 | 2012.05.13 | 3645 |
47 |
10._Dynamic_SQL_사용_기준
![]() | 남송휘 | 2012.05.07 | 4556 |