X-Original-To: pgsql-general-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F18B99FB24E for ; Thu, 3 Aug 2006 07:30:37 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 93106-03 for ; Thu, 3 Aug 2006 07:30:31 -0300 (ADT) X-Greylist: delayed 00:33:12.14252 by SQLgrey- Received: from 1006.org (unknown [62.146.87.34]) by postgresql.org (Postfix) with ESMTP id 352449FB220 for ; Thu, 3 Aug 2006 07:30:33 -0300 (ADT) Received: from dell.home.lan (host135-17.pool874.interbusiness.it [87.4.17.135]) (authenticated (0 bits)) by my.endian.it (8.11.6/8.11.6) with ESMTP id k73A4cT07908; Thu, 3 Aug 2006 12:04:38 +0200 Subject: Re: Query performance From: Chris Mair To: Christian Rengstl Cc: pgsql-general@postgresql.org In-Reply-To: <44D1CC21.0AD0.0080.0@klinik.uni-regensburg.de> References: <44D1CC21.0AD0.0080.0@klinik.uni-regensburg.de> Content-Type: text/plain Date: Thu, 03 Aug 2006 11:57:06 +0200 Message-Id: <1154599026.5794.2.camel@dell.home.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27) Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200608/157 X-Sequence-Number: 98929 > i have a table with around 57 million tuples, with the following columns: pid(varchar), crit(varchar), val1(varchar), val2(varchar). Example: > pid crit val1 val2 > p1 c1 x y > p1 c2 x z > p1 c3 y x > ... > What i am doing is to query all val1 and val2 for one pid and all crit values: > > select val1, val2, crit from mytable where pid='somepid' and crit in(select crit from myCritTable); > where myCritTable is a table that contains all crit values (around 42.000) ordered by their insertion date. In case myCritTable doesn't change a lot and this select by contrast is executed a lot, have you considered precomputing whether a record from your big table has a crit value from myCritTable? Of course this info would be invalidated each time myCritTable is updated, so you would trade fast selects on the big table vs. slow updates on myCritTable. Don't know wether that makes sence for you... Bye, Chris.