Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 533E61337BC3 for ; Wed, 12 Jan 2011 12:45:31 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 55839-05 for ; Wed, 12 Jan 2011 16:45:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id C8EAB1337BBC for ; Wed, 12 Jan 2011 12:45:23 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p0CGjKhu027366; Wed, 12 Jan 2011 11:45:20 -0500 (EST) To: Achilleas Mantzios cc: pgsql-admin@postgresql.org Subject: Re: Postgresql 9.0.2 explain analyze very slow (10x), compared to actual query time In-reply-to: <201101121817.11143.achill@matrix.gatewaynet.com> References: <201101111753.22602.achill@matrix.gatewaynet.com> <201101121318.44007.achill@matrix.gatewaynet.com> <25677.1294844873@sss.pgh.pa.us> <201101121817.11143.achill@matrix.gatewaynet.com> Comments: In-reply-to Achilleas Mantzios message dated "Wed, 12 Jan 2011 18:17:10 +0200" Date: Wed, 12 Jan 2011 11:45:20 -0500 Message-ID: <27365.1294850720@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/60 X-Sequence-Number: 36500 Achilleas Mantzios writes: > Στις Wednesday 12 January 2011 17:07:53 ο/η Tom Lane έγραψε: >> Right offhand I'd wonder whether that was more bound by gettimeofday or >> by printf. Please try it without printf in the loop. > Changed that to smth like: micros_total = micros_total + (double) micros; > instead of the printf to beat any compiler optimization, and still linux runs at light speed: > FBSD_TEST : user 0.089s, sys 1.4s > FBSD_DEV : user 0.183s, sys 3.8s > LINUX_PROD : user 0.168s, sys 0s Well, there's your problem all right: the FBSD_DEV system takes 22X longer to execute gettimeofday() than the LINUX_PROD system. The particular plan that 9.0 is choosing is especially vulnerable to this because it involves a whole lot of calls of the Materialize plan node: > -> Nested Loop (cost=3390.49..9185.73 rows=1 width=4) (actual time=279.916..93280.499 rows=1824 loops=1) > Join Filter: (msold.marinerid = mold.id) > -> Index Scan using mariner_pkey on mariner mold (cost=0.00..1957.89 rows=15914 width=4) (actual time=0.009..38.449 rows=15914 loops=1) > Filter: ((marinertype)::text = 'Mariner'::text) > -> Materialize (cost=3390.49..6989.13 rows=1 width=8) (actual time=0.013..2.881 rows=1888 loops=15914) You've got 1888 * 15914 * 2 gettimeofday() calls needed to count up the time spent in Materialize, which at 3.8usec apiece adds up to ... hmm ... I get 228 seconds, which is more than the reported runtime. So I think there's something wrong with your measurement of the gettimeofday cost. But I wouldn't be a bit surprised to hear that the true cost of gettimeofday on that machine is a microsecond or so, in which case all of the EXPLAIN ANALYZE time bloat is indeed due to that. This problem has been discussed repeatedly on the pgsql-performance list, which is where your question really belongs, not here. The short of it is that cheap motherboards tend to provide cheap clock hardware that takes about a microsecond to read. It also helps to be running an OS that is able to read the clock in userspace without invoking a kernel call. It looks like your Linux box is winning on both counts compared to your BSD boxes. regards, tom lane