Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 56D6264FE2D for ; Tue, 2 Dec 2008 10:01:17 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 02179-05 for ; Tue, 2 Dec 2008 10:01:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp-out.neti.ee (smtp-out.neti.ee [194.126.126.44]) by mail.postgresql.org (Postfix) with ESMTP id 5B18D64FE2B for ; Tue, 2 Dec 2008 10:01:10 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by MXR-5.estpak.ee (Postfix) with ESMTP id 261601DFA2A; Tue, 2 Dec 2008 16:01:04 +0200 (EET) X-Virus-Scanned: Debian amavisd-new at estpak.ee Received: from smtp-out.neti.ee ([127.0.0.1]) by localhost (MXR-5.estpak.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kM+II4EF3ANc; Tue, 2 Dec 2008 16:01:02 +0200 (EET) Received: from Relayhost1.neti.ee (Relayhost1 [88.196.174.141]) by MXR-5.estpak.ee (Postfix) with ESMTP id 7C61A1DF94B; Tue, 2 Dec 2008 16:01:02 +0200 (EET) X-SMTP-Auth-NETI-Businesmail: no Received: from andrusnotebook (unknown [195.50.198.194]) by Relayhost1.neti.ee (Postfix) with SMTP id 3B0AE2A5E8F; Tue, 2 Dec 2008 16:01:01 +0200 (EET) Message-ID: From: "Andrus" To: , "PFC" References: In-Reply-To: Subject: Re: analyzing intermediate query Date: Tue, 2 Dec 2008 16:00:48 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="utf-8"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/11 X-Sequence-Number: 32047 > Generally if you know your temptbl will always contains a few rows (say, > generally a few and never more than a few thousands) it is better to use > something like that : > > - get list of items > - SELECT * FROM table WHERE id IN (...) My list can contain 1 .. 100000 records and table contains 3000000 records and is growing. As discussed here few time ago, IN (...) forces seq scan over 3000000 rows and maybe stack overflow exception also occurs (stack overflow occurs in 8.0, maybe it is fixed in 8.1). Using temp table + ANALYZE enables bitmap index scan for this query and is thus a lot faster. I formerly used IN (...) but changed this to use temp table + primary key on temp table + analyze this temp table. Using 8.1.4 I can switch this to temp table also if it helps. This requires some special logic to generate temp table name since there may be a number of such tables in single transaction, so is would be major appl rewrite. Andrus.