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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

               http://www.postgresql.org/about/donate


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux