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 E1AA1D1C932 for ; Tue, 5 Aug 2003 09:56:11 +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 95614-09 for ; Tue, 5 Aug 2003 06:54:55 -0300 (ADT) Received: from smtp.pspl.co.in (unknown [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 12CCED1CA01 for ; Tue, 5 Aug 2003 06:56:00 -0300 (ADT) Received: (from root@localhost) by smtp.pspl.co.in (8.12.9/8.12.9) id h759uEfZ031662 for ; Tue, 5 Aug 2003 15:26:14 +0530 Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in [192.168.7.161]) (authenticated bits=0) by persistent.co.in (8.12.9/8.12.9) with ESMTP id h759uDip031636; Tue, 5 Aug 2003 15:26:13 +0530 From: Shridhar Daithankar To: "Ara Anjargolian" Subject: Re: query/table design help Date: Tue, 5 Aug 2003 15:27:50 +0530 User-Agent: KMail/1.5.2 References: <000501c35b34$9c945660$6401a8c0@charterpipeline.net> In-Reply-To: <000501c35b34$9c945660$6401a8c0@charterpipeline.net> Cc: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308051527.50790.shridhar_daithankar@nospam.persistent.co.in> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/54 X-Sequence-Number: 2871 On Tuesday 05 August 2003 15:03, Ara Anjargolian wrote: > 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. I would suggest a 3 column table with party id, action and permission. Index on partyid and action. If table is static enough clustering should help. But this is one of many possible ways to design it. There could be other details that can affect this decision. Shridhar