count(*) from _cities where country_id=1 and title_ru ilike 'а%';
                  
                  
                                                                                        QUERY PLAN
                  
                  
                  ------------------------------------------------------------------------------------------------------------------------------------------------------
                  
                  
                   Aggregate  (cost=170923.68..170923.69 rows=1 width=8) (actual time=10184.618..10184.618 rows=1 loops=1)
                  
                  
                     ->  Bitmap Heap Scan on _cities  (cost=2965.39..170919.54 rows=1657 width=0) (actual time=20.332..10181.501 rows=6173 loops=1)
                  
                  
                           Recheck Cond: (country_id = 1)
                  
                  
                           Filter: ((title_ru)::text ~~* 'а%'::text)
                  
                  
                           Rows Removed by Filter: 152942
                  
                  
                           Heap Blocks: exact=27390
                  
                  
                           ->  Bitmap Index Scan on _cities_country_id_index  (cost=0.00..2964.98 rows=160073 width=0) (actual time=15.760..15.760 rows=159115 loops=1)
                  
                  
                                 Index Cond: (country_id = 1)
                  
                  
                   Planning time: 0.572 ms
                  
                  
                   Execution time: 10185.937 ms
                  
                  
                  (10 rows)
                  
                  
                
1. полнотекстовый поиск 2. если надо искать по первой букве - что мешает построить индекс по подстроке?
Обсуждают сегодня