Re: Why indexes are not used when scanning from functions? - Mailing list pgsql-sql

From Tom Lane
Subject Re: Why indexes are not used when scanning from functions?
Date
Msg-id 16262.990642498@sss.pgh.pa.us
Whole thread Raw
In response to Why indexes are not used when scanning from functions?  ("Ловпаче Айдамир" <aidanet@yandex.ru>)
List pgsql-sql
"Ловпаче Айдамир" <aidanet@yandex.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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: index/join madness
Next
From: "Diehl, Jeffrey"
Date:
Subject: Error msg.