Re: Query plans for plpgsql triggers
| От | Tom Lane |
|---|---|
| Тема | Re: Query plans for plpgsql triggers |
| Дата | |
| Msg-id | 14507.1143261580@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Query plans for plpgsql triggers ("Eric B. Ridge" <ebr@tcdi.com>) |
| Ответы |
Re: Query plans for plpgsql triggers
|
| Список | pgsql-general |
"Eric B. Ridge" <ebr@tcdi.com> writes:
> When is the UPDATE statement inside foo() planned? When the trigger
> is first created, or when it's first used per backend, or every time
> it's used per backend?
First use per backend, ignoring corner cases such as replacing the
function definition.
> I dunno what plan is being generated, but it's gotta be using a
> sequential scan.
The issue is probably that the planner is seeing a parameterized
query. Try this:
prepare foo(int8) as update some_other_table SET field = 'value' WHERE id = $1;
explain execute foo(42);
and see what plan you get. If the id field has sufficiently
discouraging statistics then the planner may think that a seqscan
is the safest plan. In a "normal" query where you're comparing id
to a constant, the planner can see whether the constant matches any
of the most common values for the column --- if it doesn't then an
indexscan is a good plan.
If you really want a replan every time, you can get it by using
EXECUTE.
regards, tom lane
В списке pgsql-general по дате отправления: