SELECT a.sectionid as sectionid, views.timestamp as timestamp,
views.time_on_page as time_on_page, views.video as video,
views.access as access, masterid
FROM (
SELECT m.timestamp as timestamp, m.time_on_page as time_on_page,
AES_DECRYPT(m.IP_Blob, UNHEX(SHA2('Jove Is Cool',512))) as ip_bin,
m.page as page, m.language as language, m.access as access,
m.referrer as referrer, m.searchterms as searchterms,
m.user_id as user_id,
case when m.page regexp '/pdf(-materials)?/'
then replace(replace(replace(RIGHT(m.page, 5), '/', ''), 'd', ''), 'f', '')
else m.video end as video,
m.id as masterid
FROM masterstats_innodb as m
join stats_to_institution as sti ON m.id = sti.statid
JOIN institutions as ins ON sti.institutionid = ins.institutionid
WHERE m.timestamp BETWEEN '2019-12-30' AND '2020-12-29'
and ( ins.institutionid = '2'
or ins.parentinstitutionid = '2' )
) as views
LEFT JOIN articles as a ON views.video = a.productid
`enter code here`
order by masteridmasterstats_innodb -- 115759655 stats_to_institution -- 45317238个机构--45038
已经为masterstats_innodb表创建了所有可能的索引和分区。
发布于 2021-01-06 04:41:47
OR不能很好地优化;切换到UNION是一种常见的修复方法。但目前还不清楚这是否会有所帮助。m.timestamp和(ins.institutionid = '2' or ins.parentinstitutionid = '2'),哪个更有选择性?
要在stats_to_institution上获得最佳索引:http://mysql.rjweb.org/doc.php/index_cookbook_mysql#many_to_many_mapping_table
enter code here不知道它在哪里;请用一个示例来填充。
暂定INDEXes:
a: (productid, sectionid)
ins: (parentinstitutionid, institutionid)
m: (timestamp)
sti: (statid, institutionid)
sti: (institutionid, statid)https://stackoverflow.com/questions/65559287
复制相似问题