Skip site navigation (1) Skip section navigation (2)

Re: seq scan instead of index scan

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Karl Larsson <karl(dot)larsson47(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: seq scan instead of index scan
Date: 2009-12-17 23:26:36
Message-ID: dcc563d10912171526q3e341825i429c6627b4f4d3a9@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performance
On Thu, Dec 17, 2009 at 4:22 PM, Karl Larsson <karl(dot)larsson47(at)gmail(dot)com> wrote:
> Hello.
>
> I have a problem I don't understand. I hope it's a simple problem and I'm
> just stupid.
>
> When I make a subquery Postgres don't care about my indexes and makes
> a seq scan instead of a index scan. Why?

PostgreSQL uses an intelligent query planner that predicets how many
rows it will get back for each plan and chooses accordingly.  Since a
few dozen rows will all likely fit in the same block, it's way faster
to sequentially scan the table than to use an index scan.

Note that pgsql always has to go back to the original table to get the
rows anyway, since visibility info is not stored in the indexes.

In response to

Responses

pgsql-performance by date

Next:From: Kevin GrittnerDate: 2009-12-17 23:29:14
Subject: Re: seq scan instead of index scan
Previous:From: Karl LarssonDate: 2009-12-17 23:22:15
Subject: seq scan instead of index scan

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group