下面两条sql语句
,我测试了一下,怎么上面一条查询还要比下面的查询速度更快一些呢?上面的语句明明多了一个keywords条件啊? if($g_keywords)
{
$result_content = $db->query_once("select id,title,content from content,content_1 where id=fid and p_already=0 and k_already=1 and keywords='{$keywords}'");
}
else
{
$result_content = $db->query_once("select id,title,content from content,content_1 where id=fid and p_already=0 and k_already=1");
}

解决方案 »

  1.   

            explain select id,title,content 
            from content,content_1 
            where id=fid 
            and p_already=0 
            and k_already=1 
            and keywords='{$keywords}';
            explain select id,title,content 
            from content,content_1 
            where id=fid 
            and p_already=0 
            and k_already=1;用上面语句EXPLAIN一下,
    然后
    show index from content;
    show index from content_1;估计你有一个基于 keywords 的索引,而这个索引的不重复记录很多
      

  2.   


    explain SQL语句
    跟踪下看看就明白多了