Re: Planner doesn't take indexes into account

From: Shaun Thomas <sthomas(at)optionshouse(dot)com>
To: Grzegorz Olszewski <grzegorz(dot)olszewski(at)outlook(dot)com>, AI Rumman <rummandba(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Planner doesn't take indexes into account
Date: 2014-05-28 13:31:38
Message-ID: 5385E53A.4000406@optionshouse.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 05/28/2014 04:59 AM, Grzegorz Olszewski wrote:

> There is about 500,000 rows and about 500 new rows each business day.
>
> About 96% of rows meet given conditions, that is, count shoud be about
> 480,000.

Heikki is right on this. Indexes are not a magic secret sauce that are
always used simply because they exist. Think of it like this...

If the table really matches about 480,000 rows, by forcing it to use the
index, it has to perform *at least* 480,000 random seeks. Even if you
have a high-performance SSD array that can do 100,000 random reads per
second, you will need about five seconds just to read the data.

A sequence scan can perform that same operation in a fraction of a
second because it's faster to read the entire table and filter out the
*non* matching rows.

Indexes are really only used, or useful, when the number of matches is
much lower than the row count of the table. I highly recommend reading
up on cardinality and selectivity before creating more indexes. This
page in the documentation does a really good job:

http://www.postgresql.org/docs/9.3/static/row-estimation-examples.html

--
Shaun Thomas
OptionsHouse, LLC | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas(at)optionshouse(dot)com

______________________________________________

See http://www.peak6.com/email_disclaimer/ for terms and conditions related to this email

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Grzegorz Olszewski 2014-05-28 21:03:22 Re: Planner doesn't take indexes into account
Previous Message Heikki Linnakangas 2014-05-28 10:22:43 Re: Planner doesn't take indexes into account