Skip to content

Instantly share code, notes, and snippets.

@sheac
Created August 11, 2020 01:49
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 sheac/e8f4be7257bb4b370913fc48d35aebf4 to your computer and use it in GitHub Desktop.
Save sheac/e8f4be7257bb4b370913fc48d35aebf4 to your computer and use it in GitHub Desktop.
QUERY PLAN
Limit (cost=91129.81..91129.83 rows=1 width=514) (actual time=147833.015..147833.110 rows=16 loops=1)
-> Unique (cost=91129.81..91129.82 rows=1 width=514) (actual time=147833.015..147833.110 rows=16 loops=1)
-> Sort (cost=91129.81..91129.82 rows=1 width=514) (actual time=147833.014..147833.066 rows=237 loops=1)
Sort Key: template_set_versions.created_at DESC, ts.id DESC
Sort Method: quicksort Memory: 451kB
-> Nested Loop (cost=24413.59..91129.80 rows=1 width=514) (actual time=573.884..147831.945 rows=237 loops=1)
-> Nested Loop (cost=24413.17..91129.36 rows=1 width=530) (actual time=573.862..147828.139 rows=237 loops=1)
Join Filter: (SubPlan 1)
Rows Removed by Join Filter: 249
-> Nested Loop (cost=24412.76..85995.26 rows=1 width=506) (actual time=314.701..21724.207 rows=486 loops=1)
Join Filter: (template_set_versions.templates @> (json_build_array(jt.id))::jsonb)
Rows Removed by Join Filter: 67669
-> Merge Join (cost=8953.54..25224.39 rows=1 width=470) (actual time=37.943..122.296 rows=317 loops=1)
Merge Cond: (template_set_versions.id = aav.actor_id)
-> Unique (cost=0.42..15758.26 rows=41038 width=454) (actual time=0.011..76.567 rows=61595 loops=1)
-> Index Scan Backward using template_set_versions_pkey on template_set_versions (cost=0.42..15531.71 rows=90621 width=454) (actual time=0.010..60.193 rows=90500 loops=1)
-> Sort (cost=8953.13..8953.13 rows=3 width=16) (actual time=37.336..39.219 rows=6661 loops=1)
Sort Key: aav.actor_id DESC
Sort Method: quicksort Memory: 505kB
-> Nested Loop (cost=84.17..8953.10 rows=3 width=16) (actual time=7.183..34.558 rows=6661 loops=1)
-> Nested Loop (cost=0.29..2422.04 rows=1 width=16) (actual time=7.055..14.179 rows=4 loops=1)
-> Seq Scan on attribute_values av (cost=0.00..2388.77 rows=4 width=32) (actual time=7.039..14.128 rows=5 loops=1)
Filter: ((label = ANY ('{Malaysia}'::text[])) AND (archived_at = 0))
Rows Removed by Filter: 87402
-> Index Scan using attributes_pkey on attributes a (cost=0.29..8.31 rows=1 width=16) (actual time=0.007..0.008 rows=1 loops=5)
Index Cond: (id = av.attribute_id)
Filter: ((archived_at = 0) AND ((label)::text = 'Location'::text))
Rows Removed by Filter: 0
-> Bitmap Heap Scan on actor_attribute_values aav (cost=83.88..6516.51 rows=1455 width=32) (actual time=1.544..4.901 rows=1665 loops=4)
Recheck Cond: (attribute_value_id = av.id)
Filter: (archived_at = 0)
Rows Removed by Filter: 1668
Heap Blocks: exact=10266
-> Bitmap Index Scan on index_actor_attribute_values_on_attribute_value_id_and_actor_id (cost=0.00..83.52 rows=1995 width=0) (actual time=1.022..1.022 rows=3538 loops=4)
Index Cond: (attribute_value_id = av.id)
-> Bitmap Heap Scan on job_templates jt (cost=15459.21..60770.53 rows=17 width=36) (actual time=56.707..67.791 rows=215 loops=317)
Recheck Cond: ((status = 'Published'::job_template_status) AND (team_id = '641cab72-e1fe-40ae-ac89-afe4aa7cbdf0'::uuid))
Rows Removed by Index Recheck: 17483
Filter: ((metadata -> '9834f929-e683-423e-847a-c258281b1e65'::text) @> '{"__type__": "list","__isref__": false,"__value__": "7fd92d20-cf61-4c90-ba46-f85ecad2bbfd"}'::jsonb)
Rows Removed by Filter: 4690
Heap Blocks: exact=4894163
-> BitmapAnd (cost=15459.21..15459.21 rows=17394 width=0) (actual time=46.201..46.201 rows=0 loops=317)
-> Bitmap Index Scan on index_job_templates_on_status (cost=0.00..3766.55 rows=93083 width=0) (actual time=10.793..10.793 rows=94436 loops=317)
Index Cond: (status = 'Published'::job_template_status)
-> Bitmap Index Scan on index_job_templates_on_team_id (cost=0.00..11692.40 rows=238930 width=0) (actual time=27.648..27.648 rows=266658 loops=317)
Index Cond: (team_id = '641cab72-e1fe-40ae-ac89-afe4aa7cbdf0'::uuid)
-> Index Scan using template_sets_pkey on template_sets ts (cost=0.41..0.44 rows=1 width=60) (actual time=0.009..0.011 rows=1 loops=486)
Index Cond: (id = aav.actor_id)
Filter: ((type = ANY ('{0}'::integer[])) AND (archived_at = 0) AND (team_id = '641cab72-e1fe-40ae-ac89-afe4aa7cbdf0'::uuid))
SubPlan 1
-> HashAggregate (cost=5125.24..5138.70 rows=1346 width=20) (actual time=257.827..258.992 rows=5857 loops=486)
Group Key: mjt.id
-> Bitmap Heap Scan on job_templates mjt (cost=71.18..5118.30 rows=1387 width=20) (actual time=32.854..170.434 rows=248108 loops=486)
Recheck Cond: (team_id = ts.team_id)
Rows Removed by Index Recheck: 195737
Heap Blocks: exact=14224734 lossy=12938778
-> Bitmap Index Scan on index_job_templates_on_team_id (cost=0.00..70.83 rows=1387 width=0) (actual time=27.961..27.961 rows=266658 loops=486)
Index Cond: (team_id = ts.team_id)
-> Index Only Scan using template_sets_pkey on template_sets ts_1 (cost=0.41..0.43 rows=1 width=16) (actual time=0.011..0.011 rows=1 loops=237)
Index Cond: (id = aav.actor_id)
Heap Fetches: 237
Planning time: 13.330 ms
Execution time: 147833.301 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment