gpt4 book ai didi

sql - 优化 Oracle SQL 查询

转载 作者:行者123 更新时间:2023-12-03 16:10:06 25 4
gpt4 key购买 nike

您好,我有一个正在尝试优化的 SQL 查询。这个查询在 0.3 秒内完成,但我需要对大量不同的 storeId 运行相同的查询——无论如何优化这个查询以使其更快,或者改变它以便它一次获取所有 storeId。

我总是可以在 C# 中创建一个新命令,该命令连接到该命令以使其成为大量不同查询的联合。

select /*+ PUSH_SUBQ */ *  
from mytable r
where r.s in (1, 7)
and r.d in (1, 75)
and r.storeid = 1162
and r.period = 20110528
and r.pid in (select /*+ no_unnest qb_name(subq1) */
productid from otherTable where itmid=9999)

我已经尝试过这样的事情,但它需要永远。
select  /*+ PUSH_SUBQ */ * 
from mytable r
where r.s in (1, 7)
and r.d in (1, 75)
and r.storeid in (1162, 1223, 1231, 51231, 231, ...)
and r.period = 20110528
and r.pid in (select /*+ no_unnest qb_name(subq1) */
productid from otherTable where itmid=9999)

MyTable 有这样的索引:
pid 是非唯一的,分区的,没有 JOIN_INDEX
所有其他列都是 UNIQUE、PARTITIONED、NO JOIN_INDEX

最佳答案

尝试对您的查询运行 Oracle EXPLAIN PLAN。它应该突出问题区域,并可能有助于缩小查询本身或被查询表中的瓶颈。

使用解释计划:
http://download.oracle.com/docs/cd/B10500_01/server.920/a96533/ex_plan.htm

关于sql - 优化 Oracle SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6311834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com