X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 06E0A9FA293 for ; Tue, 9 May 2006 06:32:32 -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 33127-02 for ; Tue, 9 May 2006 06:32:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (boutiquenumerique.com [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id 80D7B9F931D for ; Tue, 9 May 2006 06:32:25 -0300 (ADT) Received: (qmail 2948 invoked from network); 9 May 2006 11:33:43 +0200 Received: from boutiquenumerique.com (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 9 May 2006 11:33:43 +0200 To: "Christian Kratzer" Cc: "Tom Lane" , pgsql-performance@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: Big IN() clauses etc : feature proposal References: <445F7FF8.6070707@comcast.net> <1147110142.32369.7.camel@archimedes> <20060508175013.GY99570@pervasive.com> <28288.1147111196@sss.pgh.pa.us> <20060509105214.P90693@vesihiisi.cksoft.de> Message-ID: Date: Tue, 09 May 2006 11:33:42 +0200 From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: <20060509105214.P90693@vesihiisi.cksoft.de> User-Agent: Opera M2/8.51 (Linux, build 1462) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/170 X-Sequence-Number: 18957 > You might consider just selecting your primary key or a set of > primary keys to involved relations in your search query. If you > currently use "select *" this can make your result set very large. > > Copying all the result set to the temp. costs you additional IO > that you propably dont need. It is a bit of a catch : I need this information, because the purpose of the query is to retrieve these objects. I can first store the ids, then retrieve the objects, but it's one more query. > Also you might try: > SELECT * FROM somewhere JOIN result USING (id) > Instead of: > SELECT * FROM somewhere WHERE id IN (SELECT id FROM result) Yes you're right in this case ; however the query to retrieve the owners needs to eliminate duplicates, which IN() does. > On the other hand if your search query runs in 10ms it seems to be fast > enough for you to run it multiple times. Theres propably no point in > optimizing anything in such case. I don't think so : - 10 ms is a mean time, sometimes it can take much more time, sometimes it's faster. - Repeating the query might yield different results if records were added or deleted in the meantime. - Complex search queries have imprecise rowcount estimates ; hence the joins that I would add to them will get suboptimal plans. Using a temp table is really the cleanest solution now ; but it's too slow so I reverted to generating big IN() clauses in the application.