• gitlabhq_production=# explain (buffers, analyze) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "users" WHERE (("users"."name" ILIKE '%username%' OR "users"."username" ILIKE '%username%') OR "users"."email" = 'username') AND ("users"."external" != 't') LIMIT 1001) subquery_for_count;
                                                                               QUERY PLAN
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------
     Aggregate  (cost=2156.42..2156.43 rows=1 width=8) (actual time=21.228..21.228 rows=1 loops=1)
       Buffers: shared hit=1293
       ->  Limit  (cost=1012.57..2147.87 rows=684 width=4) (actual time=19.440..21.183 rows=385 loops=1)
             Buffers: shared hit=1293
             ->  Bitmap Heap Scan on users  (cost=1012.57..2147.87 rows=684 width=4) (actual time=19.438..21.141 rows=385 loops=1)
                   Recheck Cond: (((name)::text ~~* '%username%'::text) OR ((username)::text ~~* '%username%'::text) OR ((email)::text = 'username'::text))
                   Filter: (NOT external)
                   Heap Blocks: exact=385
                   Buffers: shared hit=1293
                   ->  BitmapOr  (cost=1012.57..1012.57 rows=684 width=0) (actual time=19.376..19.376 rows=0 loops=1)
                         Buffers: shared hit=908
                         ->  Bitmap Index Scan on index_users_on_name_trigram  (cost=0.00..563.46 rows=328 width=0) (actual time=10.121..10.121 rows=66 loops=1)
                               Index Cond: ((name)::text ~~* '%username%'::text)
                               Buffers: shared hit=504
                         ->  Bitmap Index Scan on index_users_on_username_trigram  (cost=0.00..446.66 rows=355 width=0) (actual time=9.234..9.234 rows=366 loops=1)
                               Index Cond: ((username)::text ~~* '%username%'::text)
                               Buffers: shared hit=401
                         ->  Bitmap Index Scan on users_email_key  (cost=0.00..1.94 rows=1 width=0) (actual time=0.019..0.019 rows=0 loops=1)
                               Index Cond: ((email)::text = 'username'::text)
                               Buffers: shared hit=3
     Planning time: 2.066 ms
     Execution time: 21.275 ms
    (22 rows)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment