Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 3A5399FB499 for ; Wed, 18 Jul 2007 18:30:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 78397-06 for ; Wed, 18 Jul 2007 18:30:43 -0300 (ADT) X-Greylist: delayed 00:05:01.161506 by SQLgrey-1.7.5 Received: from luna.ctgameinfo.com (luna.ctgameinfo.com [65.110.52.10]) by postgresql.org (Postfix) with ESMTP id 3BF709FBCEF for ; Wed, 18 Jul 2007 18:30:39 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) (uid 80) by luna.ctgameinfo.com with local; Wed, 18 Jul 2007 14:26:01 -0700 id 00078CA9.469E8569.00011CF2 Received: from 69.31.174.216 (SquirrelMail authenticated user lists@on-track.ca) by webmail.ctgameinfo.com with HTTP; Wed, 18 Jul 2007 14:26:00 -0700 (PDT) Message-ID: <1271.69.31.174.216.1184793960.squirrel@webmail.ctgameinfo.com> Date: Wed, 18 Jul 2007 14:26:00 -0700 (PDT) Subject: Optmal tags design? From: lists@on-track.ca To: pgsql-performance@postgresql.org User-Agent: SquirrelMail/1.4.10a Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) Importance: Normal X-Mime-Autoconverted: from 8bit to 7bit by courier 0.52 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/232 X-Sequence-Number: 25916 I am planning to add a tags (as in the "web 2.0" thing) feature to my web based application. I would like some feedback from the experts here on what the best database design for that would be. The possibilities I have come up with are: * A tags table containing the tag and id number of what it links to. select pid from tags where tag='bla' select tag from tags where pid=xxx. * a tags table where each tag exists only once, and a table with the tag ID and picture ID to link them together. select pid from tags inner join picture_tags using(tag_id) where tag='bla' select tag from tags inner join picture_tags using(tag_id) where pid='xxx' * A full text index in the picture table containing the tags select pid from pictures where tags @@ to_tsquery('bla') (or the non-fti version) select pid from pictures where tags ~* '.*bla.*' select tags from pictures where pid=xxx;