(1)번에서 뭐가 문제인지 찾아서 응급조치를 했습니다.
http://opencode.co.kr/bbs/board.php?bo_table=gnu4_turning&wr_id=258
그런데, 이거도 상당한 query 부하가 됩니다.
검색 query와 무관한 것이 있는 경우에는...
그래서 tmp_table을 쓰도록 수정해주는 것이 필요합니다.
이것은 조금 더 난이도가 있기에 (2)번 튜닝이라고 합니다.
임시파일이 자동으로 뽀개지지 않기 때문에, tmp 파일을 2개 만듭니다.
sql로 부수는 것도 가능하지만 그것도 일이라... 안하는게 나을거 같아요.
그나저나... 팀장닷컴 때문에 코드가 걸레처럼...ㄷㄷㄷ
if (!$board['bo_use_list_view']) {
if ($sql_search)
$sql_search = " and " . $sql_search;
// 윗글을 얻음
// 불당팩 - tmp table을 만들고, 거기서 한판 더 돌리는게 빠르다. $sql_search는 index를 안타니까...
// 팀장처럼 create temporaty table의 권한을 안주는 경우, config.php에서 $g4['old_stype_search'] 설정값을 1로.
if ($g4['old_stype_search']) {
if ($write['wr_reply']) {
// 답글일 때. 답글이 아닐 때는 돌려봐야 답이 없습니다.
$sql = " select wr_id, wr_subject from $write_table where wr_is_comment = 0 and wr_num = '$write[wr_num]' and wr_reply < '$write[wr_reply]' $sql_search order by wr_num desc, wr_reply desc limit 1 ";
$prev = sql_fetch($sql);
}
// 위의 쿼리문으로 값을 얻지 못했다면
if (!$prev['wr_id']) {
$sql = " select wr_id, wr_subject from $write_table where wr_is_comment = 0 and wr_num < '$write[wr_num]' $sql_search order by wr_num desc, wr_reply desc limit 1 ";
$prev = sql_fetch($sql);
}
} else {
if ($write['wr_reply']) {
// 답글일 때. 답글이 아닐 때는 돌려봐야 답이 없습니다.
$sql = " select * from $write_table where wr_is_comment = 0 and wr_num = '$write[wr_num]' and wr_reply < '$write[wr_reply]' ";
$sql_tmp = " create TEMPORARY table view_tmp_prev as $sql ";
$sql_ord = " select wr_id, wr_subject from view_tmp_prev where 1 $sql_search order by wr_num desc, wr_reply desc limit 1 ";
@mysql_query($sql_tmp) or die("<p>$sql_tmp<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$result = @mysql_query($sql_ord) or die("<p>$sql_ord<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$prev = @mysql_fetch_assoc($result);
}
// 위의 쿼리문으로 값을 얻지 못했다면
if (!$prev['wr_id']) {
$sql = " select * from $write_table where wr_is_comment = 0 and wr_num < '$write[wr_num]' ";
$sql_tmp = " create TEMPORARY table view_tmp_prev1 as $sql ";
$sql_ord = " select wr_id, wr_subject from view_tmp_prev1 where 1 $sql_search order by wr_num desc, wr_reply desc limit 1 ";
@mysql_query($sql_tmp) or die("<p>$sql_tmp<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$result = @mysql_query($sql_ord) or die("<p>$sql_ord<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$prev = @mysql_fetch_assoc($result);
}
}
// 아래글을 얻음
// 불당팩 - tmp table을 만들고, 거기서 한판 더 돌리는게 빠르다. $sql_search는 index를 안타니까...
// 팀장처럼 create temporaty table의 권한을 안주는 경우, config.php에서 $g4['old_stype_search'] 설정값을 1로.
if ($g4['old_stype_search']) {
if ($write['wr_reply']) {
// 답글일 때. 답글이 아닐 때는 돌려봐야 답이 없습니다.
$sql = " select wr_id, wr_subject from $write_table where wr_is_comment = 0 and wr_num = '$write[wr_num]' and wr_reply > '$write[wr_reply]' $sql_search order by wr_num, wr_reply limit 1 ";
$next = sql_fetch($sql);
}
// 위의 쿼리문으로 값을 얻지 못했다면
if (!$next['wr_id']) {
$sql = " select wr_id, wr_subject from $write_table where wr_is_comment = 0 and wr_num > '$write[wr_num]' $sql_search order by wr_num, wr_reply limit 1 ";
$next = sql_fetch($sql);
}
} else {
if ($write['wr_reply']) {
// 답글일 때. 답글이 아닐 때는 돌려봐야 답이 없습니다.
$sql = " select * from $write_table where wr_is_comment = 0 and wr_num = '$write[wr_num]' and wr_reply > '$write[wr_reply]' ";
$sql_tmp = " create TEMPORARY table view_tmp_next as $sql ";
$sql_ord = " select wr_id, wr_subject from view_tmp_next where 1 $sql_search order by wr_num, wr_reply limit 1 ";
@mysql_query($sql_tmp) or die("<p>$sql_tmp<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$result = @mysql_query($sql_ord) or die("<p>$sql_ord<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$next = @mysql_fetch_assoc($result);
}
// 위의 쿼리문으로 값을 얻지 못했다면
if (!$next['wr_id']) {
$sql = " select * from $write_table where wr_is_comment = 0 and wr_num > '$write[wr_num]' ";
$sql_tmp = " create TEMPORARY table view_tmp_next1 as $sql ";
$sql_ord = " select wr_id, wr_subject from view_tmp_next1 where 1 $sql_search order by wr_num, wr_reply limit 1 ";
@mysql_query($sql_tmp) or die("<p>$sql_tmp<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$result = @mysql_query($sql_ord) or die("<p>$sql_ord<p>" . mysql_errno() . " : " . mysql_error() . "<p>error file : $_SERVER[PHP_SELF]");
$next = @mysql_fetch_assoc($result);
}
}
}