pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kyle Bateman <kyle@actarg.com>
To: pgsql-sql@postgresql.org
To: merrill@actarg.com
Subject: Re: Index not used in functions in 7.0?
Date: Tue, 16 May 2000 12:36:28 -0400
Message-ID: <21654.958494988@sss.pgh.pa.us> (raw)
In-Reply-To: <21401.958492203@sss.pgh.pa.us>
References: <3921689A.B70CFAC8@actarg.com>
	<21401.958492203@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.us> writes:
> Kyle Bateman <kyle@actarg.com> writes:
>> I dumped the log (-d 9) from the postmaster and the plan confirms that
>> the scan is sequential when called from within the function but indexed
>> when the SQL is called directly.

> Yikes, that does sound like a bug.

Actually, after further thought I realize that there is a reason for
plans within functions to be different from plans of hand-entered
queries.  In the latter case the optimizer knows the constant values
(eg, it sees "WHERE to_proj = 50"), in the former case it doesn't
(eg, it sees "WHERE to_proj = $1") and has to fall back on guesses
about selectivities.

In the particular case at hand I've have expected it to pick an
indexscan anyway, but maybe there's just something weird about your
data.  Could I trouble you for the vacuum stats for that table?
Easiest way to get them is

select attname,attdisbursion,s.*
from pg_statistic s, pg_attribute a, pg_class c
where starelid = c.oid and attrelid = c.oid and staattnum = attnum
and relname = 'FOO';

(I'm beginning to think we should create a standard system view
for this query ;-))

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <21654.958494988@sss.pgh.pa.us>
Permalink:  ../21654.958494988@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21654.958494988@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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kyle@actarg.com, merrill@actarg.com
  Subject: Re: Index not used in functions in 7.0?
  In-Reply-To: <21654.958494988@sss.pgh.pa.us>
  References: <3921689A.B70CFAC8@actarg.com> <21401.958492203@sss.pgh.pa.us> <21654.958494988@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