Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 46B652E0096 for ; Thu, 24 Apr 2008 14:00:22 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 13428-08-3 for ; Thu, 24 Apr 2008 14:00:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from 27.mail-out.ovh.net (27.mail-out.ovh.net [91.121.30.210]) by developer.postgresql.org (Postfix) with SMTP id 2C1902E0091 for ; Thu, 24 Apr 2008 14:00:17 -0300 (ADT) Received: (qmail 23198 invoked by uid 503); 24 Apr 2008 18:47:06 -0000 Received: from gw2.ovh.net (HELO mail174.ha.ovh.net) (213.251.189.202) by 27.mail-out.ovh.net with SMTP; 24 Apr 2008 18:47:06 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 24 Apr 2008 17:00:14 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13.peufeu.com) (88.161.102.87) by ns0.ovh.net with SMTP; 24 Apr 2008 17:00:13 -0000 Date: Thu, 24 Apr 2008 19:05:14 +0200 To: "Viktor Rosenfeld" , "Tom Lane" Subject: Re: Performance of the Materialize operator in a query plan From: PFC Cc: pgsql-performance@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <6567C6DA-88EB-4B1D-BEBD-EE15630B044C@informatik.hu-berlin.de> <11083.1208789089@sss.pgh.pa.us> <316F5B37-3D07-417B-B5C1-9DB973258B18@informatik.hu-berlin.de> Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: <316F5B37-3D07-417B-B5C1-9DB973258B18@informatik.hu-berlin.de> User-Agent: Opera Mail/9.24 (Linux) 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-Ovh-Tracer-Id: 15396118276454745648 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.72 tagged_above=0 required=5 tests=AWL=0.720 X-Spam-Level: X-Archive-Number: 200804/362 X-Sequence-Number: 29855 > Do you mean, that the overhead is an artefact of timing the query? In= = > that case, the query should run faster than its evaluation with EXPLAI= N = > ANALYZE, correct? > > Is there a way to test this assumption regarding the speed of = > gettimeofday? I'm on a Macbook and have no idea about the performance= = > of its implementation. Run EXPLAIN ANALYZE query Type \timing Run SELECT count(*) FROM (query) AS foo \timing gives timings as seen by the client. If you're local, and the = result set is one single integer, client timings are not very different = = from server timings. If the client must retrieve lots of rows, this wil= l = be different, hence the fake count(*) above to prevent this. You might = want to explain the count(*) also to be sure the same plan is used... And yes EXPLAIN ANALYZE has overhead, sometimes significant. Think = Heisenberg... You will measure it easily with this dumb method ;) Here a very dumb query : SELECT count(*) FROM test; count ------- 99999 (1 ligne) Temps : 26,924 ms test=3D> EXPLAIN ANALYZE SELECT count(*) FROM test; QUERY PLAN ------------------------------------------------------------------------= -------- = = -------------------------------- Aggregate (cost=3D1692.99..1693.00 rows=3D1 width=3D0) (actual = time=3D66.314..66.314 = r = = ows=3D1 loops=3D1) -> Seq Scan on test (cost=3D0.00..1442.99 rows=3D99999 width=3D0) = (actual = time=3D0. = = 013..34.888 rows=3D99999 loops=3D1) Total runtime: 66.356 ms (3 lignes) Temps : 66,789 ms Apparently measuring the time it takes to get a row from the table takes= = 2x as long as actually getting the row from the table. Which is = reassuring, in a way, since grabbing rows out of tables isn't such an = unusual operation.