你好,我有一个需要优化的 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)
我的表格有如下的索引: pid是非唯一的,已分区的,无联接索引 其他所有列都是唯一的,已分区的,无联接索引