From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ralph Mason <ralph.mason@telogis.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query is 800 times slower when running in function!
Date: Wed, 30 Nov 2005 23:58:00 -0500
Message-ID: <6648.1133413080@sss.pgh.pa.us> (raw)
In-Reply-To: <438E4F12.7060205@telogis.com>
References: <438E4F12.7060205@telogis.com>
Ralph Mason <ralph.mason@telogis.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
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, ralph.mason@telogis.com
Subject: Re: Query is 800 times slower when running in function!
In-Reply-To: <6648.1133413080@sss.pgh.pa.us>
* 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