gpt4 book ai didi

php - 有什么办法可以优化这个mysql查询吗?

转载 作者:行者123 更新时间:2023-11-29 15:09:55 24 4
gpt4 key购买 nike

这是查询。我最感兴趣的是是否有更好的方法来获取我使用 GROUP_CONCAT 的内容,或者这是获取这些数据的好方法。然后我将其分解,并将 ids/name 放入一个数组中,然后使用 for 循环将它们回显。

SELECT 
mov_id,
mov_title,
GROUP_CONCAT(DISTINCT categories.cat_name) as all_genres,
GROUP_CONCAT(DISTINCT cat_id) as all_genres_ids,
GROUP_CONCAT(DISTINCT case when gen_dominant = 1 then gen_catid else 0 end) as dominant_genre_ids,
GROUP_CONCAT(DISTINCT actors.act_name) as all_actors,
GROUP_CONCAT(DISTINCT actors.act_id) as all_actor_ids,
mov_desc,
mov_added,
mov_thumb,
mov_hits,
mov_numvotes,
mov_totalvote,
mov_imdb,
mov_release,
mov_html,
mov_type,
mov_buytickets,
ep_summary,
ep_airdate,
ep_id,
ep_hits,
ep_totalNs,
ep_totalRs,
mov_rating,
mov_rating_reason,
mrate_name,
dir_id,
dir_name
FROM movies
LEFT JOIN _genres
ON movies.mov_id = _genres.gen_movieid
LEFT JOIN categories
ON _genres.gen_catid = categories.cat_id
LEFT JOIN _actors
ON (movies.mov_id = _actors.ac_movid)
LEFT JOIN actors
ON (_actors.ac_actorid = actors.act_id AND act_famous = 1)
LEFT JOIN directors
ON movies.mov_director = directors.dir_id
LEFT JOIN movie_ratings
ON movies.mov_rating = movie_ratings.mrate_id
LEFT JOIN episodes
ON mov_id = ep_showid AND ep_season = 0 AND ep_num = 0
WHERE mov_id = *MOVIE_ID* AND mov_status = 1
GROUP BY mov_id

查询的解释在这里

alt text http://www.krayvee.com/o2/explain.gif

最佳答案

就我个人而言,我会尝试将查询分解为多个查询。大多数情况下,我建议删除 Actor 和 Genre Joins,以便您可以摆脱所有这些 group_concat 函数。然后执行单独的查询来提取这些数据。不确定它是否会加快速度,但可能值得一试。

关于php - 有什么办法可以优化这个mysql查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1041847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com