[LOATODO] 코드 리팩토링 SELECT 리팩토링

2023. 11. 24. 18:08·Project/LOATODO

1. 서론

연관관계 테이블이 늘어나면서

캐릭터 데이터를 호출할 때 SQL문이 여러번 실행된다.

 

1 - 1. 기존코드

@Query(value = "SELECT c FROM Character c WHERE c.member = :member AND c.serverName = :serverName")
List<Character> findCharacterListServerName(@Param("member") Member member, @Param("serverName") String serverName);

 

JPA로 Member Entity를 불러와서 Controller에서 DTO로 변경할 때

필요한 데이터들을 LAZY 형식으로 불러온다.

 

1 - 2. 기존코드 결과

2023-11-24 17:32:29.777 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        member0_.member_id as member_i1_10_,
        member0_.created_date as created_2_10_,
        member0_.last_modified_date as last_mod3_10_,
        member0_.access_key as access_k4_10_,
        member0_.api_key as api_key5_10_,
        member0_.auth_provider as auth_pro6_10_,
        member0_.password as password7_10_,
        member0_.role as role8_10_,
        member0_.username as username9_10_ 
    from
        member member0_ 
    where
        member0_.username=?
2023-11-24 17:32:29.783 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        characters0_.member_id as member_38_0_0_,
        characters0_.characters_id as characte1_0_0_,
        characters0_.characters_id as characte1_0_1_,
        characters0_.created_date as created_2_0_1_,
        characters0_.last_modified_date as last_mod3_0_1_,
        characters0_.challenge_abyss as challeng4_0_1_,
        characters0_.challenge_guardian as challeng5_0_1_,
        characters0_.character_class_name as characte6_0_1_,
        characters0_.character_image as characte7_0_1_,
        characters0_.character_level as characte8_0_1_,
        characters0_.character_name as characte9_0_1_,
        characters0_.chaos_id as chaos_i36_0_1_,
        characters0_.chaos_check as chaos_c10_0_1_,
        characters0_.chaos_gauge as chaos_g11_0_1_,
        characters0_.chaos_gold as chaos_g12_0_1_,
        characters0_.chaos_name as chaos_n13_0_1_,
        characters0_.epona_check as epona_c14_0_1_,
        characters0_.epona_check2 as epona_c15_0_1_,
        characters0_.epona_gauge as epona_g16_0_1_,
        characters0_.guardian_id as guardia37_0_1_,
        characters0_.guardian_check as guardia17_0_1_,
        characters0_.guardian_gauge as guardia18_0_1_,
        characters0_.guardian_gold as guardia19_0_1_,
        characters0_.guardian_name as guardia20_0_1_,
        characters0_.gold_character as gold_ch21_0_1_,
        characters0_.item_level as item_le22_0_1_,
        characters0_.member_id as member_38_0_1_,
        characters0_.server_name as server_23_0_1_,
        characters0_.show_chaos as show_ch24_0_1_,
        characters0_.show_character as show_ch25_0_1_,
        characters0_.show_cube_ticket as show_cu26_0_1_,
        characters0_.show_epona as show_ep27_0_1_,
        characters0_.show_guardian as show_gu28_0_1_,
        characters0_.show_silmael_change as show_si29_0_1_,
        characters0_.show_week_epona as show_we30_0_1_,
        characters0_.show_week_todo as show_we31_0_1_,
        characters0_.sort_number as sort_nu32_0_1_,
        characters0_.cube_ticket as cube_ti33_0_1_,
        characters0_.silmael_change as silmael34_0_1_,
        characters0_.week_epona as week_ep35_0_1_,
        daycontent1_.content_id as content_2_4_2_,
        daycontent1_.category as category3_4_2_,
        daycontent1_.level as level4_4_2_,
        daycontent1_.name as name5_4_2_,
        daycontent1_.destruction_stone as destruc13_4_2_,
        daycontent1_.guardian_stone as guardia14_4_2_,
        daycontent1_.honor_shard as honor_s15_4_2_,
        daycontent1_.jewelry as jewelry7_4_2_,
        daycontent1_.leap_stone as leap_sto8_4_2_,
        daycontent1_.shilling as shilling9_4_2_,
        daycontent2_.content_id as content_2_4_3_,
        daycontent2_.category as category3_4_3_,
        daycontent2_.level as level4_4_3_,
        daycontent2_.name as name5_4_3_,
        daycontent2_.destruction_stone as destruc13_4_3_,
        daycontent2_.guardian_stone as guardia14_4_3_,
        daycontent2_.honor_shard as honor_s15_4_3_,
        daycontent2_.jewelry as jewelry7_4_3_,
        daycontent2_.leap_stone as leap_sto8_4_3_,
        daycontent2_.shilling as shilling9_4_3_ 
    from
        characters characters0_ 
    left outer join
        content daycontent1_ 
            on characters0_.chaos_id=daycontent1_.content_id 
    left outer join
        content daycontent2_ 
            on characters0_.guardian_id=daycontent2_.content_id 
    where
        characters0_.member_id=?
