Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 1E4ED133655C for ; Tue, 15 Feb 2011 18:05:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 18600-02 for ; Tue, 15 Feb 2011 22:05:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 6EF3F133616B for ; Tue, 15 Feb 2011 18:05:06 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PpT16-0000Yi-JK for pgsql-sql@postgresql.org; Tue, 15 Feb 2011 23:05:04 +0100 Received: from frigga.summersault.com ([12.161.105.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 15 Feb 2011 23:05:04 +0100 Received: from mark by frigga.summersault.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 15 Feb 2011 23:05:04 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Mark Stosberg Subject: recommended data model for a search? Date: Tue, 15 Feb 2011 17:04:52 -0500 Lines: 35 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: frigga.summersault.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 X-Enigmail-Version: 1.1.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/70 X-Sequence-Number: 35146 We have an application that manages RSS feeds for searches. Our first attempt at modeling this was to create a table for the searches with the standard integer primary key generated from a sequence, and then have one column per search key. Each row should represent a unique search. When a new search comes we need to look up the key/value pairs received and find the unique search ID that corresponds to it. ( IE, we need to know whether we have an "insert" case or an "update" case, without the benefit of being provided the primary key for the update case. ) The problem with this design is that there are 13 potential search terms, and the "unique" index we would like to create to avoid duplicates and speed-up searches would necessarily span all 13 columns. And further complicating the matter is the handling of nulls, which need to be considered as part of the unique signature of a search, but are not easily indexed that way. Having gotten this far, I'm taking a step back to consider if there's a better way to design this. Perhaps there's a standard solution for this, but I'm not sure where to find it. Here's one idea I've had for a refined design: Each search can be represented as a unique, sorted query string. It would be easy for the application to compute this and then make an MD5-hash of it (or similar). The MD5-hash would then be used as the unique key instead of a standard integer. This would then be easily indexable for quick look-ups, and would allow us to create a unique index that doesn't have a problem with null values, too. Is this a reasonable approach, or is there a better design I'm overlooking? Thanks, Mark