mysql - memcache 会帮助处理昂贵的 MySQL 查询吗? (Drupal 站点)

标签 mysql drupal memcached

这是一个简单的问题。我们网站上的一些查询需要很长时间才能完成(例如 15 秒!)。对于匿名流量,他们会得到一个缓存的 .html 文件,但对于登录用户来说,速度太慢了。

查询看起来像这样:

SELECT node.nid, votingapi_cache_vote_percent_average.value AS votingapi_cache_vote_percent_average_value, votingapi_cache_vote_percent_count.value AS votingapi_cache_vote_percent_count_value, node.type AS node_type, users.name AS users_name, users.uid AS users_uid, node_data_field_species.field_species_nid AS node_data_field_species_field_species_nid, node.title AS node_title, node.changed AS node_changed, node.created AS node_created, node_data_field_picture.field_picture_fid AS node_data_field_picture_field_picture_fid, node_data_field_picture.field_picture_title AS node_data_field_picture_field_picture_title, node_data_field_picture.field_picture_alt AS node_data_field_picture_field_picture_alt, node_data_field_recorded.field_recorded_value AS node_data_field_recorded_field_recorded_value, node_data_field_static_location.field_static_location_value AS node_data_field_static_location_field_static_location_value, field_video_op_videos.video_id AS field_video_op_videos_preview_image_link FROM node node LEFT JOIN votingapi_cache votingapi_cache_vote_percent_average ON node.nid = votingapi_cache_vote_percent_average.content_id AND votingapi_cache_vote_percent_average.content_type = 'node' AND votingapi_cache_vote_percent_average.value_type = 'percent' AND votingapi_cache_vote_percent_average.tag = 'vote' AND votingapi_cache_vote_percent_average.function = 'average' LEFT JOIN votingapi_cache votingapi_cache_vote_percent_count ON node.nid = votingapi_cache_vote_percent_count.content_id AND votingapi_cache_vote_percent_count.content_type = 'node' AND votingapi_cache_vote_percent_count.value_type = 'percent' AND votingapi_cache_vote_percent_count.tag = 'vote' AND votingapi_cache_vote_percent_count.function = 'count' INNER JOIN users users ON node.uid = users.uid LEFT JOIN content_field_species node_data_field_species ON node.vid = node_data_field_species.vid LEFT JOIN content_type_picture node_data_field_picture ON node.vid = node_data_field_picture.vid LEFT JOIN content_field_recorded node_data_field_recorded ON node.vid = node_data_field_recorded.vid LEFT JOIN content_field_static_location node_data_field_static_location ON node.vid = node_data_field_static_location.vid LEFT JOIN content_type_video node_data_field_video ON node.vid = node_data_field_video.vid LEFT JOIN op_videos field_video_op_videos ON node_data_field_video.field_video_video_id = field_video_op_videos.video_id WHERE (node.type IN ('audio','picture','video')) AND (node.status = '1') ORDER BY votingapi_cache_vote_percent_average_value DESC, votingapi_cache_vote_percent_count_value DESC LIMIT 0, 30

内存缓存是否有助于更快地为该页面提供服务?或者,至少,第二次访问它...

谢谢

最佳答案

昂贵的查询应该以一种或另一种方式进行缓存。您发布的查询不依赖于登录的用户,因此应该被缓存。

您是否尝试过在管理员中打开主动缓存,这可能会有所帮助(但可能会在其他地方伤害您)。

如果查询是从 block 中运行的,请确保 block 缓存已打开并且适合查询(这将是 BLOCK_CACHE_GLOBAL)。

最坏的情况是您应该考虑为夹点构建自己的缓存。只能作为最后的手段。

更新:我猜您正在使用 View 生成页面。我看过here看起来最新的 views2 和 views3 内置了一些缓存,如果你升级你也许可以使用它。

关于mysql - memcache 会帮助处理昂贵的 MySQL 查询吗? (Drupal 站点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1675008/

相关文章:

php - Drupal 站点不正常 - 消除过程

drupal - ubercart 中的产品有多种价格吗?

google-app-engine - NDB 的 GAE Memcache 使用率似乎很低

php - facebook如何实现写入可扩展性?

php - 这个带有 NOT LIKE 语句的 SQL 查询有什么问题?

mysql - 从 SQL 中的每一行的 2 列计算 AVERAGE

mysql - 将项目部署到Tomcat后找不到com.mysql.jdbc.Driver

php - 在存储到 mysql 数据库之前压缩文本

php - Drupal 表单 API 和 $form_state ['storage' ] 在页面刷新时被销毁

在 Memcached 中缓存图像