SELECT
s.seq, s.source_key,
case when a.keyword is null then s.keyword else a.keyword end keyword ,
s.platform, s.title, s.origin_price, s.detail_page, s.detail_image, s.rank_star, s.memo, s.status, s.target, s.d_title, s.d_price, s.d_unit, s.d_fraction, s.d_price_add, s.d_feature, s.d_feature2, s.d_upc, s.d_menufacturer, s.d_asin, s.d_imgs, s.d_detail_imgs, s.d_dimensions, s.d_weight, s.d_options, s.sell_vat, s.sell_price, s.sell_amount, s.sell_representative_image, s.sell_upload_image, s.sell_onoff_discount, s.sell_onoff_discount_base, s.sell_onoff_discount_base_duration, s.sell_onoff_discount_base_duration_st, s.sell_onoff_discount_base_duration_end, s.sell_onoff_discount_reserve, s.sell_onoff_discount_reserve_st, s.sell_onoff_discount_reserve_end, s.sell_price_tax_type, s.sell_return_delivery_fee, s.sell_exchange_delivery_fee, s.sell_after_service_telephone_number, s.sell_after_service_guide_content, s.sell_html, s.sell_no, s.sell_logistics_code, s.sell_origin, s.t_kr, s.t_en, s.t_ch, s.t_won, s.t_feature, s.t_feature2, s.t_detail_imgs, s.t_imgs, s.create_DT, s.update_DT, s.delete_DT, s.delete_YN,
s.sell_tag,
a.keyword_en, a.keyword_cn, a.keyword_tw, a.detail_image, a.category,
case when s.category_01 is null then a.category_01 else s.category_01 end category_01 ,
case when s.category_02 is null then a.category_02 else s.category_02 end category_02 ,
case when s.category_03 is null then a.category_03 else s.category_03 end category_03 ,
case when s.category_04 is null then a.category_04 else s.category_04 end category_04 ,
a.keyword_type,
a.keyword_type,a.keyword_type_portion,a.search_cnt, a.product_cnt, a.compete_type,
a.compete_ratio, a.ad_click_cnt, a.ad_click_compete_type, a.ad_click_compete_type_ratio,
a.click_ad_compete, a.click_ad_compete_ratio,
(select b.category_number
from 01_info_category_naver b
where b.category_01 = a.category_01
and case when a.category_02 ='' then b.category_02 is null else b.category_02 = a.category_02 end
and case when a.category_03 ='' then b.category_03 is null else b.category_03 = a.category_03 end
and case when a.category_04 ='' then b.category_04 is null else b.category_04 = a.category_04 end ) as category_number,
c.cd_Type, c.cd_Name, c.cd_Code, c.cd_Info
from 03_info_detail s
left join 02_info_keyword a on a.seq = s.source_key
left join code c on c.cd_ID = s.sell_logistics_code
여러 테이블을 join 을 할경우 발생할 수 있는문제중 하나는 “속도” 문제가 발생한다.
테이블을 읽을때 DB엔진은 일시적으로 lock 상태로 테이블을 묶어둔다.
여러 쓰레드가 동시에온다면, 각 쓰레드별로 묶인다고 생각하면된다.
읽음 처리가 끝나면 해당 lock 상태가 종료되는데, 읽음 처리가 길어지면 길어질수록 여러 다른 쓰레드가 같은 테이블을 본다면, latency문제가 생기게된다.
Index 확인하고 추가하는 방법
```
-- 인덱스 확인하기
SHOW INDEX FROM drivingClose;
SHOW INDEX FROM DriverHistory;
SHOW INDEX FROM driving;
select * from driving where rDay = '20210314'
-- 인덱스 추가하기
ALTER TABLE driving ADD INDEX indexx_rpk (rpk);
-- 쿼리속도확인할것
EXPLAIN
select *, IFNULL(( select msg from driving b where b.rpk = a.rpk and type = 'STARTED' limit 1), '' ) as smsg
from drivingClose a where rDay = '20210314'
```
인덱싱 전

인덱싱 후