2023-11-24 17:32:29.804 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        character0_.characters_id as characte1_0_,
        character0_.created_date as created_2_0_,
        character0_.last_modified_date as last_mod3_0_,
        character0_.challenge_abyss as challeng4_0_,
        character0_.challenge_guardian as challeng5_0_,
        character0_.character_class_name as characte6_0_,
        character0_.character_image as characte7_0_,
        character0_.character_level as characte8_0_,
        character0_.character_name as characte9_0_,
        character0_.chaos_id as chaos_i36_0_,
        character0_.chaos_check as chaos_c10_0_,
        character0_.chaos_gauge as chaos_g11_0_,
        character0_.chaos_gold as chaos_g12_0_,
        character0_.chaos_name as chaos_n13_0_,
        character0_.epona_check as epona_c14_0_,
        character0_.epona_check2 as epona_c15_0_,
        character0_.epona_gauge as epona_g16_0_,
        character0_.guardian_id as guardia37_0_,
        character0_.guardian_check as guardia17_0_,
        character0_.guardian_gauge as guardia18_0_,
        character0_.guardian_gold as guardia19_0_,
        character0_.guardian_name as guardia20_0_,
        character0_.gold_character as gold_ch21_0_,
        character0_.item_level as item_le22_0_,
        character0_.member_id as member_38_0_,
        character0_.server_name as server_23_0_,
        character0_.show_chaos as show_ch24_0_,
        character0_.show_character as show_ch25_0_,
        character0_.show_cube_ticket as show_cu26_0_,
        character0_.show_epona as show_ep27_0_,
        character0_.show_guardian as show_gu28_0_,
        character0_.show_silmael_change as show_si29_0_,
        character0_.show_week_epona as show_we30_0_,
        character0_.show_week_todo as show_we31_0_,
        character0_.sort_number as sort_nu32_0_,
        character0_.cube_ticket as cube_ti33_0_,
        character0_.silmael_change as silmael34_0_,
        character0_.week_epona as week_ep35_0_ 
    from
        characters character0_ 
    where
        character0_.member_id=? 
        and character0_.server_name=?
2023-11-24 17:32:29.807 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.809 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.811 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.812 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.812 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.813 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.814 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.814 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.815 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.816 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.817 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.818 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.819 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.820 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.821 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.822 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.823 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.824 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.825 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.826 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.827 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.828 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        weekconten0_.content_id as content_2_4_0_,
        weekconten0_.category as category3_4_0_,
        weekconten0_.level as level4_4_0_,
        weekconten0_.name as name5_4_0_,
        weekconten0_.cool_time as cool_ti16_4_0_,
        weekconten0_.destruction_stone as destruc13_4_0_,
        weekconten0_.gate as gate17_4_0_,
        weekconten0_.gold as gold18_4_0_,
        weekconten0_.guardian_stone as guardia14_4_0_,
        weekconten0_.honor_shard as honor_s15_4_0_,
        weekconten0_.leap_stone as leap_sto8_4_0_,
        weekconten0_.week_category as week_ca19_4_0_,
        weekconten0_.week_content_category as week_co20_4_0_ 
    from
        content weekconten0_ 
    where
        weekconten0_.content_id=? 
        and weekconten0_.dtype='WeekContent'
