Re: Index on VARCHAR with text_pattern_ops inside PL/PGSQL procedure.

From: Richard Huxton <dev(at)archonet(dot)com>
To: Piotr Gasidło <quaker(at)barbara(dot)eu(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Index on VARCHAR with text_pattern_ops inside PL/PGSQL procedure.
Date: 2007-12-10 13:04:07
Message-ID: 475D3947.7000107@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Piotr Gasidło wrote:
> Some performance loss, but OK. Now I've changed "=" into "LIKE" to use
> users_user_name_unique_text_pattern_ops index and rerun query:
>
> explain analyze select user_login('quaker');
>
> QUERY PLAN
> --------------------------------------------------------------------------------------
>
> Result (cost=0.00..0.01 rows=1 width=0) (actual time=41.606..41.608
> rows=1 loops=1)
> Total runtime: 41.629 ms
> (2 rows)
>
> Second run give 61.061 ms. So no improvements.
>
> Why PL/PGSQL is unable to proper utilize
> users_user_name_unique_text_pattern_ops?

It plans the query just once for the pl/pgsql function. That means it
doesn't know whether you are passing in a name '%foo' which can't use
the index. Since only one plan can be used it has to use a scan of the
table.

You can use EXECUTE to get plpgsql to plan the query each time it is
called. That should let it recognise that it can use the index (if it
can, of course).

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Pavel Stehule 2007-12-10 13:07:58 Re: Index on VARCHAR with text_pattern_ops inside PL/PGSQL procedure.
Previous Message Piotr Gasidło 2007-12-10 12:58:01 Index on VARCHAR with text_pattern_ops inside PL/PGSQL procedure.