Re: Sequence vs. Index Scan

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

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.72rows=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?

Yes, the first thing I did was run it on its own. It takes about 2-6
seconds to run which is not great but acceptable and the functions are
marked as stable. It is the same +/- a second or two on each of the two
schemas. The function is a plpgsql function that executes a dynamic SQL
string. Would it be better to change it to a straight SQL function? Would
that help the planner? I may be able to change it if this will help.

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 just switched the functions in both schemas to be stable (before I posted
the original question), they were volatile. After doing that, the fast
schema worked great but the slow one is still under performing. I even went
back to the slow schema and dropped and recreated the function with no
discernible difference.

This is for PostgreSQL 8.1.3 and the results are the same on Windows and
Linux versions. The windows version is a restore from the Linux version's
backup.

--
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
==================================================================

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2007-05-06 04:13:42 Re: Sequence vs. Index Scan
Previous Message Andrew Sullivan 2007-05-06 00:40:53 Re: Sequence vs. Index Scan