From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Greg Stark <gsstark@mit.edu>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Cc: Lawrence Cohan <LCohan@web.com>
Subject: Re: Postgres not using indexes
Date: Fri, 01 Apr 2011 09:37:59 -0500
Message-ID: <4D959CF7020000250003C10C@gw.wicourts.gov> (raw)
In-Reply-To: <AANLkTin+ucp7067uVp+YDVLE+fqVhSO-WOEUuGkEVnHG@mail.gmail.com>
References: <965AA5440EAC094E9F722519E285ACEDAC5E66A53D@WWCEXCHANGE.web.web.com>
<4D9317D3020000250003BF7B@gw.wicourts.gov>
<965AA5440EAC094E9F722519E285ACEDAC5E66A556@WWCEXCHANGE.web.web.com>
<4D9322E8020000250003BF8C@gw.wicourts.gov>
<965AA5440EAC094E9F722519E285ACEDAC5E66A55F@WWCEXCHANGE.web.web.com>
<AANLkTikniFOL=SN1-xdWSJ+TrOmiN4xGxPqZSXd3yyVP@mail.gmail.com>
<4D94BB07020000250003C09F@gw.wicourts.gov>
<AANLkTin+ucp7067uVp+YDVLE+fqVhSO-WOEUuGkEVnHG@mail.gmail.com>
Greg Stark <gsstark@mit.edu> wrote:
> On Thu, Mar 31, 2011 at 11:33 PM, Kevin Grittner
> <Kevin.Grittner@wicourts.gov> wrote:
>> Greg Stark <gsstark@mit.edu> wrote:
>>
>>> your query does require reading all the data.
>>
>> Huh? It requires reading all the data from at least *one* of the
>> tables.
>
> The query he posted a plan for was:
>
> EXPLAIN ANALYZE select oi.id from order_items oi inner join
> clients_orders co on oi.order_id = co.id;
>
> And the plan for it looks like it's optimal to me:
>
> 'Hash Join (cost=780.55..1908023.16 rows=1027457 width=4) (actual
> time=63.506..85607.003 rows=33768 loops=1)'
> ' Hash Cond: (oi.order_id = co.id)'
> ' -> Seq Scan on order_items oi (cost=0.00..1558536.52
> rows=33843152 width=8) (actual time=0.005..69718.563 rows=33909137
> loops=1)'
> ' -> Hash (cost=480.80..480.80 rows=23980 width=4) (actual
> time=13.072..13.072 rows=23980 loops=1)'
> ' Buckets: 4096 Batches: 1 Memory Usage: 844kB'
> ' -> Seq Scan on clients_orders co (cost=0.00..480.80
> rows=23980 width=4) (actual time=0.006..6.570 rows=23980 loops=1)'
> 'Total runtime: 85613.391 ms'
It may or may not be optimal, but the assertion that all 33.9
*million* order_items rows must be read to pick out the needed 33.8
*thousand* is just plain incorrect. Personally, I won't be shocked
if using the index to cut the tuples accessed by three orders of
magnitude is faster.
-Kevin
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-bugs@postgresql.org
Cc: Kevin.Grittner@wicourts.gov, gsstark@mit.edu, LCohan@web.com
Subject: Re: Postgres not using indexes
In-Reply-To: <4D959CF7020000250003C10C@gw.wicourts.gov>
References: <965AA5440EAC094E9F722519E285ACEDAC5E66A53D@WWCEXCHANGE.web.web.com> <4D9317D3020000250003BF7B@gw.wicourts.gov> <965AA5440EAC094E9F722519E285ACEDAC5E66A556@WWCEXCHANGE.web.web.com> <4D9322E8020000250003BF8C@gw.wicourts.gov> <965AA5440EAC094E9F722519E285ACEDAC5E66A55F@WWCEXCHANGE.web.web.com> <AANLkTikniFOL=SN1-xdWSJ+TrOmiN4xGxPqZSXd3yyVP@mail.gmail.com> <4D94BB07020000250003C09F@gw.wicourts.gov> <AANLkTin+ucp7067uVp+YDVLE+fqVhSO-WOEUuGkEVnHG@mail.gmail.com> <4D959CF7020000250003C10C@gw.wicourts.gov>
* 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