pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marko Tiikkaja <marko@joh.to>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8598: Row count estimates of partial indexes
Date: Sun, 17 Nov 2013 20:55:30 +0100
Message-ID: <52891F32.8010902@joh.to> (raw)
In-Reply-To: <28474.1384705755@sss.pgh.pa.us>
References: <E1Vi1ve-0005cP-Ax@wrigleys.postgresql.org>
	<28474.1384705755@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 11/17/13, 5:29 PM, Tom Lane wrote:
> marko@joh.to writes:
>> We have the following partial index on a small subset of a larger table:
>>    "index_transactions_transaction_balance_details" btree (transactionid)
>> WHERE NOT processed AND accountbalancesdailyid IS NOT NULL
>> However, querying with the WHERE clause completely ignores the
>> pg_class.reltuples value for the index:
>
> Yup.  Row count estimates are derived by estimating the selectivity of the
> given WHERE clauses and multiplying by the (estimated) current table size.
> In the particular case you show here, with a partial index that *exactly*
> matches the WHERE clause, we could get a better answer by looking at the
> index size --- but that doesn't scale to any less simplistic case, such
> as a query with additional WHERE clauses.
>
> It's also important to realize that reltuples for an index is a whole lot
> less trustworthy than it is for a table; ANALYZE doesn't update the
> former, for example.  And scaling from the last-reported VACUUM stats
> to current reality is going to be shakier.
>
> So on the whole, I don't think this would be a good idea.

Any suggestions for a workaround?  When reading this index as a part of 
a bigger query the horrible estimate ensures that nobody's having fun. 
I currently have something like:

   SELECT * FROM
   (SELECT * FROM transactions WHERE <partial index> LIMIT 25000) 
transactions
   JOIN ..

And I *really* don't like that as a workaround.


Regards,
Marko Tiikkaja


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



view thread (9+ messages)  latest in thread

Message-ID: <52891F32.8010902@joh.to>
Permalink:  ../52891F32.8010902@joh.to/
Also on:    postgresql.org/message-id/52891F32.8010902@joh.to

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: marko@joh.to, tgl@sss.pgh.pa.us
  Subject: Re: BUG #8598: Row count estimates of partial indexes
  In-Reply-To: <52891F32.8010902@joh.to>
  References: <E1Vi1ve-0005cP-Ax@wrigleys.postgresql.org> <28474.1384705755@sss.pgh.pa.us> <52891F32.8010902@joh.to>

* 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