2011-05-06 17 views
6

निम्न क्वेरी 25 सेकंड 2 टेबल के साथ जुड़ जाता है लेता है। पहली पोस्ट टेबल में 150,00 पंक्तियां हैं, विषयों की तालिका में 50,000 पंक्तियां हैं। कोई भी जानता है कि मैं इसे कैसे गति दे सकता हूं।अनुकूलन चयन क्वेरी और मैच के खिलाफ

SELECT SQL_NO_CACHE 
    post_search.post_id, 
    topic_search.topic_id, 
    topic_search.topic_title, 
    topic_search.topic_last_post_time, 
    MATCH(post_search.post_text,topic_search.topic_title) AGAINST('search_terms' IN BOOLEAN MODE) AS score 
FROM bb_posts_fulltext_search post_search 
LEFT JOIN bb_topics_fulltext_search topic_search 
    ON post_search.topic_id = topic_search.topic_id 
WHERE MATCH(post_search.post_text,topic_search.topic_title) AGAINST('search_terms' IN BOOLEAN MODE) 
GROUP BY topic_search.topic_id 
ORDER BY score DESC 
LIMIT 0,6 

mysql> DESCRIBE bb_posts_fulltext_search; 
+-----------+------------+------+-----+---------+-------+ 
| Field  | Type  | Null | Key | Default | Extra | 
+-----------+------------+------+-----+---------+-------+ 
| post_id | bigint(20) | NO | PRI | NULL |  | 
| post_text | longtext | YES | MUL | NULL |  | 
| topic_id | bigint(20) | YES | MUL | NULL |  | 
+-----------+------------+------+-----+---------+-------+ 

वर्णन वर्णन

mysql> DESCRIBE bb_topics_fulltext_search 
    -> ; 
+----------------------+--------------+------+-----+---------+-------+ 
| Field    | Type   | Null | Key | Default | Extra | 
+----------------------+--------------+------+-----+---------+-------+ 
| topic_id    | int(11)  | NO | PRI | NULL |  | 
| topic_title   | varchar(255) | YES | MUL | NULL |  | 
| topic_posts   | bigint(20) | YES |  | NULL |  | 
| topic_poster_name | varchar(40) | YES |  | NULL |  | 
| topic_last_post_id | bigint(20) | YES |  | NULL |  | 
| forum_id    | int(11)  | YES |  | NULL |  | 
| parent_group_id  | int(11)  | YES |  | NULL |  | 
| child_group_id  | int(11)  | YES |  | NULL |  | 
| topic_last_post_time | datetime  | YES | MUL | NULL |  | 
+----------------------+--------------+------+-----+---------+-------+ 

व्याख्या

+----+-------------+--------------+--------+---------------+---------+---------+----------------------------------+--------+---------------------------------+ 
| id | select_type | table  | type | possible_keys | key  | key_len | ref        | rows | Extra       | 
+----+-------------+--------------+--------+---------------+---------+---------+----------------------------------+--------+---------------------------------+ 
| 1 | SIMPLE  | post_search | ALL | NULL   | NULL | NULL | NULL        | 158972 | Using temporary; Using filesort | 
| 1 | SIMPLE  | topic_search | eq_ref | PRIMARY  | PRIMARY | 4  | wordpress.post_search.topic_id |  1 | Using where      | 
+----+-------------+--------------+--------+---------------+---------+---------+----------------------------------+--------+---------------------------------+ 

अद्यतन: इंडेक्स

+--------------------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 
| Table     | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | 
+--------------------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 
| bb_posts_fulltext_search |   0 | PRIMARY |   1 | post_id  | A   |  158972 |  NULL | NULL |  | BTREE  |   |    | 
| bb_posts_fulltext_search |   1 | topic_id |   1 | topic_id | A   |  52990 |  NULL | NULL | YES | BTREE  |   |    | 
| bb_posts_fulltext_search |   1 | post_text |   1 | post_text | NULL  |   1 |  NULL | NULL | YES | FULLTEXT |   |    | 
+--------------------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 

बनाएँ 1