2023-11-24 17:32:29.829 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.830 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.831 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.831 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.832 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.833 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.834 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.835 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.835 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.837 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?
2023-11-24 17:32:29.838 DEBUG 39633 --- [nio-8080-exec-6] org.hibernate.SQL                        : 
    select
        todov2list0_.character_id as characte8_15_0_,
        todov2list0_.todo_id as todo_id1_15_0_,
        todov2list0_.todo_id as todo_id1_15_1_,
        todov2list0_.created_date as created_2_15_1_,
        todov2list0_.last_modified_date as last_mod3_15_1_,
        todov2list0_.character_id as characte8_15_1_,
        todov2list0_.cool_time as cool_tim4_15_1_,
        todov2list0_.gold as gold5_15_1_,
        todov2list0_.is_checked as is_check6_15_1_,
        todov2list0_.message as message7_15_1_,
        todov2list0_.content_id as content_9_15_1_ 
    from
        todov2 todov2list0_ 
    where
        todov2list0_.character_id=?

 

여러 테이블을 SELECT 문으로 호출

테이블이 더 늘어나기전에 정리를 해야할 꺼 같아서 정리

 

 

2. 개발

2 - 1. 리팩토링 코드

FETCH JOIN으로 묶음

@Query(value = "SELECT DISTINCT c FROM Character c " +
            "JOIN FETCH c.todoV2List t JOIN FETCH t.weekContent " +
            "JOIN FETCH c.dayTodo.guardian " +
            "JOIN FETCH c.dayTodo.chaos " +
            "WHERE c.member.username = :username AND c.serverName = :serverName")
List<Character> findCharacterListServerName(@Param("username") String username, @Param("serverName") String serverName);

 

2 - 2. 리팩토링 결과

select
        distinct character0_.characters_id as characte1_0_0_,
        todov2list1_.todo_id as todo_id1_15_1_,
        weekconten2_.content_id as content_2_4_2_,
        daycontent3_.content_id as content_2_4_3_,
        daycontent4_.content_id as content_2_4_4_,
        character0_.created_date as created_2_0_0_,
        character0_.last_modified_date as last_mod3_0_0_,
        character0_.challenge_abyss as challeng4_0_0_,
        character0_.challenge_guardian as challeng5_0_0_,
        character0_.character_class_name as characte6_0_0_,
        character0_.character_image as characte7_0_0_,
        character0_.character_level as characte8_0_0_,
        character0_.character_name as characte9_0_0_,
        character0_.chaos_id as chaos_i36_0_0_,
        character0_.chaos_check as chaos_c10_0_0_,
        character0_.chaos_gauge as chaos_g11_0_0_,
        character0_.chaos_gold as chaos_g12_0_0_,
        character0_.chaos_name as chaos_n13_0_0_,
        character0_.epona_check as epona_c14_0_0_,
        character0_.epona_check2 as epona_c15_0_0_,
        character0_.epona_gauge as epona_g16_0_0_,
        character0_.guardian_id as guardia37_0_0_,
        character0_.guardian_check as guardia17_0_0_,
        character0_.guardian_gauge as guardia18_0_0_,
        character0_.guardian_gold as guardia19_0_0_,
        character0_.guardian_name as guardia20_0_0_,
        character0_.gold_character as gold_ch21_0_0_,
        character0_.item_level as item_le22_0_0_,
        character0_.member_id as member_38_0_0_,
        character0_.server_name as server_23_0_0_,
        character0_.show_chaos as show_ch24_0_0_,
        character0_.show_character as show_ch25_0_0_,
        character0_.show_cube_ticket as show_cu26_0_0_,
        character0_.show_epona as show_ep27_0_0_,
        character0_.show_guardian as show_gu28_0_0_,
        character0_.show_silmael_change as show_si29_0_0_,
        character0_.show_week_epona as show_we30_0_0_,
        character0_.show_week_todo as show_we31_0_0_,
        character0_.sort_number as sort_nu32_0_0_,
        character0_.cube_ticket as cube_ti33_0_0_,
        character0_.silmael_change as silmael34_0_0_,
        character0_.week_epona as week_ep35_0_0_,
        todov2list1_.created_date as created_2_15_1_,
        todov2list1_.last_modified_date as last_mod3_15_1_,
        todov2list1_.character_id as characte8_15_1_,
        todov2list1_.cool_time as cool_tim4_15_1_,
        todov2list1_.gold as gold5_15_1_,
        todov2list1_.is_checked as is_check6_15_1_,
        todov2list1_.message as message7_15_1_,
        todov2list1_.content_id as content_9_15_1_,
        todov2list1_.character_id as characte8_15_0__,
        todov2list1_.todo_id as todo_id1_15_0__,
        weekconten2_.category as category3_4_2_,
        weekconten2_.level as level4_4_2_,
        weekconten2_.name as name5_4_2_,
        weekconten2_.cool_time as cool_ti16_4_2_,
        weekconten2_.destruction_stone as destruc13_4_2_,
        weekconten2_.gate as gate17_4_2_,
        weekconten2_.gold as gold18_4_2_,
        weekconten2_.guardian_stone as guardia14_4_2_,
        weekconten2_.honor_shard as honor_s15_4_2_,
        weekconten2_.leap_stone as leap_sto8_4_2_,
        weekconten2_.week_category as week_ca19_4_2_,
        weekconten2_.week_content_category as week_co20_4_2_,
        daycontent3_.category as category3_4_3_,
        daycontent3_.level as level4_4_3_,
        daycontent3_.name as name5_4_3_,
        daycontent3_.destruction_stone as destruc13_4_3_,
        daycontent3_.guardian_stone as guardia14_4_3_,
        daycontent3_.honor_shard as honor_s15_4_3_,
        daycontent3_.jewelry as jewelry7_4_3_,
        daycontent3_.leap_stone as leap_sto8_4_3_,
        daycontent3_.shilling as shilling9_4_3_,
        daycontent4_.category as category3_4_4_,
        daycontent4_.level as level4_4_4_,
        daycontent4_.name as name5_4_4_,
        daycontent4_.destruction_stone as destruc13_4_4_,
        daycontent4_.guardian_stone as guardia14_4_4_,
        daycontent4_.honor_shard as honor_s15_4_4_,
        daycontent4_.jewelry as jewelry7_4_4_,
        daycontent4_.leap_stone as leap_sto8_4_4_,
        daycontent4_.shilling as shilling9_4_4_ 
    from
        characters character0_ 
    inner join
        todov2 todov2list1_ 
            on character0_.characters_id=todov2list1_.character_id 
    inner join
        content weekconten2_ 
            on todov2list1_.content_id=weekconten2_.content_id 
    inner join
        content daycontent3_ 
            on character0_.guardian_id=daycontent3_.content_id 
    inner join
        content daycontent4_ 
            on character0_.chaos_id=daycontent4_.content_id cross 
    join
        member member5_ 
    where
        character0_.member_id=member5_.member_id 
        and member5_.username=? 
        and character0_.server_name=?

 

 

