Skip site navigation (1) Skip section navigation (2)

Re: Two queries are better than one?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Karim Nassar <karim(dot)nassar(at)acm(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Two queries are better than one?
Date: 2005-07-29 01:53:22
Message-ID: 20050729015322.GA25003@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-performance
On Thu, Jul 28, 2005 at 04:04:25PM -0700, Karim Nassar wrote:
> I ran into a situation today maintaining someone else's code where the
> sum time running 2 queries seems to be faster than 1. The original code
> was split into two queries. I thought about joining them, but
> considering the intelligence of my predecessor, I wanted to test it. 
> 
> The question is, which technique is really faster? Is there some hidden
> setup cost I don't see with explain analyze?

To see which technique will be faster in your application, time the
application code.  The queries you show are taking fractions of a
millisecond; the communications overhead of executing two queries
might make that technique significantly slower than just the server
execution time that EXPLAIN ANALYZE shows.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

pgsql-performance by date

Next:From: John A MeinelDate: 2005-07-29 02:01:01
Subject: Re: Two queries are better than one?
Previous:From: Matthew SchumacherDate: 2005-07-29 00:13:19
Subject: Re: Performance problems testing with Spamassassin 3.1.0

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group