我在我的穆迪网站上使用了下面给出的自定义查询,它的工作正常,但是现在mdl_user_enrollments表中的总记录为3000万,需要一些时间才能将结果返回到我的最终屏幕。请让我知道如何使其快速。

查询如下

select t1.userid,t2.courseid AS course_id, t1.timestart AS subscription_start, t1.timeend AS subscription_end,t1.timecreated AS timecreated,t1.timemodified AS timemodified, t3.id AS quiz_id,

t3.name AS quiz_name from mdl_user_enrolments t1

join  mdl_enrol t2 on t1.userid=$user_id and  t1.enrolid = t2.id

join mdl_quiz t3 on t3.course = t2.courseid


解释输出

Explain mdl_user_enrolments result

Field          Type       Null    Key    Default      Extra
id           bigint(10)    NO     PRI     NULL         auto_increment
status       bigint(10)    NO      0
enrolid      bigint(10)    NO     MUL     NULL
userid       bigint(10)    NO     MUL     NULL
timestart    bigint(10)    NO      0
timeend      bigint(10)    NO   2147483647
modifierid   bigint(10)    NO      MUL      0
timecreated  bigint(10)    NO       0
timemodified bigint(10)    NO       0


分析表mdl_user_enrolments结果

表操作Msg_type Msg_text
eLearningDev_v1.mdl_user_enrolments分析状态OK

表mdl_user_enrolments的大小910 MB

最佳答案

Select t1.userid,t2.courseid AS course_id, t1.timestart AS subscription_start, t1.timeend AS subscription_end,t1.timecreated AS timecreated,t1.timemodified AS timemodified, t3.id AS quiz_id,
t3.name AS quiz_name from mdl_user_enrolments t1
LEFT join  mdl_enrol AS  t2 on t1.userid=$user_id and  t1.enrolid = t2.id
LEFT join mdl_quiz AS  t3 on t3.course = t2.courseid


希望这对您有用。

关于php - PHP从3000万条记录中检索数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41360154/

10-12 06:48