Received: from sss2.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id MAA94888 for ; Tue, 16 May 2000 12:36:35 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss2.sss.pgh.pa.us (8.9.3/8.9.3) with ESMTP id MAA21657; Tue, 16 May 2000 12:36:28 -0400 (EDT) To: Kyle Bateman , pgsql-sql@postgresql.org, merrill@actarg.com Subject: Re: Index not used in functions in 7.0? In-reply-to: <21401.958492203@sss.pgh.pa.us> References: <3921689A.B70CFAC8@actarg.com> <21401.958492203@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 16 May 2000 11:50:03 -0400" Date: Tue, 16 May 2000 12:36:28 -0400 Message-ID: <21654.958494988@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200005/15 Tom Lane writes: > Kyle Bateman 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