登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

820716的博客-知识分享 向上的心!

知识分享 开阔向上的心胸! http://www.820716.net/blog

 
 
 

日志

 
 

wordpress对于查找不到博文时的处理 效率问题的思考  

2009-09-02 14:59:13|  分类: WordPress WPMU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
 
 
wp-includes/canonical.php
 
/**
 * Attempts to guess correct post based on query vars.
 *
 * @since 2.3.0
 * @uses $wpdb
 *
 * @return bool|string Returns False, if it can't find post, returns correct
 * location on success.
 */
function redirect_guess_404_permalink() {
global $wpdb;
return false; // 关闭此功能
if ( !get_query_var('name') )
return false;
$where = $wpdb->prepare("post_name LIKE %s", get_query_var('name') . '%');
// if any of year, monthnum, or day are set, use them to refine the query
if ( get_query_var('year') )
$where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year'));
if ( get_query_var('monthnum') )
$where .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var('monthnum'));
if ( get_query_var('day') )
$where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day'));
$post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'");
if ( !$post_id )
return false;
return get_permalink($post_id);
}
 
问题 : 大数据量 并发访问量多 时,造成效率低:like查询;YEAR/MONTH/DAYOFMONTH等系统函数的调用使得查询没使用合适的索引(时间索引)
 
mysql> SELECT ID FROM wp_posts WHERE post_name LIKE '%e5%8d%9a%e5%a3%ab%e5%bc%9f%e5%bc%9f%e5%90%ab%e6%b3%aa%e6%84%9f%e6%81%a935%e5%b2%81%e5%93%a5%e5%93%a5%e9%87%8d%e8%af%bb%e9%ab%98%e4%b8%ad%e6%a0%a1%e5%9b%ad-271%' AND YEAR(post_date) = 2008 AND MONTH(post_date) = 3 AND DAYOFMONTH(post_date) = 17 AND post_status = 'publish';
Empty set (1.76 sec)
 
mysql> SELECT ID FROM wp_posts WHERE post_name LIKE '%e5%8d%9a%e5%a3%ab%e5%bc%9f%e5%bc%9f%e5%90%ab%e6%b3%aa%e6%84%9f%e6%81%a935%e5%b2%81%e5%93%a5%e5%93%a5%e9%87%8d%e8%af%bb%e9%ab%98%e4%b8%ad%e6%a0%a1%e5%9b%ad-271%' AND post_date>='2008-03-17' and post_date<'2008-03-18' AND post_status = 'publish';
Empty set (0.00 sec)
  评论这张
 
阅读(523)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018