Re: Differences in identical queries

From: Richard Huxton <dev(at)archonet(dot)com>
To: Rob Schall <rschall(at)callone(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Differences in identical queries
Date: 2007-03-02 07:53:45
Message-ID: 45E7D809.3000007@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rob Schall wrote:
> Question for anyone...
>
> I have to queries. One runs in about 2 seconds. The other takes upwards
> of 2 minutes. I have a temp table that is created with 2 columns. This
> table is joined with the larger database of call detail records.
> However, these 2 queries are handled very differently.

1. They're different queries - the second is expecting 10 times as many
rows as the first.
2. Can't tell if that is accurate - you need to supply EXPLAIN ANALYSE
output instead of EXPLAIN, so we can see what actually happened.

> calldetail=> EXPLAIN SELECT current.* FROM current JOIN anitmp ON
> current.destnum=anitmp.ani AND istf=true;
> QUERY PLAN
> --------------------------------------------------------------------------------------
> Nested Loop (cost=0.00..2026113.09 rows=500908 width=108)

> calldetail=> EXPLAIN SELECT current.* FROM current JOIN anitmp ON
> current.orignum=anitmp.ani AND istf=false;
> ---------------------------------------------------------------------------
> Hash Join (cost=35.99..3402035.53 rows=5381529 width=108)

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2007-03-02 08:28:02 Re: usage for 'with recursive'?
Previous Message Tom Lane 2007-03-02 07:06:49 Re: [GENERAL] Fun with Cursors- how to rewind a cursor