sql - 大表查询
问题描述
我有以下查询 -
SELECT n.fname
,ii.render AS practitioner_npi
,n.address AS address1
,substring(n.postal,0,6) AS zip
,substring(n.postal,6,4) AS zip4
,ii.count AS count
FROM
(
SELECT render, count(*) AS count
FROM dx sl
JOIN annual caq
ON DATE_TRUNC('quarter', date_of_service::date) >= caq.start
JOIN entities n
ON sl.render = n.npi
WHERE dx_cd IN (
SELECT DISTINCT dx_cd
FROM dx_per_code pc
JOIN bucket bac
ON pc.code = bac.hcpccode
WHERE
bucketname = 'something'
AND dx_rank BETWEEN 1 AND 5
)
AND n.npi_type = '1'
GROUP BY render
)
ii
JOIN npi n ON n.npi = ii.render
LEFT JOIN taxonomy t ON t.code = n.taxonomy
ORDER BY ii.count DESC;
dx 表没有任何索引,包含大约 8B 条记录。此查询当前需要 20 分钟才能运行。我可以进行哪些索引/优化以使其运行得更快?
解决方案
推荐阅读
- android - 为什么当我“缓慢”更改滑块时,我的搜索栏只注册 0 值?
- c - 我的 C 代码给了我很多错误
- javascript - 单击 SpeedDialAction 按钮时,我可以阻止 Material-UI SpeedDial 关闭吗
- google-cloud-platform - 限制谷歌云功能配额
- javascript - 在我自己的网站上显示我自己的 Instagram 供稿
- python - 是否有可能通过 Microsoft Teams 中的代码响应呼叫?
- html - Bootstrip 网格元素 - 将大多数内容垂直对齐到顶部,但将按钮对齐到底部
- anaconda - 没有名为“trading_calenders”的模块
- nuxt.js - 带有可选参数的 Nuxjs 主路由
- sql - SQL:选择一系列日期范围内的所有观察?