简体   繁体   English

我在MySQL上执行的查询需要超过51个小时才能完成

[英]A query I'm doing on MySQL takes over 51 hours to complete

The structure of the query is as follows: 查询的结构如下:

SELECT DISTINCT field from table where (param1 IS NULL OR param1=CURDATE()) and (param2 IS NULL or param2=CURDATE())

There are no indexes on param1 or param2. 在param1或param2上没有索引。 We have a lot of data, and I want to have a cron job run a script that runs this query on a daily basis. 我们有很多数据,我想让cron作业运行一个脚本,该脚本每天运行一次此查询。

Suggestions? 有什么建议吗? Should I somehow split this into multiple smaller queries? 我应该以某种方式将其拆分为多个较小的查询吗?

EDIT: I'm expecting around 10 million results. 编辑:我预计会有1000万个结果。

Adding this index is likely to help: 添加此索引可能会有所帮助:

INDEX(param1, param2, field)

(It would help to know the size of the table, the schema, etc) (这将有助于了解表,模式等的大小)

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

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