pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nick Fankhauser <nickf@ontko.com>
To: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Are statistics gathered on function indexes?
Date: Wed, 26 Jun 2002 14:36:01 -0500
Message-ID: <NEBBLAAHGLEEPCGOBHDGMEHPFDAA.nickf@ontko.com> (raw)

Hi-

Can someone tell me how the cost is estimated for retrieving a column based
on a function that is indexed?

The issue I'm wrestling with is a query which works nicely when based on a
plain "LIKE field", but    poorly using "LIKE upper(field)". There is an
index on both.

Since this field has only uppercase strings in it currently, I know that
both indexes are equally selective, but the planner judges that "LIKE field"
will return 1 row, and "LIKE upper(field)" will return 2168 rows. In both
cases, the index is used, but in the next step, joining to another table,
the regular version uses an index on the other table, while the "upper"
version uses a seq scan. I'm guessing that the scan is used because if we
are going after 2168 rows in the adjoining table, the index is no longer a
good choice.

I'm able to see the stats for the field using pg_stats, but don't see
anything connected to the function, so I'm guessing that real stats aren't
kept & some sort of default is used. perhaps I can modify this default.



Also, even with 2168 rows to gather, my experience based on cases where
several thousand rows really are returned indicates that the index would
still be a good choice. Is there a way to make the planner favor index scans
a bit more? (Other than the drastic set enable_seqscan to off.)


Thanks

-Nick



--------------------------------------------------------------------------
Nick Fankhauser  nickf@ontko.com  Phone 1.765.935.4283  Fax 1.765.962.9788
Ray Ontko & Co.     Software Consulting Services     http://www.ontko.com/






view thread (23+ messages)  latest in thread

Message-ID: <NEBBLAAHGLEEPCGOBHDGMEHPFDAA.nickf@ontko.com>
Permalink:  ../NEBBLAAHGLEEPCGOBHDGMEHPFDAA.nickf@ontko.com/
Also on:    postgresql.org/message-id/NEBBLAAHGLEEPCGOBHDGMEHPFDAA.nickf@ontko.com

 · 

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-admin@postgresql.org
  Cc: nickf@ontko.com
  Subject: Re: Are statistics gathered on function indexes?
  In-Reply-To: <NEBBLAAHGLEEPCGOBHDGMEHPFDAA.nickf@ontko.com>
  References: <NEBBLAAHGLEEPCGOBHDGMEHPFDAA.nickf@ontko.com>

* 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