Re: Query is 800 times slower when running in function!

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ralph Mason <ralph(dot)mason(at)telogis(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query is 800 times slower when running in function!
Date: 2005-12-01 04:58:00
Message-ID: 6648.1133413080@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Ralph Mason <ralph(dot)mason(at)telogis(dot)com> writes:
> I have a simple query that is running inside a plpgsql function.

> SELECT INTO _point_id id FROM ot2.point WHERE unit_id = _unit_id AND
> time > _last_status ORDER BY time LIMIT 1;

It would probably help significantly to make that be
"ORDER BY unit_id, time". This'd eliminate the need for the separate
sort step and encourage the planner to use the index, even when it does
not know whether the "time > x" condition is selective or not.

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tatsumi Abe 2005-12-01 05:50:56 About the relation between fragmentation of file and VACUUM
Previous Message Ralph Mason 2005-12-01 01:17:06 Query is 800 times slower when running in function!