From: Tom Lane <tgl@sss.pgh.pa.us>
To: nickf@ontko.com
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Will an outer join on two indexed fields use the indexes?
Date: Mon, 08 Apr 2002 17:45:37 -0400
Message-ID: <23730.1018302337@sss.pgh.pa.us> (raw)
In-Reply-To: <NEBBLAAHGLEEPCGOBHDGOEKCELAA.nickf@ontko.com>
References: <NEBBLAAHGLEEPCGOBHDGOEKCELAA.nickf@ontko.com>
"Nick Fankhauser" <nickf@ontko.com> writes:
> monroe=# explain select * from
> monroe-# (charge left outer join criminal_disposition on
> monroe(# (charge.charge_id = criminal_disposition.charge_id));
> NOTICE: QUERY PLAN:
> Hash Join (cost=260.68..21110.40 rows=147101 width=360)
> -> Seq Scan on charge (cost=0.00..4883.01 rows=147101 width=252)
> -> Hash (cost=150.94..150.94 rows=5894 width=108)
> -> Seq Scan on criminal_disposition (cost=0.00..150.94 rows=5894
> width=108)
This seems like a perfectly reasonable plan to me, given that query,
and assuming that the row-count estimates aren't completely out of touch
with reality. A mergejoin-based plan isn't obviously better, and a
nestloop-based plan is almost certainly worse. (You could try forcing
those plan types and comparing the actual runtimes if you doubt it.)
If you had additional constraints --- say, a WHERE clause that selects
just one or a few rows of "charge" --- then a different plan type might
be more appropriate.
> My question is- Does the fact that this is an outer join cause this, or is
> soem other factor involved?
A left join constrains the planner's choices somewhat (it can't choose
to put the lefthand table on the inside of the join, for example). In
this case I doubt that's making any difference. Anyway, if you need an
outer join then you need it --- there are no better alternatives.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, nickf@ontko.com
Subject: Re: Will an outer join on two indexed fields use the indexes?
In-Reply-To: <23730.1018302337@sss.pgh.pa.us>
References: <NEBBLAAHGLEEPCGOBHDGOEKCELAA.nickf@ontko.com> <23730.1018302337@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox