Re: Question on Explain : Index Scan

From: Mathieu De Zutter <mathieu(at)dezutter(dot)org>
To: DM <dm(dot)aeqa(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Question on Explain : Index Scan
Date: 2010-10-21 10:20:43
Message-ID: AANLkTik+AFrvM+ExApccijUN0pnbi=9Nt0iZotP88z31@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 21, 2010 at 3:47 AM, DM <dm(dot)aeqa(at)gmail(dot)com> wrote:
> I was hoping the optimizer would do a join using index scan.
>
> Could some one please explain me why its not doing an index scan rather than
> sequential scan .

A index scan would be probably slower here because you're asking for a
lot of rows. A lot of rows means a lot of I/O, and an index scan is
more I/O intensive (since it has to read the index too). If you limit
the result (by being more selective in your where clause, just like
you do in the first two queries), postgres will most likely switch to
index scan.

You can see for yourself if index-scan would be faster in your case by
running the following command before "explain (analyze)":

set enable_seqscan = off;

BTW, try to use explain analyze instead of explain, that way you'll
see the actual timings too instead of just the planner estimates.

Kind regards,
Mathieu

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2010-10-21 10:40:42 Re: [GENERAL] [ANNOUNCE] PGDay Europe 2010 Registration Open
Previous Message Scott Marlowe 2010-10-21 07:52:09 Re: Updates, deletes and inserts are very slow. What can I do make them bearable?