<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: WordPress Taxonomies</title>
	<atom:link href="http://murraywoodman.com/355/wordpress-taxonomies/feed/" rel="self" type="application/rss+xml" />
	<link>http://murraywoodman.com/355/wordpress-taxonomies?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-taxonomies</link>
	<description>Homepage and blog</description>
	<lastBuildDate>Wed, 16 May 2012 04:58:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Murray Woodman</title>
		<link>http://murraywoodman.com/355/wordpress-taxonomies/comment-page-1/#comment-25</link>
		<dc:creator>Murray Woodman</dc:creator>
		<pubDate>Wed, 24 Jun 2009 00:32:07 +0000</pubDate>
		<guid isPermaLink="false">http://murraywoodman.com/?p=355#comment-25</guid>
		<description>Not at all. The point you raise is exactly the same one I make above. If you take a look at my mw_term table you see that it is possible to define a title, slug and description for each tag, category, link-category and custom. So it is possible to do what you mention above. The advantage this has over the current WP design is that you are not forcing a single title/slug namespace on the entities. Maybe there is a reason for that but I can&#039;t see it.

mw_term
term_id
subtype (”tag”&#124;”category”&#124;”custom”&#124;”predicate”)
title
slug
description
parent
unique index: subtype + slug</description>
		<content:encoded><![CDATA[<p>Not at all. The point you raise is exactly the same one I make above. If you take a look at my mw_term table you see that it is possible to define a title, slug and description for each tag, category, link-category and custom. So it is possible to do what you mention above. The advantage this has over the current WP design is that you are not forcing a single title/slug namespace on the entities. Maybe there is a reason for that but I can&#8217;t see it.</p>
<p>mw_term<br />
term_id<br />
subtype (”tag”|”category”|”custom”|”predicate”)<br />
title<br />
slug<br />
description<br />
parent<br />
unique index: subtype + slug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anshul</title>
		<link>http://murraywoodman.com/355/wordpress-taxonomies/comment-page-1/#comment-24</link>
		<dc:creator>Anshul</dc:creator>
		<pubDate>Tue, 23 Jun 2009 14:02:30 +0000</pubDate>
		<guid isPermaLink="false">http://murraywoodman.com/?p=355#comment-24</guid>
		<description>Hmmm... there would be another subtle issue.  The wp implementation allows for attaching different descriptions to tag x, link_category x, and post_category x and also put them in different tree structures.  These are worthy goals for a blog that implements pages devoted to a term_taxonomy.  The triple implementation would lose that.</description>
		<content:encoded><![CDATA[<p>Hmmm&#8230; there would be another subtle issue.  The wp implementation allows for attaching different descriptions to tag x, link_category x, and post_category x and also put them in different tree structures.  These are worthy goals for a blog that implements pages devoted to a term_taxonomy.  The triple implementation would lose that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Murray Woodman</title>
		<link>http://murraywoodman.com/355/wordpress-taxonomies/comment-page-1/#comment-21</link>
		<dc:creator>Murray Woodman</dc:creator>
		<pubDate>Tue, 23 Jun 2009 00:51:02 +0000</pubDate>
		<guid isPermaLink="false">http://murraywoodman.com/?p=355#comment-21</guid>
		<description>Good point. My implementation is hamstrung in this case somewhat but it isn&#039;t a big problem.

If I were to start with a clean sheet and design from scratch there would be a super class table (node) which would have properties for name, slug, description and type. The type could be a page, post, tag, custom or comment. If I did that then my joining table could do away with subject_type and object_type. ie. it really is a pure triple with subject_id, predicate and object_id. If I could follow this design then you could easily join across to the subject and object:

select o.name, o.slug, o.description, o.type 
from triple t 
inner join node o on t.object_id = o.node_id
where t.subject_id in (1,2,3,4,5,6,7,8,9)

Unfortunately, we don&#039;t have this luxury as changing the post/page/etc tables for this schema would mean changing IDs, so we can do it. ie. the post and page tables must stay as they are.

So yeah, my current design cannot solve this neatly in one query because we would need to do lots of joins to each of the tables in order to get the data. This would be slow and return a lot of useless data. Not a starter.

However, it is possible to work around this. The basic idea would be to run a simple query on the triple table to get the object types and ids. Then run a query against each of the target tables (page, post, term) to get the names.

Step 1: Query triple
get_objects_for_subject(x):
select t.object_type, t.object_id 
from triple t 
where t.subject_type=&#039;post&#039; and t.subject_id=x

Step 2: Get the names
get_names((type_n, id_n), ...):
select &#039;post&#039;, name, slug, description from post where post_id in (...)
union
select &#039;page&#039;, name, slug, description from page where page_id in (...)
union
select &#039;term&#039;, name, slug, description from term where term_id in (...)

This is not a bad idea because:
- the initial query on triple will be fast since there are no joins. In many cases the recommendation for fast queries on big tables is to avoid joins and to break the query up.
- the name data could well be cached in ram in mysql for post, page and term. Depends on how often these tables are updated.
- each of these union queries should be fast in themselves because they use an index
- the interface for users could still be clean. ie they just call get_names.

To conclude, it is a bit messy but still possible to do it efficiently and cleanly whilst remaining flexible.</description>
		<content:encoded><![CDATA[<p>Good point. My implementation is hamstrung in this case somewhat but it isn&#8217;t a big problem.</p>
<p>If I were to start with a clean sheet and design from scratch there would be a super class table (node) which would have properties for name, slug, description and type. The type could be a page, post, tag, custom or comment. If I did that then my joining table could do away with subject_type and object_type. ie. it really is a pure triple with subject_id, predicate and object_id. If I could follow this design then you could easily join across to the subject and object:</p>
<p>select o.name, o.slug, o.description, o.type<br />
from triple t<br />
inner join node o on t.object_id = o.node_id<br />
where t.subject_id in (1,2,3,4,5,6,7,8,9)</p>
<p>Unfortunately, we don&#8217;t have this luxury as changing the post/page/etc tables for this schema would mean changing IDs, so we can do it. ie. the post and page tables must stay as they are.</p>
<p>So yeah, my current design cannot solve this neatly in one query because we would need to do lots of joins to each of the tables in order to get the data. This would be slow and return a lot of useless data. Not a starter.</p>
<p>However, it is possible to work around this. The basic idea would be to run a simple query on the triple table to get the object types and ids. Then run a query against each of the target tables (page, post, term) to get the names.</p>
<p>Step 1: Query triple<br />
get_objects_for_subject(x):<br />
select t.object_type, t.object_id<br />
from triple t<br />
where t.subject_type=&#8217;post&#8217; and t.subject_id=x</p>
<p>Step 2: Get the names<br />
get_names((type_n, id_n), &#8230;):<br />
select &#8216;post&#8217;, name, slug, description from post where post_id in (&#8230;)<br />
union<br />
select &#8216;page&#8217;, name, slug, description from page where page_id in (&#8230;)<br />
union<br />
select &#8216;term&#8217;, name, slug, description from term where term_id in (&#8230;)</p>
<p>This is not a bad idea because:<br />
- the initial query on triple will be fast since there are no joins. In many cases the recommendation for fast queries on big tables is to avoid joins and to break the query up.<br />
- the name data could well be cached in ram in mysql for post, page and term. Depends on how often these tables are updated.<br />
- each of these union queries should be fast in themselves because they use an index<br />
- the interface for users could still be clean. ie they just call get_names.</p>
<p>To conclude, it is a bit messy but still possible to do it efficiently and cleanly whilst remaining flexible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anshul</title>
		<link>http://murraywoodman.com/355/wordpress-taxonomies/comment-page-1/#comment-17</link>
		<dc:creator>Anshul</dc:creator>
		<pubDate>Mon, 22 Jun 2009 10:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://murraywoodman.com/?p=355#comment-17</guid>
		<description>Interesting.   In a 3 table case a single join query can retrieve all the terms associated to an object. To retrieve all the categories and tags for say 9 posts,  wp 2.8 runs the query:

SELECT t.*, tt.*, tr.object_id 
FROM wp_terms AS t 
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id 
WHERE tt.taxonomy IN (&#039;category&#039;, &#039;post_tag&#039;) AND tr.object_id IN (1,2,3,4,5,6,7,8,9) ORDER BY t.name ASC

Can this be done in a single query with two tables?</description>
		<content:encoded><![CDATA[<p>Interesting.   In a 3 table case a single join query can retrieve all the terms associated to an object. To retrieve all the categories and tags for say 9 posts,  wp 2.8 runs the query:</p>
<p>SELECT t.*, tt.*, tr.object_id<br />
FROM wp_terms AS t<br />
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id<br />
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id<br />
WHERE tt.taxonomy IN (&#8216;category&#8217;, &#8216;post_tag&#8217;) AND tr.object_id IN (1,2,3,4,5,6,7,8,9) ORDER BY t.name ASC</p>
<p>Can this be done in a single query with two tables?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Content Delivery Network via cdn-small.murraywoodman.com

Served from: www.murraywoodman.com @ 2012-05-20 04:37:06 -->