DROP TABLE IF EXISTS `wordpress`.`bb_posts_fulltext_search`; 
CREATE TABLE `wordpress`.`bb_posts_fulltext_search` (
    `post_id` bigint(20) NOT NULL, 
    `post_text` longtext, 
    `topic_id` bigint(20) DEFAULT NULL, 
    PRIMARY KEY (`post_id`), 
    KEY `topic_id` (`topic_id`), 
    FULLTEXT KEY `post_text` (`post_text`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

बनाएँ 2

DROP TABLE IF EXISTS `wordpress`.`bb_topics_fulltext_search`; 
CREATE TABLE `wordpress`.`bb_topics_fulltext_search` (
    `topic_id` int(11) NOT NULL, 
    `topic_title` varchar(255) DEFAULT NULL, 
    `topic_posts` bigint(20) DEFAULT NULL, 
    `topic_poster_name` varchar(40) DEFAULT NULL, 
    `topic_last_post_id` bigint(20) DEFAULT NULL, 
    `forum_id` int(11) DEFAULT NULL, 
    `parent_group_id` int(11) DEFAULT NULL, 
    `child_group_id` int(11) DEFAULT NULL, 
    `topic_last_post_time` datetime DEFAULT NULL, 
    PRIMARY KEY (`topic_id`), 
    KEY `topic_last_post_time` (`topic_last_post_time`), 
    FULLTEXT KEY `topic_title` (`topic_title`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

समाधान: http://forums.mysql.com/read.php?115,418955,418955#msg-418955

+0

आप बाईं प्रयोग कर रहे हैं में शामिल होने के लिए, वहाँ एक विषय के बिना पोस्ट कर रहे हैं? – piotrm

+0

की प्रतिलिपि प्राप्त अनुक्रमित अपने myisam_key_buffer में फिट है, तो यकीन है कि यह विन्यास चर ठीक से सेट किया गया है चाहिए। इसके अलावा FULLTEXT प्रदर्शन कुख्यात रूप से क्रमी है। मुझे ज़ापियन जैसे वास्तविक खोज इंजन का उपयोग करके अधिक उपयोग करने योग्य परिणाम (जैसे, 1000x तेज) मिला। स्पिंग और ल्यूसीन भी अच्छे प्रतिनिधि हैं। – peufeu

+5

ऐसा लगता है कि आप अपनी समस्या का हल मिल गया। मेरा सुझाव है कि आप इसे का एक सरल व्याख्या लिख, एक जवाब के रूप में पोस्ट, और फिर इसे स्वीकार ताकि हम समस्या का समाधान कैसे का एक रिकॉर्ड है और इसलिए हम इस सवाल का खुला फांसी नहीं है। धन्यवाद। – IAmTimCorey

उत्तर

1

ओपी यहाँ एक जवाब मिल गया है, अगर लिंक गायब हो जाता है, नीचे में पाठ है उस लिंक:

DROP TABLE IF EXISTS `wordpress`.`bb_posts_fulltext_search`; 
CREATE TABLE `wordpress`.`bb_posts_fulltext_search` (
`post_id` int(10) unsigned NOT NULL, 
`post_text` longtext, 
`topic_id` int(10) unsigned NOT NULL DEFAULT '0', 
PRIMARY KEY (`post_id`,`topic_id`) USING BTREE, 
FULLTEXT KEY `post_text` (`post_text`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

DROP TABLE IF EXISTS `wordpress`.`bb_topics_fulltext_search`; 
CREATE TABLE `wordpress`.`bb_topics_fulltext_search` (
`topic_id` int(11) NOT NULL, 
`topic_title` varchar(255) DEFAULT NULL, 
`topic_posts` bigint(20) DEFAULT NULL, 
`topic_poster_name` varchar(40) DEFAULT NULL, 
`topic_last_post_id` bigint(20) DEFAULT NULL, 
`forum_id` int(11) DEFAULT NULL, 
`parent_group_id` int(11) DEFAULT NULL, 
`child_group_id` int(11) DEFAULT NULL, 
`topic_last_post_time` datetime DEFAULT NULL, 
PRIMARY KEY (`topic_id`), 
KEY `topic_last_post_time` (`topic_last_post_time`), 
FULLTEXT KEY `topic_title` (`topic_title`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

SELECT 
    topic_search.topic_id, 
    topic_search.topic_title, 
    topic_search.topic_posts, 
    topic_search.topic_title, 
    topic_search.topic_poster_name, 
    topic_search.topic_last_post_id, 
    topic_search.topic_last_post_time, 
    MATCH(post_search.post_text,topic_search.topic_title) 
    AGAINST('searchterms' IN BOOLEAN MODE) AS score 
FROM bb_posts_fulltext_search as post_search 
LEFT JOIN bb_topics_fulltext_search as topic_search 
    ON post_search.topic_id = topic_search.topic_id 
WHERE 
    MATCH(post_search.post_text,topic_search.topic_title) 
    AGAINST('searchterms' IN BOOLEAN MODE) 
GROUP BY topic_search.topic_id 
ORDER BY score DESC 
LIMIT 0,6 
संबंधित मुद्दे