0

OR、AND 句を使用してクエリを改善するにはどうすればよいですか?

explain 
       select fileds 
       from table_name 
       where (fldlp>='2012-09-15 13:00:34' and fldlp<='2012-09-16 06:00:02') 
    or (flexp>='2012-09-15 13:00:34' and flexp<='2012-09-16 06:00:02');

+----+-------------+------------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table      | type | possible_keys | key  | key_len | ref  | rows    | Extra       |
+----+-------------+------------+------+---------------+------+---------+------+---------+-------------+
|  1 | SIMPLE      | table_name | ALL  | NULL          | NULL | NULL    | NULL | 2928790 | Using where | 
+----+-------------+------------+------+---------------+------+---------+------+---------+-------------+
4

2 に答える 2

4

BETWEEN句を使用できます。

WHERE (fldlp BETWEEN '2012-09-15 13:00:34' AND '2012-09-16 06:00:02') 
   OR (flexp BETWEEN '2012-09-15 13:00:34' AND '2012-09-16 06:00:02');
于 2012-09-18T10:37:57.367 に答える
4

改善するためのヒント

  • とに索引をfldlp作成flexp

  • 上記の列の dataType はdateTimeにする必要があります

于 2012-09-18T10:41:45.490 に答える