Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DED9AB5D80B for ; Tue, 14 Jun 2011 01:44:52 -0300 (ADT) 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 37080-04 for ; Tue, 14 Jun 2011 04:44:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f46.google.com (mail-pz0-f46.google.com [209.85.210.46]) by mail.postgresql.org (Postfix) with ESMTP id 8BA0FB5D80A for ; Tue, 14 Jun 2011 01:44:46 -0300 (ADT) Received: by pzk9 with SMTP id 9so2444349pzk.19 for ; Mon, 13 Jun 2011 21:44:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.15.170 with SMTP id y10mr2471179pbc.364.1308026685365; Mon, 13 Jun 2011 21:44:45 -0700 (PDT) Received: by 10.68.49.197 with HTTP; Mon, 13 Jun 2011 21:44:45 -0700 (PDT) X-Originating-IP: [66.215.95.51] In-Reply-To: References: <4DF5B7B3.7010708@postnewspapers.com.au> <56264945a293522f5d499649330d3f84@mail.softperience.eu> Date: Mon, 13 Jun 2011 21:44:45 -0700 Message-ID: Subject: Re: Question about speed: Weird Behavior From: Samuel Gendler To: Israel Ben Guilherme Fonseca Cc: pgsql-jdbc@postgresql.org Content-Type: multipart/alternative; boundary=bcaec51f9959f01f1304a5a4b1e4 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201106/34 X-Sequence-Number: 21958 --bcaec51f9959f01f1304a5a4b1e4 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 13, 2011 at 6:07 PM, Israel Ben Guilherme Fonseca < israel.bgf@gmail.com> wrote: > > When I use the count, my timings get around of > > 100 miliseconds. > > When I use the select it goes to > > 30 miliseconds. > > I don't know much about the internals of the protocol used to move data around for jdbc, but doesn't this actually make some sense? If the query returns as soon as the first row has arrived, then select * should definitely be faster than select count(*), since count(*) can't return until the entire table has been scanned, whereas select * returns with the first row received. That, at least, seems like a likely candidate for the difference between them, no? --sam --bcaec51f9959f01f1304a5a4b1e4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Mon, Jun 13, 2011 at 6:07 PM, Israel Ben= Guilherme Fonseca <israel.bgf@gmail.com> wrote:

When I use the count, my timings get around of

100 miliseconds.<= br>
When I use the select it goes to

30 miliseconds.


I don't know much about the internals of th= e protocol used to move data around for jdbc, but doesn't this actually= make some sense? =A0If the query returns as soon as the first row has arri= ved, then select * should definitely be faster than select count(*), since = count(*) can't return until the entire table has been scanned, whereas = select * returns with the first row received. =A0That, at least, seems like= a likely candidate for the difference between them, no?

--sam


--bcaec51f9959f01f1304a5a4b1e4--