Re: Any better plan for this query?..

From: Ries van Twisk <pg(at)rvt(dot)dds(dot)nl>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Dimitri <dimitrik(dot)fr(at)gmail(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Any better plan for this query?..
Date: 2009-05-06 13:08:01
Message-ID: 3D84DC40-FD91-4CC3-85F7-9F5B1FCF5D89@rvt.dds.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On May 6, 2009, at 7:53 AM, Richard Huxton wrote:

> Dimitri wrote:
>> I'll try to answer all mails at once :-))
>> - query is running fully in RAM, no I/O, no network, only CPU time
>> - looping 100 times the same query gives 132ms total time (~1.32ms
>> per
>> query), while it's 44ms on InnoDB (~0.44ms per query)
>
> Well, assuming you're happy that PG is tuned reasonably for your
> machine and that MySQL's query cache isn't returning the results
> here it looks like MySQL is faster for this particular query.
>
> The only obvious place there could be a big gain is with the hashing
> algorithm. If you remove the ORDER BY and the query-time doesn't
> fall by much then it's the hash phase.
>
> The other thing to try is to alter the query to be a SELECT count(*)
> rather than returning rows - that will let you measure the time to
> transfer the result rows.
>
> --
> Richard Huxton
> Archonet Ltd
>

Do you expect to run this query 100 times per second during your
application?
or is this just a test to see how fast the query is for optimalisation.

I always get scared myself with such a test as 'runs out of memory',
reason
given is that usually this is not really the case in a production
environment.

Try to make a little test case where you give the query random
parameters
so different result sets are returned. This will give you a better
idea on how
fast the query really is and might give you better comparison results.

instead of count(*) I isusallt do explain analyze to see how fast
PostgreSQL handles to query.

Ries

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Dimitri 2009-05-06 14:03:42 Re: Any better plan for this query?..
Previous Message Kenneth Marshall 2009-05-06 13:05:10 Re: Any better plan for this query?..