Re: index not being used when variable is sent

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Eyal Wilde <eyal(at)impactsoft(dot)co(dot)il>
Cc: pgsql-performance(at)postgresql(dot)org, erans(at)impactsoft(dot)co(dot)il
Subject: Re: index not being used when variable is sent
Date: 2011-08-16 13:40:58
Message-ID: 25601.1313502058@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Eyal Wilde <eyal(at)impactsoft(dot)co(dot)il> writes:
> CREATE OR REPLACE FUNCTION test_func(STR text)
> ...
> perform t1.val FROM t1 WHERE
> (COALESCE(rpad(t1.val, 100),'') ) like COALESCE(STR || '%','')
> order by COALESCE(rpad(t1.val, 100), '') using ~<~ LIMIT 5;

[ doesn't use index ]

No, it doesn't. The LIKE index optimization requires the LIKE pattern
to be a constant at plan time, so that the planner can extract the
pattern's fixed prefix. An expression depending on a function parameter
is certainly not constant.

If you really need this to work, you could use EXECUTE USING so that
the query is re-planned for each execution.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Pin007 2011-08-16 20:03:16 Re: Streaming replication performance
Previous Message Eyal Wilde 2011-08-16 04:30:18 index not being used when variable is sent