简体   繁体   English

mysql-orderby和左外部联接问题

[英]mysql - orderby and left outer join issue

When I use left outer join with order by in the below query the query executes infinitely without giving a resultset. 当我在下面的查询中将左外部联接与order by一起使用时,查询将无限执行而没有给出结果集。 However - individually they work fine that is if I change it from left outer join to inner join. 但是,如果我将其从左外部联接更改为内部联接,则它们各自工作正常。 But I need all the values from interregen table below. 但我需要下面的interregen表中的所有值。

Not understanding what could possibly be the error :( 不明白可能是什么错误:(

My mysql query: 我的mysql查询:

   SELECT r.name, 
          r.network, 
          r.namestring, 
          i.name, 
          i.description, 
          r.rid,   
          i.id, 
          d.dtime,
          d.ifInOctets, 
          d.ifOutOctets, 
          FROM_UNIXTIME(d.dtime)
     FROM range AS r 
     JOIN interregen AS i ON r.rid = i.rid  
LEFT JOIN 1278993600_1_60 AS d ON i.id = d.id  -- i.id is the primary key
                              AND dtime BETWEEN 1279026000 AND 1279040400 
    WHERE r.net = 'ITPN'
      AND i.status = 'active' 
 ORDER BY i.id, d.dtime

Please help!! 请帮忙!! Thanks 谢谢

It is probable that your problem is there are a very large number of rows in your interregen table that do not have a matching entry in table 1278993600_1_60. 可能是您的问题是在interregen表中有很多行,而表1278993600_1_60中没有匹配的条目。 So the problem with the left outer join is that the query is trying to get a very much larger result set than with the inner join. 因此,左外部联接的问题在于查询试图获得比内部联接大得多的结果集。 It probably will return, eventually, but depending on the number of rows, it could take awhile. 它最终可能会返回,但是取决于行数,可能需要一段时间。

Another look at the query and you might be able to improve performance if you move this: 再看一下查询,如果移动此命令,可能会提高性能:

AND dtime BETWEEN 1279026000 AND  1279040400

to somewhere AFTER the WHERE. 到之后的某个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM