Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 43C709FB3B1 for ; Fri, 27 Oct 2006 08:46:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 61675-01 for ; Fri, 27 Oct 2006 11:44:49 +0000 (UTC) X-Greylist: delayed 00:32:10.203006 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 43DC49FB440 for ; Fri, 27 Oct 2006 08:44:23 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail.aeccom.com (port-83-236-156-26.static.qsc.de [83.236.156.26]) by svr4.postgresql.org (Postfix) with ESMTP id B95165AF031 for ; Fri, 27 Oct 2006 11:12:10 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.aeccom.com (Postfix) with ESMTP id 2EDD01CCF7; Fri, 27 Oct 2006 13:12:07 +0200 (CEST) Received: from mail.aeccom.com ([127.0.0.1]) by localhost (gate6.aeccom.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 32238-03-29; Fri, 27 Oct 2006 13:12:05 +0200 (CEST) Received: from cayambe.core.aeccom.com (cayambe.core.aeccom.com [192.168.2.120]) by mail.aeccom.com (Postfix) with ESMTP id 596B51CCFC; Fri, 27 Oct 2006 13:11:44 +0200 (CEST) Received: by cayambe.core.aeccom.com (Postfix, from userid 500) id DE9163ECE; Sat, 5 Feb 2005 18:25:52 +0100 (CET) From: Dirk Lutzebaeck To: pgsql-performance@postgresql.org Subject: query produces 1 GB temp file Message-Id: <20061027111142.DE9163ECE@cayambe.core.aeccom.com> Date: Sat, 5 Feb 2005 18:25:52 +0100 (CET) X-Virus-Scanned: amavisd-new at aeccom.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.155 tagged_above=0 required=5 tests=DATE_IN_PAST_96_XX, FORGED_RCVD_HELO X-Spam-Level: ** X-Archive-Number: 200610/574 X-Sequence-Number: 21703 Hi, here is a query which produces over 1G temp file in pgsql_tmp. This is on pgsql 7.4.2, RHEL 3.0, XEON MP machine with 32GB RAM, 300MB sort_mem and 320MB shared_mem. Below is the query and results for EXPLAIN and EXPLAIN ANALYZE. All tables have been analyzed before. Can some please explain why the temp file is so huge? I understand there are a lot of rows. All relevant indices seem to be used. Thanks in advance, Dirk EXPLAIN SELECT DISTINCT ON (ft.val_9, ft.created, ft.flatid) ft.docstart, ft.flatobj, bi.oid, bi.en FROM bi, en, df AS ft, es WHERE bi.rc=130170467 AND bi.en=ft.en AND bi.co=117305223 AND bi.hide=FALSE AND ft.en=en.oid AND es.en=bi.en AND es.co=bi.co AND es.spec=122293729 AND (ft.val_2='DG' OR ft.val_2='SK') AND ft.docstart=1 ORDER BY ft.val_9 ASC, ft.created DESC LIMIT 1000 OFFSET 0; Limit (cost=8346.75..8346.78 rows=3 width=1361) -> Unique (cost=8346.75..8346.78 rows=3 width=1361) -> Sort (cost=8346.75..8346.76 rows=3 width=1361) Sort Key: ft.val_9, ft.created, ft.flatid -> Nested Loop (cost=0.00..8346.73 rows=3 width=1361) -> Nested Loop (cost=0.00..5757.17 rows=17 width=51) -> Nested Loop (cost=0.00..5606.39 rows=30 width=42) -> Index Scan using es_sc_index on es (cost=0.00..847.71 rows=301 width=8) Index Cond: ((spec = 122293729) AND (co = 117305223::oid)) -> Index Scan using bi_env_index on bi (cost=0.00..15.80 rows=1 width=42) Index Cond: ("outer".en = bi.en) Filter: ((rc = 130170467::oid) AND (co = 117305223::oid) AND (hide = false)) -> Index Scan using en_oid_index on en (cost=0.00..5.01 rows=1 width=9) Index Cond: ("outer".en = en.oid) -> Index Scan using df_en on df ft (cost=0.00..151.71 rows=49 width=1322) Index Cond: ("outer".en = ft.en) Filter: (((val_2 = 'DG'::text) OR (val_2 = 'SK'::text)) AND (docstart = 1)) (17 rows) -------------- EXPLAIN ANALYZE gives: Limit (cost=8346.75..8346.78 rows=3 width=1361) (actual time=75357.465..75679.964 rows=1000 loops=1) -> Unique (cost=8346.75..8346.78 rows=3 width=1361) (actual time=75357.459..75675.371 rows=1000 loops=1) -> Sort (cost=8346.75..8346.76 rows=3 width=1361) (actual time=75357.448..75499.263 rows=22439 loops=1) Sort Key: ft.val_9, ft.created, ft.flatid -> Nested Loop (cost=0.00..8346.73 rows=3 width=1361) (actual time=34.104..18016.005 rows=703677 loops=1) -> Nested Loop (cost=0.00..5757.17 rows=17 width=51) (actual time=0.467..3216.342 rows=48563 loops=1) -> Nested Loop (cost=0.00..5606.39 rows=30 width=42) (actual time=0.381..1677.014 rows=48563 loops=1) -> Index Scan using es_sc_index on es (cost=0.00..847.71 rows=301 width=8) (actual time=0.184..46.519 rows=5863 loops=1) Index Cond: ((spec = 122293729) AND (co = 117305223::oid)) -> Index Scan using bi_env_index on bi (cost=0.00..15.80 rows=1 width=42) (actual time=0.052..0.218 rows=8 loops=5863) Index Cond: ("outer".en = bi.en) Filter: ((rc = 130170467::oid) AND (co = 117305223::oid) AND (hide = false)) -> Index Scan using en_oid_index on en (cost=0.00..5.01 rows=1 width=9) (actual time=0.015..0.019 rows=1 loops=48563) Index Cond: ("outer".en = en.oid) -> Index Scan using df_en on df ft (cost=0.00..151.71 rows=49 width=1322) (actual time=0.038..0.148 rows=14 loops=48563) Index Cond: ("outer".en = ft.en) Filter: (((val_2 = 'DG'::text) OR (val_2 = 'SK'::text)) AND (docstart = 1)) Total runtime: 81782.052 ms (18 rows)