X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id A003FD1B8D2 for ; Tue, 26 Aug 2003 14:31:20 -0300 (ADT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 73043-02 for ; Tue, 26 Aug 2003 14:30:49 -0300 (ADT) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by svr1.postgresql.org (Postfix) with ESMTP id 2F369D1B897 for ; Tue, 26 Aug 2003 14:30:33 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 19rheK-0006o2-0U for pgsql-sql@postgresql.org; Tue, 26 Aug 2003 18:30:33 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 4C7991595F for ; Tue, 26 Aug 2003 18:30:31 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id B559B15917 for ; Tue, 26 Aug 2003 18:30:30 +0100 (BST) From: Richard Huxton To: pgsql-sql@postgresql.org Subject: Eliminating duplicate lists Date: Tue, 26 Aug 2003 18:30:31 +0100 User-Agent: KMail/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308261830.31192.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/308 X-Sequence-Number: 14924 TIA all... Four tables: content: content_id, content_name, ... content_features: content_id, feature_id device_features: device_id, feature_id device: device_id, device_name, ... One item of content can run on many devices, providing all the required features in "content_features" correspond to those in "device_features". One device can run many content items. Now - I have functions to return compatibility for a single piece of content, but I also need to build static compatibility lists, something of the form: content_compat: content_id, compat_list_id compat_list_info: compat_list_id, compat_list_name, ... compat_list: compat_list_id, device_id What I don't want are any duplicate lists. By which, I mean if list "A" contains devices 1,2,3 then there should be no list "B" which contains 1,2,3 (and no others). Of course, new content items and devices are added regularly and shouldn't require rebuilding the entire table (just to make life interesting). Solution 1 Introduce a "compat_uniq_code" into table "compat_list_info". This would be composed of all the features supported by this list, built via plpgsql, something of the form "content-type:7:8:9" for features 7,8,9. I can then use this as a key and checking for duplicates is easy. Note that the feature ids will have to be sorted. Solution 2 Have a temporary table - build each list there and then join against compat_list and make sure that for any given compat_list_id there are either: 1. items in temp_compat_list but not in compat_list 2. items in compat_list but not in compat_list You could avoid the temporary table with a temporary compat_list_id and a self-join on the compat_list table. Solution 1 is a somewhat ugly procedural hack, and 2 isn't going to be a simple query and is probably going to be slow. Anyone got any better ideas? -- Richard Huxton Archonet Ltd