[wp-hackers] Permalink Structure - Performance vs. SEO

Mike Schinkel mikeschinkel at newclarity.net
Tue Jun 14 13:32:12 UTC 2011


On Jun 14, 2011, at 8:30 AM, Christopher Ross wrote:
> so in summary, ... the least number of SQL calls are generated by putting the ID first.


NOT TRUE, actually.  Including a ID in your permalink generates the same number of SQL calls, at least in a vanilla WP32 install calling path /2011/05/hello-world/ using the following code in functions.php to monitor:

add_action( 'query', 'wp32_query' );
function wp32_query($query) {
	global $wp32_query_list;
	$wp32_query_list[] = $query;
	return $query;
}
add_action( 'shutdown', 'wp32_shutdown' );
function wp32_shutdown() {
	global $wp32_query_list;
	print_r($wp32_query_list);
}

10 queries are generated of which only #2 differs:

Month and name Permalink: http://example.com/2011/06/sample-post/
============================================
 [2] =>  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND YEAR(wp_posts.post_date)='2011' AND MONTH(wp_posts.post_date)='5' AND wp_posts.post_name = 'hello-world' AND wp_posts.post_type = 'post'  ORDER BY wp_posts.post_date DESC 


Numeric Permalink: http://example.com/archives/123
============================================
 [2] =>  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.ID = 1 AND wp_posts.post_type = 'post'  ORDER BY wp_posts.post_date DESC 


IRONICALLY using the default permalink with just p=%post_id% generates one additional query, see: 

Default Permalink: http://example.com/?p=123
============================================
 [2] => SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules' LIMIT 1
 [3] =>  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.ID = 1 AND wp_posts.post_type = 'post'  ORDER BY wp_posts.post_date DESC 


So the conventional wisdom is wrong.  Instrument before assumption.

<soapbox>
Of course, using a post ID in a URL is anti-user friendly as it means absolutely nothing to a user and, if I had the power, I would banish from all use on the interwebs.
</soapbox>

On Jun 14, 2011, at 9:26 AM, Lynne Pope wrote:
> Unfortunately, the best performance isn't always matched with
> user-friendliness. The best URL's are URL's that are relevant and that
> people can remember. An URL of
> http://example.com/123456789/now-here-comes-the-slug  *might* be search
> engine friendly but it sure isn't human friendly.

+1

-Mike



More information about the wp-hackers mailing list