Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 7AD5F63344B for ; Thu, 7 Jan 2010 02:11:28 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 58116-07 for ; Thu, 7 Jan 2010 06:11:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from shrek.krogh.cc (2605ds1-ynoe.0.fullrate.dk [90.184.12.24]) by mail.postgresql.org (Postfix) with ESMTP id B8702633431 for ; Thu, 7 Jan 2010 02:11:17 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by shrek.krogh.cc (Postfix) with ESMTP id 259001C5776; Thu, 7 Jan 2010 07:11:11 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at shrek.krogh.cc Received: from shrek.krogh.cc ([127.0.0.1]) by localhost (shrek.krogh.cc [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K+WMzuWl5XH7; Thu, 7 Jan 2010 07:10:34 +0100 (CET) Received: from [90.184.13.137] (unknown [90.184.13.137]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jesper@krogh.cc) by shrek.krogh.cc (Postfix) with ESMTPSA id 164451F021E; Thu, 7 Jan 2010 07:10:25 +0100 (CET) Message-ID: <4B457AD4.8090405@krogh.cc> Date: Thu, 07 Jan 2010 07:10:28 +0100 From: Jesper Krogh User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Ron Mayer CC: pgsql-performance@postgresql.org Subject: Re: Digesting explain analyze References: <4B44E02A.6080109@krogh.cc> <4B44EC89.7060200@cheapcomplexdevices.com> In-Reply-To: <4B44EC89.7060200@cheapcomplexdevices.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.757 tagged_above=-10 required=5 tests=AWL=-0.758, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 201001/73 X-Sequence-Number: 36953 Ron Mayer wrote: >> ...The inner sets are on average 3.000 for >> both id1 and id2 and a typical limit would be 100, so if I could convince >> postgresql to not fetch all of them then I would reduce the set retrieved >> by around 60. The dataset is quite large so the random query is not very >> likely to be hitting the same part of the dataset again, so there is going >> to be a fair amount of going to disk., > > If disk seeks are killing you a kinda crazy idea would be to > duplicate the table - clustering one by (id1) and > the other one by an index on (id2) and unioning the > results of each. That's doubling the disk space needs for the table. Is there any odds that this would benefit when the intitial table significantly exceeds available memory by itself? > Since each of these duplicates of the table will be clustered > by the column you're querying it on, it should just take one > seek in each table. > > Then your query could be something like > > select * from ( > select * from t1 where id1=2067 order by evalue limit 100 > union > select * from t2 where id2=2067 order by evalue limit 100 > ) as foo order by evalue limit 100; This is actually what I ended up with as the best performing query, just still on a single table, because without duplication I can add index and optimize this one by (id1,evalue) and (id2,evalue). It is still getting killed quite a lot by disk IO. So I guess I'm up to: 1) By better disk (I need to get an estimate how large it actually is going to get). 2) Stick with one table, but make sure to have enough activity to get a large part of the index in the OS-cache anyway. (and add more memory if nessesary). The data is seeing a fair amount of growth (doubles in a couple of years ) so it is fairly hard to maintain clustering on them .. I would suspect. Is it possible to get PG to tell me, how many rows that fits in a disk-page. All columns are sitting in "plain" storage according to \d+ on the table. > Hmm.. and I wonder if putting evalue into the criteria to cluster > the tables too (i.e. cluster on id1,evalue) if you could make it > so the limit finds the right 100 evalues first for each table.... I didnt cluster it, since clustering "locks everything". -- Jesper