如何调优以下 Oracle10g 查询?

发布于 2024-12-23 03:42:09 字数 1375 浏览 1 评论 0原文

我编写了一个查询来从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那请放手 2024-12-30 03:42:10

尝试将其简化为这样:

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 t1.digitsmax >= t2.digitsmin
         and t1.digitsmin <= t2.digitsmax;

根据您的四个示例行,这将返回 12 行,而不是原始查询返回的 7 行。但是,据我了解,这是正确的,因为每一行都与其他行重叠。

Try to simplify it to just this:

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 t1.digitsmax >= t2.digitsmin
         and t1.digitsmin <= t2.digitsmax;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文