我想让这个查询更快

时间:2019-03-18 07:20:54

标签: mysql sql

SELECT 
    `per_in`, `per_out`
FROM
    (SELECT 
        `time`, `per_in`, `per_out`
    FROM
        `10.255.246.186_10113`
    WHERE
        `time` BETWEEN '1551378600' AND '1551724200') AS T1
WHERE
    `per_in` BETWEEN '10.0' AND '20.0'
        OR `per_out` BETWEEN '10.0' AND '20.0'

每个表包含1000万或更多但不少于1000万的数据。

4 个答案:

答案 0 :(得分:1)

请尝试这个。

0    [val1,  val2,  val3]
1    [val4,  val5,  val6]
2           [val7,  val8]

答案 1 :(得分:0)

SELECT time
 , per_in
 , per_out
  FROM `10.255.246.186_10113`
 WHERE time BETWEEN 1551378600 AND 1551724200      
   AND per_in < 20.0
   AND per_out > 10.0

这是一个可怕的表名,是次优设计的症状。

有关更多帮助,请参见Why should I provide an MCVE for what seems to me to be a very simple SQL query?。此外,有关查询性能的问题要求对给定查询进行解释

答案 2 :(得分:-1)

尝试进行查看,然后应用程序

答案 3 :(得分:-1)

此SELECT等效于以下内容:

SELECT `per_in`,`per_out` FROM 
   `10.255.246.186_10113` 
   WHERE (`time` BETWEEN '1551378600' AND '1551724200') 
         AND 
        (
          (`per_in` BETWEEN '10.0' AND '20.0')
          OR 
          (`per_out` BETWEEN '10.0' AND '20.0')
        )