Re: PL/PgSQL Index Usage with Trigger Variables - Mailing list pgsql-general

From Michael Fuhr
Subject Re: PL/PgSQL Index Usage with Trigger Variables
Date
Msg-id 20050119045732.GA56463@winnie.fuhr.org
Whole thread Raw
In response to PL/PgSQL Index Usage with Trigger Variables  (Thomas F.O'Connell <tfo@sitening.com>)
List pgsql-general
On Tue, Jan 18, 2005 at 10:53:40AM -0600, Thomas F.O'Connell wrote:

> UPDATE mytable SET mybigintcol = somevalue WHERE mybigintcol =
> NEW.myotherbigintcol;
>
> This shows up in the logs with the NEW variable converted to unquoted
> constant data. Is PL/PgSQL smart enough to help the planner figure out
> that it can use an index on mybigintcol based on the fact that the type
> of myotherbigintcol can be discerned from the record of NEW?

Start a new session and try this:

SET debug_print_plan TO on;
SET client_min_messages TO debug1;
<some statement that invokes the trigger>

I did some tests in 7.4.6 and 8.0.0 and an UPDATE statement like
the one above did appear to be using an index from a trigger.  Note
that the plan for the UPDATE is logged only the first time it's
executed in a session, presumably because subsequent calls to the
function use a cached plan.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Jamie Deppeler
Date:
Subject: update in triggers
Next
From: Ken Tozier
Date:
Subject: Getting table metadata