Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D94971337B8C for ; Tue, 11 Jan 2011 11:53:32 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 24951-10 for ; Tue, 11 Jan 2011 15:53:27 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by mail.postgresql.org (Postfix) with ESMTP id 8203E1337B64 for ; Tue, 11 Jan 2011 11:53:23 -0400 (AST) Received: from smadev.internal.net (localhost.internal.net [127.0.0.1]) by smadev.internal.net (8.14.2/8.14.2) with ESMTP id p0BFrNt6045242 for ; Tue, 11 Jan 2011 17:53:23 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Received: from localhost (localhost [[UNIX: localhost]]) by smadev.internal.net (8.14.2/8.14.2/Submit) id p0BFrMQO045241 for pgsql-admin@postgresql.org; Tue, 11 Jan 2011 17:53:22 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: pgsql-admin@postgresql.org Subject: Postgresql 9.0.2 explain analyze very slow (10x), compared to actual query time Date: Tue, 11 Jan 2011 17:53:22 +0200 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201101111753.22602.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.451 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_BRBL_LASTEXT=1.449 X-Spam-Level: X-Archive-Number: 201101/51 X-Sequence-Number: 36491 Hello, I have noticed that in 9.0.2 EXPLAIN ANALYZE takes considerably longer time to return than the actual query. I never noticed this in 8.3. Example: In 9.0.2 i get dynacom=# EXPLAIN ANALYZE SELECT count(ms.id) from marinerstates ms,mariner m where ms.endtime IS NOT NULL AND ms.marinerid=m.id; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=4716.48..4716.49 rows=1 width=4) (actual time=413.378..413.379 rows=1 loops=1) -> Hash Join (cost=788.77..4582.04 rows=53775 width=4) (actual time=54.029..330.286 rows=53845 loops=1) Hash Cond: (ms.marinerid = m.id) -> Seq Scan on marinerstates ms (cost=0.00..2583.33 rows=53775 width=8) (actual time=0.005..99.092 rows=53845 loops=1) Filter: (endtime IS NOT NULL) -> Hash (cost=583.90..583.90 rows=16390 width=4) (actual time=54.011..54.011 rows=16390 loops=1) Buckets: 2048 Batches: 1 Memory Usage: 577kB -> Seq Scan on mariner m (cost=0.00..583.90 rows=16390 width=4) (actual time=0.004..27.587 rows=16390 loops=1) Total runtime: 413.495 ms dynacom=# \timing Timing is on. dynacom=# SELECT count(ms.id) from marinerstates ms,mariner m where ms.endtime IS NOT NULL AND ms.marinerid=m.id; count ------- 53845 (1 row) Time: 39,038 ms So the actual time (39 ms) differs considerably from the EXPLAIN ANALYZE Total runtime (413 ms) (10 times bigger) In 8.3 i get postgres@dynacom=# EXPLAIN ANALYZE SELECT count(ms.id) from marinerstates ms,mariner m where ms.endtime IS NOT NULL AND ms.marinerid=m.id; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=5094.13..5094.14 rows=1 width=4) (actual time=84.180..84.180 rows=1 loops=1) -> Hash Join (cost=869.15..4954.27 rows=55942 width=4) (actual time=11.284..72.630 rows=54168 loops=1) Hash Cond: (ms.marinerid = m.id) -> Seq Scan on marinerstates ms (cost=0.00..2756.50 rows=55942 width=8) (actual time=0.013..25.696 rows=54168 loops=1) Filter: (endtime IS NOT NULL) -> Hash (cost=642.40..642.40 rows=18140 width=4) (actual time=11.256..11.256 rows=16442 loops=1) -> Seq Scan on mariner m (cost=0.00..642.40 rows=18140 width=4) (actual time=0.007..5.762 rows=16442 loops=1) Total runtime: 84.346 ms (8 rows) postgres@dynacom=# SELECT count(ms.id) from marinerstates ms,mariner m where ms.endtime IS NOT NULL AND ms.marinerid=m.id; count ------- 54168 (1 row) Time: 42.224 ms In 8.3 the Total runtime is only double the value of the actual time. Is there anything that can shed some light on this? -- Achilleas Mantzios