我正在尝试优化/加快数据加载的性能,是否有办法解决此问题?
我有3个表:tbl_tt_college_studentpersonalinfo
-此表显示学生的姓名,它是查询中的连接tbl_tt_college_preenrollment
-此表显示预注册学员的待定状态tbl_tt_college_enlistment
-此表将检查学生的现有记录。
以下是我的查询:- 我遇到的问题是数据加载很慢,可能需要30-50秒。有没有办法改进这个问题,或者使它像连接查询一样?
public function get_enlists()
{
$this->db->join('tbl_tt_college_studentpersonalinfo','tbl_tt_college_preenrollment.studentID = tbl_tt_college_studentpersonalinfo.studentID');
$this->db->where('tbl_tt_college_preenrollment.departmentID', $this->input->post('course'));
$this->db->where('tbl_tt_college_preenrollment.yearLevel', $this->input->post('yearLevel'));
$this->db->where("NOT EXISTS (SELECT tbl_tt_college_enlistment.studentKeyID FROM tbl_tt_college_enlistment WHERE tbl_tt_college_enlistment.studentKeyID = tbl_tt_college_preenrollment.studentKeyID AND schoolYear = '" . $this->session->userdata('currentAcademicYear') . '-' . ($this->session->userdata('currentAcademicYear') + 1) . "' AND semester = '" . $this->session->userdata('currentSemester') . "')");
$query = $this->db->get('tbl_tt_college_preenrollment');
return $query->result_array();
}
下面是引用的原始查询:
NOT EXISTS (
SELECT studentKeyID FROM tbl_tt_college_enlistment
WHERE tbl_tt_college_studentpersonalinfo.studentKeyID = tbl_tt_college_enlistment.studentKeyID
AND schoolYear = '" . $this->session->userdata('currentAcademicYear') . '-' . ($this->session->userdata('currentAcademicYear') + 1) . "'
AND semester = '" . $this->session->userdata('currentSemester') . "'
)
1条答案
按热度按时间zsbz8rwp1#
看看
tbl_tt_college_enlistment
上的复合索引是否有帮助:如果不充分,请提供
SHOW CREATE TABLE
和EXPLAIN SELECT ...