symfony - PostgreSQL index for like 'abc%' searching -


i have postgresql table city list (>1m) , need search on table pattern 'abc%'. created b-tree index on city.name column, , here got:

explain select * city name ~~* 'Мос%'  seq scan on city  (cost=0.00..44562.62 rows=117 width=131) 

and exact select:

explain select * city name = 'Москва'  index scan using city_name_idx on city  (cost=0.43..12.33 rows=2 width=131) 

is there way use standart index achieve performance on first select?

i using symfony2/doctrine2, it's not easy (and not want) implement db-specific things here.

  • to speed like (case sensitive), create index this:

    create index indexname on city (name text_pattern_ops); 
  • to speed ilike or ~~* , in addition like, assuming postgresql 9.1 or newer, create index this:

    create index indexname on city  using gin(name gin_trgm_ops); 

    gin_trgm_ops provided pg_trgm extension should added if not present in database.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -