sql - 调整 Postgres 查询
问题描述
我需要根据否定条件加入两个表,这需要很长时间才能执行。
SELECT oola.ship_from_org_id ,
oola.subinventory,
oola.line_id ,
crl.requirement_header_id,
crl.inventory_item_id
FROM racesbi_ods.ods_csp_requirement_lines crl
LEFT JOIN racesbi_ods.ods_csp_req_line_details crld
ON crld.requirement_line_id = crl.requirement_line_id
JOIN racesbi_ods.ods_oe_order_lines_all oola
ON crld.source_id <> oola.line_id
AND oola.header_id IN
(SELECT header_id FROM racesbi_ods.ods_oe_order_lines_All
WHERE line_id = crld.source_id
)
为了调整这一点,我尝试使用临时表。但我仍然面临性能问题。
create temporary table tst1 --ON commit drop 244067
as(select crl.requirement_header_id,
crl.inventory_item_id,
crld.requirement_line_id,
crld.source_id FROM racesbi_ods.ods_csp_requirement_lines crl
LEFT JOIN racesbi_ods.ods_csp_req_line_details crld
ON crld.requirement_line_id = crl.requirement_line_id
) distributed randomly;
-- Query returned successfully: 244067 rows affected, 15264 ms execution time.
create temporary table tst2 --ON commit drop 2700951
as(
select ship_from_org_id,
subinventory,
line_id
FROM racesbi_ods.ods_oe_order_lines_all
) distributed randomly;
create temporary table tst3 --ON commit drop
as(
select tst1.requirement_header_id,
tst1.inventory_item_id,
tst2.ship_from_org_id,
tst2.subinventory,
tst2.line_id
FROM tst1
JOIN tst2 ON tst2.line_id != tst1.source_id
) distributed randomly;
请帮助如何处理 JOIN 中的否定条件
解决方案
推荐阅读
- r - 在ggplot2中更改分组条形图的颜色
- google-sheets - 这适用于一个单元格 - 现在我如何将它应用于一个范围?
- python - 为什么这些递归函数使用相同数量的内存?
- c# - 右击看不到 C# 按钮被按下
- c++ - 在 C/C++ 中从 int32 转换为 char 时出现垃圾
- twilio - Twilio Sip 域和 Yealink 电话转移不起作用
- scala - akka stream alpakka csv:跳过异常并解析下一行
- sql - 更新行,内部加入获取顶行
- c++ - 最大面积直方图 动态规划 C++
- javascript - 使用 JavaScript 查找给定值的完整对象路径