Re: Sequence vs. Index Scan

From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: "Aaron Bono" <postgresql(at)aranya(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "PostgreSQL SQL List" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Sequence vs. Index Scan
Date: 2007-05-06 04:37:24
Message-ID: c2d9e70e0705052137i44d56415ud7ec0a8fa9250e23@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 5/5/07, Aaron Bono <postgresql(at)aranya(dot)com> wrote:
> On 5/5/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > "Aaron Bono" <postgresql(at)aranya(dot)com> writes:
> > > 9. -> Seq Scan on branch (cost=0.00..4.72
> rows=1
> > > width=1281) (actual time= 130129.988..157492.057 rows=1 loops=1)
> > > 10. Filter: ((start_day
> <= now()) AND
> > > ((end_day IS NULL) OR (end_day >= now())) AND (branch_id =
> > > get_branch_for_zip('22151'::character varying)))
> >
> > There is something *awfully* wacko about that entry --- the fact that
> > the cost estimate is less than 5 units means that the planner thinks
> > there's 4 or fewer pages; either that's way wrong or the
> > get_branch_for_zip function is taking enormous amounts of time per row.
> > Have you tried timing that function on its own?
> >
> > One possible reason for the performance difference is if you have
> > get_branch_for_zip marked as stable in one database and volatile in the
> > other --- volatile would prevent it from being used in an indexqual as
> > you'd like.
> >
>
> I verified it by putting a RAISE NOTICE in the function. The fast schema
> runs the function twice (odd, I would think it would run only once). The
> slow schema runs it 30 times (the number of records returned + 1). I know I
> put the functions into both schemas as stable and even dropped and recreated
> the function. Then I verified with EMS Manager and it tells me the DDL for
> the function in the database is set to stable. Is there something I can do
> to tell PostgreSQL that I really did mean stable?
>

maybe this is silly but you can verify what the database thinks of the
function selecting from pg_proc

select pronamespace, provolatile
from pg_proc where proname = 'get_branch_for_zip'

--
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Robins 2007-05-06 16:01:39 ROW_NUMBER alias
Previous Message Aaron Bono 2007-05-06 04:25:19 Re: Sequence vs. Index Scan