pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
To: Josh Berkus <josh@agliodbs.com>
To: postgres performance list <pgsql-performance@postgresql.org>
Subject: Re: Strange choice of general index over partial index
Date: Fri, 16 Jan 2015 13:37:06 +1300
Message-ID: <54B85D32.7090106@catalyst.net.nz> (raw)
In-Reply-To: <54B83F70.7080004@agliodbs.com>
References: <54B83F70.7080004@agliodbs.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

On 16/01/15 11:30, Josh Berkus wrote:
> 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?
>

Are you seeing a bitmapscan access plan? If so see if disabling it gets 
you a plan on the files_in_flight index. I'm seeing this scenario with a 
fake/generated dataset a bit like yours in 9.2 (9.5 uses the 
files_in_flight w/o any coercing).

regards

Mark


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (11+ messages)  latest in thread

Message-ID: <54B85D32.7090106@catalyst.net.nz>
Permalink:  ../54B85D32.7090106@catalyst.net.nz/
Also on:    postgresql.org/message-id/54B85D32.7090106@catalyst.net.nz

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: mark.kirkwood@catalyst.net.nz, josh@agliodbs.com
  Subject: Re: Strange choice of general index over partial index
  In-Reply-To: <54B85D32.7090106@catalyst.net.nz>

* 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