X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4CD77D1C97F for ; Tue, 5 Aug 2003 09:40:21 +0000 (GMT) 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 97760-02 for ; Tue, 5 Aug 2003 06:39:05 -0300 (ADT) Received: from lassen.berkeley.edu (lassen.Berkeley.EDU [128.32.25.102]) by svr1.postgresql.org (Postfix) with ESMTP id 0C0FCD1C932 for ; Tue, 5 Aug 2003 06:40:10 -0300 (ADT) Received: from uclink4.berkeley.edu (localhost [127.0.0.1]) by lassen.berkeley.edu (8.12.9/8.12.9) with ESMTP id h759eAIm008680 for ; Tue, 5 Aug 2003 02:40:11 -0700 (PDT) Received: from ara (66-215-20-38.gln-mres.charterpipeline.net [66.215.20.38]) by uclink4.berkeley.edu (8.12.9/8.12.3) with ESMTP id h759e5Ur083791 for ; Tue, 5 Aug 2003 02:40:07 -0700 (PDT) Message-ID: <000501c35b34$9c945660$6401a8c0@charterpipeline.net> Reply-To: "Ara Anjargolian" From: "Ara Anjargolian" To: Subject: query/table design help Date: Tue, 5 Aug 2003 02:33:17 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/53 X-Sequence-Number: 2870 I have a table permissions with the fields (party_id integer, permission varchar, key_name varchar, key_value integer) for which I need to a query to see if a person has permission to carry out a particular action. The query looks like: SELECT 1 FROM permissions WHERE party_id in (4, 7, 11, 26) AND permission = 'permission8' AND ((key_name = 'keyname8' AND key_value = 223) OR (key_name = 'keyname1' AND key_value = 123) OR (key_name = 'keyname5' AND key_value = 212) OR (key_name = 'keyname7' AND key_value = 523) OR (key_name = 'keyname0' AND key_value = 123) OR (key_name = 'keyname10' AND key_value = 400)); would a permissions(party_id, permission) index work best here? or should I index all 4 columns? Also, Another alternative is to combine the key_name and key_value fields into a varchar field key (e. g. 'keyname8=223'), in which case the equilalent query would just check 1 field 6 times instead of having 6 ANDstatements. I expect the table to have about 1 million rows at the most, and I need this query to run as fast as possible since it will be run many, many times. So, from a design standpoint, what is the the best way to go, should I have two fields key_name, and key_value, or just one field key. And how should I index this table best. I guess the fundamental question here is, is it faster to check a varchar(60) field for equality, or to check two check an integer and then a varchar(30). Or does having one varchar field replace an integer and a varchar field, allow for some nice optimization not practical otherwise (i.e a 3-column index). I'd greatly appreciate any insight into this matter. -Ara Anjargolian