쿼리문제좀 봐주세요~
본문
안녕하세요?
아래의 쿼리실행시 2분이상 로딩이 걸립니다.
왜 그런지 전문가님들의 의견을 듣고 싶습니다.
$real_today1 = $g4[server_time] + (int)(86400 * -1);
$real_today2 = $g4[server_time] + (int)(86400 * 0);
$real_today3 = $g4[server_time] + (int)(86400 * 1);
$real_today4 = $g4[server_time] + (int)(86400 * 2);
$real_today5 = $g4[server_time] + (int)(86400 * 3);
$rtoday[0] = $real_today1 = date("Y-m-d", $real_today1);
$rtoday[1] = $real_today2 = date("Y-m-d", $real_today2);
$rtoday[2] = $real_today3 = date("Y-m-d", $real_today3);
$rtoday[3] = $real_today4 = date("Y-m-d", $real_today4);
$rtoday[4] = $real_today5 = date("Y-m-d", $real_today5);
for($num=0;$num<5;$num++){
$td_sql = "select count(*) as cnt from nss_sikdan_ok so
join nss_order od on od.od_id=so.od_id
join nss_cart ct on od.on_uid=ct.on_uid
where ct.ct_status in('배송','배송완료') and so.today_end='1' and DATE_FORMAT(so.today_end_date,'%Y-%m-%d')='".$rtoday[$num]."'
";
$td_data1 = sql_fetch($td_sql);
$td_cnt1[$num] = $td_data1[cnt];
$td_sql2 = "select count(*) as cnt from nss_sikdan_ok so
join nss_order od on od.od_id=so.od_id
join nss_cart ct on od.on_uid=ct.on_uid
where ct.ct_status in('배송','배송완료') and so.today_end='1' and DATE_FORMAT(so.today_end_date,'%Y-%m-%d')='".$rtoday[$num]."' and so.change_date>so.today_end_date2
";
$td_data2 = sql_fetch($td_sql2);
$td_cnt2[$num] = $td_data2[cnt];
$td_sql3 = "select * from nss_sikdan_ok where od_id in(
select od_id from nss_order od
join nss_cart ct on od.on_uid=ct.on_uid
where ct.ct_status in('배송','배송완료')
) and (DATE_FORMAT(today_end_date,'%Y-%m-%d')='".$rtoday[$num]."') and today_end='1'
limit 0,1";
$today_end_data = sql_fetch($td_sql3);
$today_end_arr[$num] = $today_end_data[today_end_date2];
}
답변 2
explan
select 'test'
위와 같은 형태로 쿼리를 실행해서 index 를 사용하고 있는지 확인해보세요
원인을 찾다보니... 맨아래 쿼리때문에 발생한문제 같습니다.
바로 아래의 쿼리입니다.
$td_sql3 = "select * from nss_sikdan_ok where od_id in(
select od_id from nss_order od
join nss_cart ct on od.on_uid=ct.on_uid
where ct.ct_status in('배송','배송완료')
) and (DATE_FORMAT(today_end_date,'%Y-%m-%d')='".$rtoday[$num]."') and today_end='1'
limit 0,1";
$today_end_data = sql_fetch($td_sql3);
$today_end_arr[$num] = $today_end_data[today_end_date2];