안녕하세요 현재 Tibero DB 포팅 작업을 진행하고 있습니다.
시퀀스가 있는 테이블에 insert all이 잘 되지 않아 도움 구하고자 게시물 남깁니다.
mysql/postgres의 경우,
1 | insert into table ( t1 ) values (1), values (2), values (3) |
과 같은 SQL문이 지원이 되었습니다.
Tibero의 경우, 오라클과 많이 유사하여 오라클 문법으로 확인한 후, Tibero DB로 테스트해봤습니다.
1 2 3 4 5 6 7 8 9 | insert all into table ( t1 ) values ( 1 ) into table ( t1 ) values ( 2 ) into table ( t1 ) values ( 3 ) select 1 from dual; |
위와 같은 SQL 문은 이상없습니다.
그러나
1 2 3 4 5 6 7 8 9 | insert all into table ( t1 ) values ( seq.nextval ) into table ( t1 ) values ( seq.nextval ) into table ( t1 ) values ( seq.nextval ) select 1 from dual; |
위와 같은 SQL문장은 seq.nextval이 제 기능을 하지 못하더라구요..
오라클의 경우 아래 URL과 같이 해결된다는데, 티베로는 해당되지 않는 것 같더라구요..
insert all with sequence 문제를 어떻게 해결하면 좋을까요..
현재 tibero 5를 사용하며, mybatis를 사용하고 있습니다.
글 읽어주셔서 감사드립니다. 또한 댓글 달아주시고 도움주시는 분들께 미리 감사드립니다.
도와주시면 정말 감사하겠습니다.
방법을 찾았습니다.
해당글과 같이 진행하니까 되었습니다.
1 2 3 4 5 6 | insert into service_code (code,serv_info_seq_id, name ) select service_code_seq.nextval, a, b from ( SELECT 1 as a, 'SOME VALUE' as b FROM DUAL UNION ALL SELECT 1, 'ANOTHER VALUE' FROM DUAL) |
select ~~ from dual 부분을 foreach 돌리며 될 것 같습니다..
근데 궁금한게... 성능이 정말 궁금하네요.. 한번 확인해봐야겠습니다..
감사합니다!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | Execution Plan -------------------------------------------------------------------------------- 1 INSERT : SERVICE_CODE (Cost:211, %CPU:0, Rows :8) 2 UNION ALL (Cost:211, %CPU:0, Rows :8) 3 UNION ALL (Cost:105, %CPU:0, Rows :4) 4 UNION ALL (Cost:52, %CPU:0, Rows :2) 5 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) 6 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) 7 UNION ALL (Cost:52, %CPU:0, Rows :2) 8 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) 9 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) 10 UNION ALL (Cost:105, %CPU:0, Rows :4) 11 UNION ALL (Cost:52, %CPU:0, Rows :2) 12 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) 13 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) 14 UNION ALL (Cost:52, %CPU:0, Rows :2) 15 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) 16 DPV: _VT_DUAL (Cost:26, %CPU:0, Rows :1) |
확실히 union all 자체에 cost가 필요하네요.. ㅠㅠㅠㅠ
위와 같이 했더니
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | < insert id= "insertServiceCodeList" parameterType= "serviceCodeVo" useGeneratedKeys= "true" keyColumn= "code" keyProperty= "code" > insert into service_code ( code, serv_info_seq_id, name , default_key_type, cre_date, creator, description, state ) select service_code_seq.nextval, servInfoSeqId, name , defaultKeyType, systimestamp, creator, description, 0 from ( <foreach collection= "list" item= "item" separator= "union all" > select #{item.servInfoSeqId} servInfoSeqId, #{item. name } name , #{item.defaultKeyType} defaultKeyType, #{item.creator} creator, #{item.description} description from dual </foreach> ) </ insert > |
useGeneratedKeys가 제기능을 하지 못하고 syntax error 뿜뿜...
usegenKey 관련 프로퍼티 지우면 정상가동되지만.. sequence id write back이 안되네요 ㅠㅠ..