pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kyle Bateman <kyle@actarg.com>
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us
Cc: merrill@actarg.com
Subject: Index not used in functions in 7.0?
Date: Tue, 16 May 2000 09:26:18 -0600
Message-ID: <3921689A.B70CFAC8@actarg.com> (raw)

Help! We upgraded to 7.0 last week and all looks good except a problem
with indexes and its a show-stopper!  Any advice would be greatly
appreciated.

Here's the problem.  I have a table with 50,000 entries.  This function
runs a sum on a column of the table:

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';

We have a critical query (which calls this function) we run on stock
levels that used to take about 30 seconds.  Now it takes something like
30 hours (I've never seen it terminate).

The problem seems to be that when a query is called from within a
function, the scan is sequential even if an index exists.  I tried
entering the SQL directly as:

select sum(tquant)
        from mtr_reg
        where to_proj = 50
        and pnum = '1051'
        and (status = 'clsd' or status = 'open' or status = 'prip')
;

And it accesses the index properly even though it is the exact same
query.

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.

Is this due to something I'm doing wrong or is this a bug?

I'd be happy to provide a dump of the data, do other testing or whatever
would help.  I'm not sure who on the team is best to look at this.

Thanks all!

Kyle

Attachments:

kyle.vcf (text/x-vcard, 290B) download begin:vcard n:Bateman;Kyle tel;fax:801-377-8096 tel;work:801-377-8033x101 x-mozilla-html:FALSE url:www.actiontarget.com org:Action Target Inc adr:;;PO Box 636;Provo;UT;84603;US version:2.1 email;internet:kyle@actiontarget.com title:President x-mozilla-cpt:;-15520 fn:Kyle Bateman end:vcard

view thread (7+ messages)  latest in thread

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