首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查询耗时较长

查询耗时较长
EN

Stack Overflow用户
提问于 2021-01-04 15:52:10
回答 1查看 49关注 0票数 1
代码语言:javascript
复制
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 masterid

masterstats_innodb -- 115759655 stats_to_institution -- 45317238个机构--45038

已经为masterstats_innodb表创建了所有可能的索引和分区。

EN

回答 1

Stack Overflow用户

发布于 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:

代码语言:javascript
复制
a:  (productid, sectionid)
ins:  (parentinstitutionid, institutionid)
m:  (timestamp)
sti:  (statid, institutionid)
sti:  (institutionid, statid)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65559287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档