CI 묻고 답하기

제목 count 속도 차이
글쓴이 이지포토 작성시각 2012/09/11 14:54:28
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 20412   RSS

리스트의 토탈 갯수를 구하려면 아래와 같이 쓰고 있습니다.
// 릿스트 구하기
 function lists($page=1, $rowNo=20, $pagelistno=20)
 { 
  $this->page_rows = $rowNo;
  $this->page_list_size = $pagelistno;
  $start_limit = (($page-1) * $rowNo);
  
 // $this->db->where('bw_notice', 'qna');
  $this->db->select('o.*, a.*');
  $this->db->where( "o.CertFlag", "Y" ) ;


  $this->db->from($this->table_name.' as o');
  $this->db->join('ibtpoint as a', 'a.Idx = o.point_Idx', 'left');

  $this->db->limit( $rowNo, $start_limit);
 

  $this->kcSearch();
  $query = $this->db->get();
  echo $this->db->last_query();

  return $query->result_array();             
 }


// Total 갯수 구하기
 function total_cnt(){
  //$this->db->select(" * ");
  $this->db->select(" count(*) as total_cnt");
  $this->db->from($this->table_name.' as o');
  $this->db->join('ibtpoint as a', 'a.Idx = o.point_Idx', 'left');
  $this->db->where( "o.CertFlag","Y" ) ;

  $this->kcSearch();
  $query = $this->db->get();

  //return $query->num_rows();
  return $query->row()->total_cnt;
 }


//검색 조건
 function kcSearch(){
  @extract($_POST);
  if(@$stx){
   if ($sfl=="mID") {    $this->db->like('o.mID',  $stx);  }
   if ($sfl=="mName") {   $this->db->like('o.mName', $stx);  }
   if ($sfl=="Email") {   $this->db->like('o.Email', $stx);  }
   if ($sfl=="mTel") {    $this->db->like('o.mTel',  $stx);  }
   if ($sfl=="mMobile") {   $this->db->like('o.mMobile', $stx);  }
   if ($sfl=="mRegdate") {   $this->db->like('o.mRegdate', $stx);  }
  }
 }

멤버테이블의 모델 부분인데요. 여기서 마크한 select * 를 한것과 count(*) 한것의 속도 차이와 리소스 잡아먹는 양은
체감적으로 많이 차이 날까요?
여러분들은 어떻게 하세요?

리스트를 구하기 위해 별도의 함수를 만들고

그들의 총 갯수를 구하는 쿼리문을 별도로 만들지 않고 num_rows 형태로 한 쿼리에서 뽑아 내나요?
 

 다음글 You don't have permission to a... (5)
 이전글 20분뒤 특정 디비에 있는 값을 '자동으로' 지우고 싶... (4)

댓글

변종원(웅파) / 2012/09/11 15:05:23 / 추천 0
위 모델을 호출하는 컨트롤러에서 프로파일러 삽입해보시면 
해당 페이지 메모리 사용량과 쿼리의 실행시간이 나옵니다.

소스 주석처리해서 비교해보시면 되겠네요.

차이가 있을 겁니다. 
이지포토 / 2012/09/11 15:55:47 / 추천 0

웅파님 매번 빠른 응답 감사 합니다.
복받으세요.^^