【发布时间】:2021-04-30 01:10:29
【问题描述】:
我有一个包含 5 万个收据 ID(硬编码值)的列表。我想在 where 条件下应用这 5 万个 ID 或加入操作。我使用了下面的“with”子句来创建一个临时表来收集这 5 万个 ID。然后我在连接查询中使用这个临时表进行过滤。
with temp_receiptIds(receiptId)
as
(
select 'M0000001' from dual
union
select 'M0000002' from dual
union
select 'M0000003' from dual
union
select 'M0000004' from dual
..
..
...
union
select 'M0049999' from dual
union
select 'M0050000' from dual
)
select sal.receiptId, prd.product_name, prd.product_price, sal.sales_date, sal.seller_name
from product prd
join sales sal on prd.product_id=sal.product_id
join temp_receiptIds tmp on tmp.receiptId=sal.receiptId
每当我运行上述选择连接查询以根据业务人员的要求提取数据时,在生产服务器中获取结果大约需要 8 分钟。 我的上述方法正确吗?通过考虑生产服务器中的最佳性能,有没有比这更简单的方法。 请注意,每一秒,客户都会使用生产数据库。由于生产数据库非常繁忙,我是否可以直接在生产数据库中运行此查询,是否会导致客户使用每秒调用此生产数据库的网站时性能变慢。正确答案将不胜感激!谢谢
【问题讨论】:
-
50,000 个硬编码值?!?!它们起源于哪里?您如何将它们硬编码为 50,000 个单独的 SELECT 语句?当然,您可以使用实用程序将它们加载到表中并从那里引用它们。
-
感谢@thatjeffsmith 的回复。 50,000 个硬编码值来自一个 csv 文件。
-
我回复了吗?将这些 csv 放入一个表中,这就像 where 子句一样简单
标签: oracle performance join plsql temp-tables