【发布时间】:2016-03-20 07:49:27
【问题描述】:
我有以下 MySQL 查询:
$sql = "SELECT (SELECT COUNT(share_id) FROM pd_shares WHERE section = 'news' AND item_id = news.article_id) AS count_shares, article_id, link, title, publish_date, description, source FROM pd_news AS news WHERE (MATCH (title_ascii, description_ascii) AGAINST ('".match_against($_GET["sn"])."' IN BOOLEAN MODE)) AND article_id > " . $last_index . " ORDER BY article_id ASC LIMIT 0,$limit";
当我进行搜索时,使用 ORDER BY 子句的查询加载了 513.24 毫秒。当我删除它时,它运行 77.12 毫秒。
title_ascii 和 description_ascii 都是 FULLTEXT。
如何重写此查询,以使运行速度比当前加载速度快得多?
解释输出:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY news fulltext PRIMARY,news_search news_search 0 NULL 1 Using where; Using filesort
2 DEPENDENT SUBQUERY pd_shares ref section section 19 const,my_database.news.article_id 2 Using index condition
【问题讨论】:
-
你能发布你的解释输出吗?
-
您的 EXPLAIN 输出告诉我们查询应该非常快,因为它只处理几行。你会在实际数据集上调用 EXPLAIN 吗?
标签: mysql sql sql-order-by match-against