Re: Why indexes are not used when scanning from functions?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ловпаче Айдамир" <aidanet(at)yandex(dot)ru>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Why indexes are not used when scanning from functions?
Date: 2001-05-23 18:28:18
Message-ID: 16262.990642498@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

=?KOI8-R?B?IuzP19DB3sUg4crEwc3J0iI=?= <aidanet(at)yandex(dot)ru> writes:
> create function get_fio1(text) returns varchar
> as 'select fio from patient_temp where fio like $1::text || \'%\';'
> language 'sql';

You won't get an indexscan for this because the LIKE pattern is not
a constant at planning time, and so the planner cannot extract indexscan
bounds from it.

In 7.1 it's possible to obtain the desired result in plpgsql, by using
EXECUTE. You'd need to substitute the pattern into the query string
as a literal constant, not as a plpgsql variable.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Diehl, Jeffrey 2001-05-23 21:00:33 Error msg.
Previous Message Alla 2001-05-23 18:20:14 Return cursor