如何调优以下 Oracle10g 查询?
我编写了一个查询来从 my_codes 表中获取一些重叠的数字范围。查询是...
select distinct t1.destination,
t1.digitsmin,
t1.digitsmax,
t2.destination,
t2.digitsmin,
t2.digitsmax,
'S'
from my_codes t1
join my_codes t2
on t1.rownumber <> t2.rownumber
and t1.typ = t2.typ
WHERE t1.mycarr= 73
and t1.typ = 'S'
AND (t2.DigitsMin <= t1.DigitsMin AND t2.DigitsMax > t1.DigitsMin and
t2.DigitsMax < t1.DigitsMax OR
(t2.digitsmin > t1.digitsmin and t2.digitsmax <= t1.digitsmin) OR
(t2.digitsmin >= t1.digitsmin and t2.digitsmax < t1.digitsmax) OR
(t2.digitsmin > t1.digitsmin and t2.digitsmax <= t1.digitsmax) OR
(t2.digitsmin > t1.digitsmin and t2.digitsmin <= t1.digitsmax and
t2.digitsmax > t1.digitsmax));
my_codes
表数据是
mycarr typ rownumber destination digitsmin digitsmax
73 S 1 AAA 8875 8880
73 S 2 AAA1 8870 8880
73 S 3 AAA2 8875 8878
73 S 4 AAA3 8876 8880
如果表有更多数据,则需要花费大量时间。有人可以帮我解决这个问题吗?
I'd written a query to get some overlapping digits range from my_codes table. The query is...
select distinct t1.destination,
t1.digitsmin,
t1.digitsmax,
t2.destination,
t2.digitsmin,
t2.digitsmax,
'S'
from my_codes t1
join my_codes t2
on t1.rownumber <> t2.rownumber
and t1.typ = t2.typ
WHERE t1.mycarr= 73
and t1.typ = 'S'
AND (t2.DigitsMin <= t1.DigitsMin AND t2.DigitsMax > t1.DigitsMin and
t2.DigitsMax < t1.DigitsMax OR
(t2.digitsmin > t1.digitsmin and t2.digitsmax <= t1.digitsmin) OR
(t2.digitsmin >= t1.digitsmin and t2.digitsmax < t1.digitsmax) OR
(t2.digitsmin > t1.digitsmin and t2.digitsmax <= t1.digitsmax) OR
(t2.digitsmin > t1.digitsmin and t2.digitsmin <= t1.digitsmax and
t2.digitsmax > t1.digitsmax));
my_codes
Table data is
mycarr typ rownumber destination digitsmin digitsmax
73 S 1 AAA 8875 8880
73 S 2 AAA1 8870 8880
73 S 3 AAA2 8875 8878
73 S 4 AAA3 8876 8880
If the table has more data its taking lot of time. Could someone help me to resolve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将其简化为这样:
根据您的四个示例行,这将返回 12 行,而不是原始查询返回的 7 行。但是,据我了解,这是正确的,因为每一行都与其他行重叠。
Try to simplify it to just this:
Based upon your four sample rows this would return 12 rows instead of the 7 that your original query returns. But, as I understand it that is correct as each of those rows overlap the others.