pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ray Ontko <rayo@ontko.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Are statistics gathered on function indexes?
Date: Fri, 28 Jun 2002 10:01:02 -0400
Message-ID: <3612.1025272862@sss.pgh.pa.us> (raw)
In-Reply-To: <200206281240.HAA03045@shire.ontko.com>
References: <200206281240.HAA03045@shire.ontko.com>

Ray Ontko <rayo@ontko.com> writes:
>> It's there already; what did you think was making the difference
>> between W% and WI% ?

> Yes, but the cost doesn't continue to decline if I make the LIKE
> more and more restrictive by going from WI% to WIL% to WILL%, etc.

Yes it does, if you have a large enough table.  In most scenarios
the selectivity drops off fast enough with larger strings that you
hit the minimum estimate of 1 row pretty quickly; I suppose that's
what's happening with your case.  Here's an example using the 7.2
regression-test database:

-- update stats
regression=# analyze road;
ANALYZE

-- now force planner to think "road" is much larger than it really is,
-- else we can't see the change in estimate beyond WI%
regression=# update pg_class set relpages = relpages * 10000,
regression-# reltuples = reltuples * 10000 where relname = 'road';
UPDATE 1

regression=# explain select * from only road where name like 'W%';
NOTICE:  QUERY PLAN:

Seq Scan on road  (cost=0.00..1444625.00 rows=764903 width=89)

EXPLAIN
regression=# explain select * from only road where name like 'WI%';
NOTICE:  QUERY PLAN:

Index Scan using rix on road  (cost=0.00..25007.80 rows=8406 width=89)

EXPLAIN
regression=# explain select * from only road where name like 'WIJ%';
NOTICE:  QUERY PLAN:

Index Scan using rix on road  (cost=0.00..277.04 rows=92 width=89)

EXPLAIN
regression=# explain select * from only road where name like 'WIJK%';
NOTICE:  QUERY PLAN:

Index Scan using rix on road  (cost=0.00..5.28 rows=1 width=89)

EXPLAIN
regression=# explain select * from only road where name like 'WIJKL%';
NOTICE:  QUERY PLAN:

Index Scan using rix on road  (cost=0.00..5.23 rows=1 width=89)

EXPLAIN
regression=# explain select * from only road where name like 'WIJKLM%';
NOTICE:  QUERY PLAN:

Index Scan using rix on road  (cost=0.00..5.23 rows=1 width=89)

EXPLAIN
regression=#

As you can see, the estimate drops off by about a factor of 90 per
added character.  This is probably too much, but it's not that easy
to determine what the ratio ought to be.  The critical code involved
in this is convert_string_to_scalar in backend/utils/adt/selfuncs.c;
the ratio per character is essentially the same as the character range
that it induces from the available values.  Feel free to propose a
better implementation if you can think of one.

			regards, tom lane





view thread (23+ messages)  latest in thread

Message-ID: <3612.1025272862@sss.pgh.pa.us>
Permalink:  ../3612.1025272862@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3612.1025272862@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, rayo@ontko.com
  Subject: Re: Are statistics gathered on function indexes?
  In-Reply-To: <3612.1025272862@sss.pgh.pa.us>
  References: <200206281240.HAA03045@shire.ontko.com> <3612.1025272862@sss.pgh.pa.us>

* 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