0

下面的查询大约需要 6-7 秒。我希望在不到 1 秒的时间内得到结果。我该怎么办。find_in_set 中使用的索引 catsid 列会有所帮助吗?

**EXPLAIN SELECT** sp_events.id,sp_events.id as speventId,
event.id as eventId,event.cityid as city_id,city.name as cityname,
event.title as event_name,event.title as eventName,
UNIX_TIMESTAMP(sp_events.dates) as sphinx_date,
sp_events.dates as sphinx_start_date,
UNIX_TIMESTAMP(sp_events.enddates) as sphinx_enddate,
sp_events.enddates as
sphinx_end_date,
UNIX_TIMESTAMP(event.dates) as date,event.dates as start_date,
UNIX_TIMESTAMP(event.enddates) as enddate,
event.enddates as end_date,
UNIX_TIMESTAMP(event.times) as times,
event.times as start_time,
TIME_TO_SEC(event.times) as sorttime,
TIME_TO_SEC(event.times) as startTime,
UNIX_TIMESTAMP(event.endtimes) as endtimes,
event.endtimes as end_time,event.booking_url,
event.image_low,event.preferred_image,
event.multiple_booking,event.recurrence_type,
event.recurrence_days,event.recurrence_times,
event.recurrence_endtimes,event.partner_url,event.partner_url_cc,
event.catsid as catsid,event.catsid as event_cat_id,
event.artist_id as aid,event.artist_id as artist_id,event.price,
event.partner,event.partner as eventpartner,
content.title as venue_name,content.title as venueName,
content.id as venueId,contact.latitude as lat,
contact.longitude as lon,RADIANS(contact.latitude) as lat1,
RADIANS(contact.longitude) as lon1,contact.city as venuecity,
city.countryid as country_id,event.image_high,
sd.stateCode 
**FROM** jos_sphinx_events as sp_events **LEFT JOIN** 
jos_eventlist_events as event ON sp_events.eventid = event.id **LEFT join** 
jos_content as content on content.id=event.locid **LEFT JOIN** 
jos_contact_details as contact ON content.id=contact.id **LEFT JOIN** 
jos_city_details as city on city.id=event.cityid **LEFT JOIN** 
jos_state_details as sd ON sd.id= city.stateid 
**WHERE** event.published='1'
      AND  event.enddates>=DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY)
      and  content.state='1'
      AND  city.published='1'
      AND  sp_events.eventid IN (
        SELECT  eventid
            FROM  jos_sphinx_events
            WHERE  (FIND_IN_SET(911,catsid)
                      OR  FIND_IN_SET(630,catsid)
                      OR  FIND_IN_SET(631,catsid)
                      OR  FIND_IN_SET(632,catsid)
                      OR  FIND_IN_SET(633,catsid)
                      OR  FIND_IN_SET(634,catsid)
                      OR  FIND_IN_SET(635,catsid)
                      OR  FIND_IN_SET(636,catsid)
                      OR  FIND_IN_SET(637,catsid)
                      OR  FIND_IN_SET(638,catsid)
                      OR  FIND_IN_SET(639,catsid)
                      OR  FIND_IN_SET(640,catsid)
                      OR  FIND_IN_SET(641,catsid)
                      OR  FIND_IN_SET(642,catsid)
                      OR  FIND_IN_SET(661,catsid)
                      OR  FIND_IN_SET(662,catsid)
                      OR  FIND_IN_SET(663,catsid)
                      OR  FIND_IN_SET(664,catsid)
                      OR  FIND_IN_SET(711,catsid)
                   )
              and  published='1'
              AND  enddates>=DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY)
              AND  enddates<=DATE_ADD(CURRENT_DATE(),INTERVAL 2 YEAR)
                          )
    limit  5

上述查询的解释结果如下: 上述查询的解释结果如下:

4

1 回答 1

0

将 更改IN ( SELECT ... )JOIN. 这可能会大大提高性能。

通常最好在表格中“设置”类似的东西,而不是在列中的 commalist 中。

该综合指数可能会有所帮助:

INDEX(published, enddates)

请在子查询中的字段上添加表别名限定——我不知道为什么它是“DEPENDENT”。分析可能会导致其他建议。

请提供SHOW CREATE TABLE每张桌子;还有一些可能会浮出水面的建议。

于 2015-05-11T16:40:29.157 回答