Strange choice of general index over partial index - Mailing list pgsql-performance

From Josh Berkus
Subject Strange choice of general index over partial index
Date
Msg-id 54B83F70.7080004@agliodbs.com
Whole thread Raw
Responses Re: Strange choice of general index over partial index  (Jeff Janes <jeff.janes@gmail.com>)
Re: Strange choice of general index over partial index  (Mark Kirkwood <mark.kirkwood@catalyst.net.nz>)
Re: Strange choice of general index over partial index  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance
This is an obfuscation and mock up, but:

table files (
    id serial pk,
    filename text not null,
    state varchar(20) not null
    ... 18 more columns
)

index file_state on (state)
    (35GB in size)
index file_in_flight_state (state) where state in (
'waiting','assigning', 'processing' )
    (600MB in size)
... 10 more indexes

More important facts:
* state = 'done' 95% of the time.  thereform the partial index
represents only 5% of the table
* all indexes and the table are very bloated
* server has 128GB RAM
* Version 9.2.

Given this setup, I would expect the planner to *always* choose
file_in_flight_state over file_state for this query:

SELECT id, filename FROM files WHERE state = 'waiting';

... and yet it keeps selecting file_state based on extremely small
changes to the stats.   This is important because the same query, using
file_state, is 20X to 50X slower, because that index frequently gets
pushed out of memory.

What am I missing?  Or is this potentially a planner bug for costing?

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


pgsql-performance by date:

Previous
From: Jeff Janes
Date:
Subject: Re: shared_buffers vs Linux file cache
Next
From: Tom Lane
Date:
Subject: Re: shared_buffers vs Linux file cache