From: Bruce Momjian <maillist@candle.pha.pa.us>
To: molivier@yahoo.com
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] questions on interpreting the output of explain
Date: Sat, 20 Feb 1999 01:06:48 -0500 (EST)
Message-ID: <199902200606.BAA10867@candle.pha.pa.us> (raw)
In-Reply-To: <19990220050748.28250.rocketmail@send103.yahoomail.com>
> I'm trying to optimize a query and don't yet understand PostGreSQL's
> query optimization... I'm not sure how to read it in terms of best
> outcome. On a query that looks like:
>
> explain select U.oid from users U, selections S where
> U.acctname = S.acctname and
> U.birthdate <= '1-1-1963' and
> U.birthdate >= '1-1-1933' and
> 38 >= S.field1_int and
> 38 <= S.field2_int and
> U.tol_a < 99.0 and
> U.tol_b < 99.0
>
> (indexes on: U.birthdate, U.acctname, S.acctname, U.tol_a, U.tol_b)
>
> I get:
>
> Nested Loop (cost=9.38 size=1 width=28)
> -> Index Scan on u (cost=3.26 size=3 width=16)
> -> Index Scan on s (cost=2.04 size=25 width=12)
>
> ...but if I shorten the query slightly:
>
> explain select U.oid from users U, selections S where
> U.acctname = S.acctname and
> U.birthdate <= '1-1-1963' and
> U.birthdate >= '1-1-1933' and
> 38 >= S.field1_int and
> 38 <= S.field2_int
>
> ...I get:
>
> Hash Join (cost=14.67 size=3 width=28)
> -> Index Scan on u (cost=3.26 size=26 width=16)
> -> Hash (cost=0.00 size=0 width=0)
> -> Index Scan on s (cost=7.73 size=25 width=12)
>
> Can someone explain the details here to me? I guess specific questions
> are:
> - Does hash join mean my acctname indexes are hashed, not btree'd?
No. It hashes the inner to make the join quicker.
> - What does index scan mean?
Uses an existing index to restrict what rows are used.
> - Nested loop?
compare every row to every other row.
> - Does the cost roll-up, meaning the top line is total cost, and
> rest is a breakdown, or do I add up all the cost numbers?
rolls up.
> - Can I compare costs between two queries?
It picks the cheapest. Go to the web site, go to support, the
documenation, choose the backend flowchart, and click on optimizer. It
will show you a README file that is new for 6.5(not released yet) which
should give you some ideas. The optimizer will be improved for 6.5.
--
Bruce Momjian | http://www.op.net/~candle
maillist@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
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-sql@postgresql.org
Cc: maillist@candle.pha.pa.us, molivier@yahoo.com
Subject: Re: [SQL] questions on interpreting the output of explain
In-Reply-To: <199902200606.BAA10867@candle.pha.pa.us>
References: <19990220050748.28250.rocketmail@send103.yahoomail.com> <199902200606.BAA10867@candle.pha.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