2013-10-15 2 views
-1

J'ai cette requête qui est trop lente. C'est une requête simple pour obtenir tous les sujets d'une table (contient des enregistrements de 1.5m) avec une clause order by. Voici la requête. S'il vous plaît j'ai besoin d'aide pour faire cette requête rapide.Ordre de requête simple par optimisation

SELECT * FROM _sch_forum_topics WHERE _sch_forum_topics.sch_sub_forum_id=4 ORDER BY _sch_forum_topics.topic_last_post_time DESC LIMIT 0,15 

<pre> 
<h1>schema below</h1> 
    <pma_xml_export version="1.0" xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"> 
    <!-- 
    - Structure schemas 
    --> 
    <pma:structure_schemas> 
     <pma:database name="ccruize_database" collation="utf8_general_ci" charset="utf8"> 
      <pma:table name="_sch_forum_topics"> 
       CREATE TABLE `_sch_forum_topics` (
        `topic_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, 
        `forum_id` mediumint(8) unsigned NOT NULL DEFAULT '0', 
        `sch_sub_forum_id` tinyint(3) unsigned NOT NULL, 
        `topic_attachment` tinyint(1) unsigned NOT NULL DEFAULT '0', 
        `topic_approved` tinyint(1) unsigned NOT NULL DEFAULT '1', 
        `topic_reported` tinyint(1) unsigned NOT NULL DEFAULT '0', 
        `topic_title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '', 
        `topic_poster` bigint(20) unsigned NOT NULL DEFAULT '0', 
        `topic_views` mediumint(8) unsigned NOT NULL DEFAULT '0', 
        `topic_replies` mediumint(8) unsigned NOT NULL DEFAULT '0', 
        `unit_id` mediumint(8) NOT NULL, 
        `sch_id` mediumint(8) NOT NULL, 
        `post_text` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, 
        `topic_last_post_id` mediumint(8) unsigned NOT NULL DEFAULT '0', 
        `topic_last_poster_id` mediumint(8) unsigned NOT NULL DEFAULT '0', 
        `topic_last_poster_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', 
        `topic_last_post_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
        `topic_post_time` datetime NOT NULL, 
        `post_edit_count` tinyint(1) NOT NULL, 
        PRIMARY KEY (`topic_id`), 
        KEY `forum_id` (`forum_id`), 
        KEY `topic_approved` (`topic_approved`), 
        KEY `topic_reported` (`topic_reported`), 
        KEY `unit_id` (`unit_id`), 
        KEY `sch_id` (`sch_id`), 
        KEY `topic_post_time` (`topic_post_time`), 
        KEY `topic` (`topic_poster`,`sch_sub_forum_id`,`topic_last_post_time`) 
       ) ENGINE=InnoDB AUTO_INCREMENT=1277968 DEFAULT CHARSET=utf8; 
      </pma:table> 
     </pma:database> 
    </pma:structure_schemas> 
</pma_xml_export> 
</pre> 

Répondre

0

Vous pouvez mettre un index sur le champ _sch_forum_topics.topic_last_post_time

Ou vous pouvez trier à l'aide d'un algorithme de tri personnalisé dans l'arrière-plan de votre application