[Tagdb] Tagging multiple classes of things

Michal Migurski mike at teczno.com
Fri Mar 3 23:28:55 GMT 2006


> Any ideas on how best to implement this kind of system: where one  
> database of tags needs to be shared with several other databases?   
> Maybe the multiple query solution is the only way ... I'd just like  
> to know that before I start architecting.  :)

Two ways that came to mind for me:

1) Denormalize, and get enough information about the linked objects  
into the tags table so you don't need to do any joins at all when  
retrieving summary results. For example, add title and description  
columns to your tags table so you can display brief summaries without  
diving into the other three tables.

2) Return 3x as many columns, e.g.:

	SELECT tags.tag,
		articles.title AS article_title,
		sponsors.title AS sponsor_title,
		products.title AS product_title
	FROM tags
	LEFT JOIN articles ...
	LEFT JOIN sponsors ...
	LEFT JOIN products ...
	...

You'll end up with a lot of NULL values, and a gob of repeats. But  
it's one query, and the results aren't hard to handle. You can also  
generate nested conditionals in the columns portion of the SELECT to  
avoid the repetition.

-mike.

----------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca            http://mike.teczno.com/contact.html





More information about the Tagdb mailing list