簡體   English   中英

mysql大量行查詢

[英]mysql large number of rows query

我有以下mysql查詢:

EXPLAIN
  SELECT
     id,
     name,
     title,
     description,
     time
  FROM entity
  WHERE 
    (date_end > CURRENT_DATE 
       OR (date_end = CURRENT_DATE AND time_end >= CURRENT_TIME)
     )
     AND (next_date < CURRENT_DATE 
        OR (next_date = CURRENT_DATE AND next_time <= CURRENT_TIME)
     )

處理表中的10000+行時,何時可以使此查詢花費更少的時間?

顯示/分析解釋計划將有助於更多答案。

盡管我猜想在[date_end, time_end][next_date,next_time]上添加復合索引可能會有所幫助

如果可能,將date_end和time_end列合並為單個datetime_end列,對於next_date和next_time列,將其類似地作為next_datetime,並在datetime_end,next_datetime上建立索引。 然后,您可以將查詢重寫為:

  SELECT id, name, title, description, time
  FROM entity
  WHERE datetime_end >= now() and next_datetime <= now()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM