Skip to content

Instantly share code, notes, and snippets.

@thomas-mcdonald
Created November 17, 2019 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomas-mcdonald/309c5de135dcda0364aa44f97ca9562c to your computer and use it in GitHub Desktop.
Save thomas-mcdonald/309c5de135dcda0364aa44f97ca9562c to your computer and use it in GitHub Desktop.
libref_dev=# EXPLAIN ANALYZE SELECT "functions".* FROM "functions" INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id" INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id" WHERE "versions"."project_id" = 2 AND "functions"."slug" = 'ActionController/ParameterEncoding/ClassMethods/instance/skip_parameter_encoding' ORDER BY string_to_array(regexp_replace(versions.name, '[^0-9.]', '', 'g'), '.')::int[] ASC;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=3189.68..3189.69 rows=1 width=1279) (actual time=45.787..45.788 rows=2 loops=1)
Sort Key: ((string_to_array(regexp_replace((versions.name)::text, '[^0-9.]'::text, ''::text, 'g'::text), '.'::text))::integer[])
Sort Method: quicksort Memory: 29kB
-> Nested Loop (cost=18.84..3189.67 rows=1 width=1279) (actual time=3.918..45.772 rows=2 loops=1)
-> Nested Loop (cost=18.55..554.11 rows=809 width=40) (actual time=0.134..5.400 rows=6825 loops=1)
-> Seq Scan on versions (cost=0.00..1.11 rows=1 width=40) (actual time=0.008..0.023 rows=9 loops=1)
Filter: (project_id = 2)
-> Bitmap Heap Scan on klasses (cost=18.55..544.91 rows=809 width=16) (actual time=0.076..0.352 rows=758 loops=9)
Recheck Cond: (version_id = versions.id)
Heap Blocks: exact=808
-> Bitmap Index Scan on index_klasses_on_version_id (cost=0.00..18.35 rows=809 width=0) (actual time=0.061..0.061 rows=849 loops=9)
Index Cond: (version_id = versions.id)
-> Index Scan using index_functions_on_klass_id on functions (cost=0.29..3.25 rows=1 width=1247) (actual time=0.006..0.006 rows=0 loops=6825)
Index Cond: (klass_id = klasses.id)
Filter: ((slug)::text = 'ActionController/ParameterEncoding/ClassMethods/instance/skip_parameter_encoding'::text)
Rows Removed by Filter: 5
Planning Time: 0.700 ms
Execution Time: 45.842 ms
(18 rows)
libref_dev=# EXPLAIN ANALYZE SELECT "functions".* FROM "functions" INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id" INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id" WHERE "versions"."project_id" = 2 AND "functions"."slug" = 'ActionController/ParameterEncoding/ClassMethods/instance/skip_parameter_encoding' ORDER BY string_to_array(regexp_replace(versions.name, '[^0-9.]', '', 'g'), '.')::int[] ASC;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=66.79..66.79 rows=1 width=1279) (actual time=3.269..3.269 rows=2 loops=1)
Sort Key: ((string_to_array(regexp_replace((versions.name)::text, '[^0-9.]'::text, ''::text, 'g'::text), '.'::text))::integer[])
Sort Method: quicksort Memory: 29kB
-> Nested Loop (cost=4.74..66.78 rows=1 width=1279) (actual time=0.154..3.251 rows=2 loops=1)
Join Filter: (klasses.version_id = versions.id)
Rows Removed by Join Filter: 16
-> Seq Scan on versions (cost=0.00..1.11 rows=1 width=40) (actual time=0.008..0.030 rows=9 loops=1)
Filter: (project_id = 2)
-> Nested Loop (cost=4.74..65.54 rows=5 width=1255) (actual time=0.342..0.349 rows=2 loops=9)
-> Bitmap Heap Scan on functions (cost=4.45..24.04 rows=5 width=1247) (actual time=0.097..0.099 rows=2 loops=9)
Recheck Cond: ((slug)::text = 'ActionController/ParameterEncoding/ClassMethods/instance/skip_parameter_encoding'::text)
Heap Blocks: exact=18
-> Bitmap Index Scan on index_functions_on_slug (cost=0.00..4.45 rows=5 width=0) (actual time=0.093..0.093 rows=2 loops=9)
Index Cond: ((slug)::text = 'ActionController/ParameterEncoding/ClassMethods/instance/skip_parameter_encoding'::text)
-> Index Scan using klasses_pkey on klasses (cost=0.28..8.30 rows=1 width=16) (actual time=0.037..0.037 rows=1 loops=18)
Index Cond: (id = functions.klass_id)
Planning Time: 0.911 ms
Execution Time: 3.340 ms
(18 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment