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>
Cc: pgsql-sql@postgresql.org
Cc: merrill@actarg.com
Subject: Re: Index not used in functions in 7.0?
Date: Tue, 16 May 2000 15:11:56 -0400
Message-ID: <14055.958504316@sss.pgh.pa.us> (raw)
In-Reply-To: <3921689A.B70CFAC8@actarg.com>
References: <3921689A.B70CFAC8@actarg.com>

Kyle Bateman <kyle@actarg.com> writes:
> create function summtr_ocpt2(text, int4) returns int4 as '
>     select sum(tquant) from mtr_reg where to_proj = $2 and pnum = $1 and
> (status = \'open\' or status = \'clsd\' or status = \'prip\');
>     ' language 'sql';

Ah, I've sussed it.  The difference between the environment in your
function and the environment in a hand-entered query is that you've
declared $1 to be type 'text', whereas in the hand-entered query the
parser resolves the unknown-type string literal into type 'varchar'
to match the type of what it's being compared to.  What you effectively
have inside the function is pnum::text = $1::text, and the planner is
not able to figure out that it can use a varchar index for that.  If you
had written the hand-entered query as "... pnum = '1051'::text ..."
it wouldn't have been done with an indexscan either.

Best short-term solution is to declare the function as taking varchar
in the first place.

This behavior is a regression from 6.5, which handled implicit coercions
differently and could recognize the clause as indexable despite the
inserted coercion.  I'll look into whether it's patchable for 7.0.1.
A proper fix might be too complex to risk patching into 7.0.1 though :-(
... might have to wait for 7.1.

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <14055.958504316@sss.pgh.pa.us>
Permalink:  ../14055.958504316@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14055.958504316@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: <14055.958504316@sss.pgh.pa.us>
  References: <3921689A.B70CFAC8@actarg.com> <14055.958504316@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