3. 정리 및 후기

리팩토링 후 테스트해보니 주간 숙제가 없는 캐릭터 데이터는 못불러와서 다시 롤백...

저작자표시 (새창열림)
'Project/LOATODO' 카테고리의 다른 글
  • [LOATODO] 이메일 인증 Redis 서버 -> RDBMS로 변경
  • [LOATODO] 이메일 인증 추가후 구글 로그인 error
  • [LOATODO] JPA 영속성 컨텍스트 더티체킹 VS JPQL로 벌크업데이트
  • [LOATODO] 주간 숙제 완료 시 수치가 초과되는 에러
마볼링
마볼링
개발과 게임에 관한 내용을 읽기 쉽게 정리합니다.
  • 마볼링
    게임을 좋아하는 개발자의 블로그
    마볼링
  • 전체
    오늘
    어제
    • 분류 전체보기
      • Project
        • LOATODO
        • 인스타그램 클론코딩(중단)
      • Language
        • Java
        • PHP
        • Javascript
      • Framework & Library
        • Spring
        • Vue
      • Computer Science
        • Web
        • Linux
      • CodingTest
        • Algorithm
        • Kotlin으로 푼 코딩 테스트
        • Java로 푼 코딩 테스트
        • Sorting & Thinking
        • BFS
      • 책&강의 정리
      • 정보처리기사
      • 개인
        • 팰월드(PALWORLD)
        • 마인크래프트
  • 블로그 메뉴

    • 링크

      • GitHub
      • Threads
    • 공지사항

    • 인기 글

    • 태그

      codingtest
      php
      네트워크
      이터널 모드
      티스토리챌린지
      LoaTodo
      JPA
      java
      아크 서바이벌
      로아투두
      springboot
      jsp
      error
      Spring
      코딩테스트
      오블완
      운영체제
      프로그래머스
      CS
      Database
    • 최근 댓글

    • 최근 글

    • hELLO· Designed By정상우.v4.10.1
    마볼링
    [LOATODO] 코드 리팩토링 SELECT 리팩토링
    상단으로

    티스토리툴바