內容/問題描述:
小弟遇到了一個瓶頸
我有個 table 要去裡面取這個 User 最後回答的那個版本號碼並且記錄到另一個 table
如下:
UPDATE tm_team_assign_curriculum_profile t
LEFT JOIN (
SELECT pp.uuid as profile_id , pp.badge_no , max(csqa1.version) as version , ce.uuid as cm_enrollment_id , ttacp.team_assign_curriculum_uuid
FROM tm_team_assign_curriculum_profile ttacp
INNER JOIN pm_profile pp ON ttacp.profile_id = pp.uuid
INNER JOIN cm_enrollment ce ON pp.badge_no = ce.badge_no
INNER JOIN cm_profile_survey_ques_answer csqa1 ON csqa1.cm_enrollment_id = ce.uuid
WHERE ttacp.status = '1'
AND ce.course_id = ( select type_id from ap_risksurvey_conf where code = 'ASSIGN_CHECKLISTCODE_RISKSURVEY' )
GROUP BY pp.uuid
)userVersion ON userVersion.profile_id = t.profile_id
SET t.enrollment_id = userVersion.cm_enrollment_id , t.version = userVersion.version , t.modified_date = NOW()
WHERE t.status = '1'
AND userVersion.profile_id is NOT NULL ;
schema:
schema:
CREATE TABLE tm_team_assign_curriculum_profile (uuid , team_assign_curriculum_uuid , profile_id , enrollment_id , version , status )
CREATE TABLE pm_profile (uuid , badge_no );
CREATE TABLE cm_enrollment (uuid , course_id , badge_no )
CREATE TABLE cm_profile_survey_ques_answer (uuid , cm_enrollment_id , version )
tm_team_assign_curriculum_profile :
是這次要做的 user ( 最大會到5w 筆 )
cm_profile_survey_ques_answer :
是每個 User 回答的紀錄 , 人數有 將近 20w ,
題目有三十幾題,
每次回答後 version會 +1 ,
再加上不只回答一次 , 所以數量很大
一兩萬筆都是沒什麼問題的 , 但是只要有五萬筆就掛在這裡了
一直想不到有什麼方法可以再提升一下效率 , 不知道各位先進是否有什麼想法?