Re: PL/PgSQL Index Usage with Trigger Variables

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "Thomas F(dot)O'Connell" <tfo(at)sitening(dot)com>
Cc: PgSql General <pgsql-general(at)postgresql(dot)org>
Subject: Re: PL/PgSQL Index Usage with Trigger Variables
Date: 2005-01-19 04:57:32
Message-ID: 20050119045732.GA56463@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ken Tozier 2005-01-19 05:14:57 Getting table metadata
Previous Message Jamie Deppeler 2005-01-19 04:45:53 update in triggers