Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 6ED6B64FE47 for ; Tue, 2 Dec 2008 09:47:40 -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 97600-06 for ; Tue, 2 Dec 2008 09:47:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 42.mail-out.ovh.net (42.mail-out.ovh.net [213.251.189.42]) by mail.postgresql.org (Postfix) with SMTP id 4EDF764FE01 for ; Tue, 2 Dec 2008 09:47:35 -0400 (AST) Received: (qmail 4295 invoked by uid 503); 2 Dec 2008 13:47:15 -0000 Received: from b6.ovh.net (HELO mail412.ha.ovh.net) (213.186.33.56) by 42.mail-out.ovh.net with SMTP; 2 Dec 2008 13:47:15 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 2 Dec 2008 13:47:33 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO soyouz) (88.161.102.87) by ns0.ovh.net with SMTP; 2 Dec 2008 13:47:31 -0000 Date: Tue, 02 Dec 2008 14:48:36 +0100 To: Andrus , pgsql-performance@postgresql.org Subject: Re: analyzing intermediate query From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/9.62 (Linux) X-Ovh-Tracer-Id: 4355825264677291654 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|H 0.5/N 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/10 X-Sequence-Number: 32046 > I noticed that query > > SELECT dok.* > FROM dok > JOIN (SELECT DISTINCT dokumnr FROM temptbl ) x USING(dokumnr); > > is slow in 8.1.4 > I cannot use explain analyze since this query uses results from > temporary table temptbl which is not available. 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 (...) Of course you must be pretty damn sure that the list isn't gonna contain 10 million items. Or else you'll have a little problem. But it generally works pretty well. The overhead of generating and parsing the IN() is lower than the overhead of temptables... By the way, sometime ago there was talk about adding estimation of number of rows returned to set-returning functions. What's the status of this ? It doesn't seem to have survived... 8.3> EXPLAIN SELECT * FROM generate_series( 1,10 ); QUERY PLAN ------------------------------------------------------------------------ Function Scan on generate_series (cost=0.00..12.50 rows=1000 width=4) > Sometimes innter table returns only 1 row so maybe seq scan is selected > instead of single row index access becauses expected count is 1000 > > As I understand, PostgreSql requires manually running ANALYZE for > temporary tables if their row count is different from 1000 > > How to force PostgreSql to analyze inner table in this query or use > other way to get index using query plan if inner query returns single > row ? > > How