Guest User

Untitled

a guest
May 21st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. select film.film_id, film.title, a.actors
  2. from film
  3. left join
  4. (
  5. select film_actor.film_id, array_agg(first_name) as actors
  6. from actor
  7. inner join film_actor using(actor_id)
  8. group by film_actor.film_id
  9. ) as a
  10. on a.film_id = film.film_id
  11. where film.title = 'ACADEMY DINOSAUR'
  12. order by film.title;
  13.  
  14. select film.film_id, film.title, a.actors
  15. from film
  16. left join lateral
  17. (
  18. select array_agg(first_name) as actors
  19. from actor
  20. inner join film_actor using(actor_id)
  21. where film_actor.film_id = film.film_id
  22. ) as a
  23. on true
  24. where film.title = 'ACADEMY DINOSAUR'
  25. order by film.title;
  26.  
  27. Merge Left Join (cost=507.20..573.11 rows=1 width=51) (actual time=15.087..15.089 rows=1 loops=1)
  28. Merge Cond: (film.film_id = film_actor.film_id)
  29. -> Sort (cost=8.30..8.31 rows=1 width=19) (actual time=0.075..0.075 rows=1 loops=1)
  30. Sort Key: film.film_id
  31. Sort Method: quicksort Memory: 25kB
  32. -> Index Scan using idx_title on film (cost=0.28..8.29 rows=1 width=19) (actual time=0.044..0.058 rows=1 loops=1)
  33. Index Cond: ((title)::text = 'ACADEMY DINOSAUR'::text)
  34. -> GroupAggregate (cost=498.90..552.33 rows=997 width=34) (actual time=15.004..15.004 rows=1 loops=1)
  35. Group Key: film_actor.film_id
  36. -> Sort (cost=498.90..512.55 rows=5462 width=8) (actual time=14.934..14.937 rows=11 loops=1)
  37. Sort Key: film_actor.film_id
  38. Sort Method: quicksort Memory: 449kB
  39. -> Hash Join (cost=6.50..159.84 rows=5462 width=8) (actual time=0.355..8.359 rows=5462 loops=1)
  40. Hash Cond: (film_actor.actor_id = actor.actor_id)
  41. -> Seq Scan on film_actor (cost=0.00..84.62 rows=5462 width=4) (actual time=0.035..2.205 rows=5462 loops=1)
  42. -> Hash (cost=4.00..4.00 rows=200 width=10) (actual time=0.303..0.303 rows=200 loops=1)
  43. Buckets: 1024 Batches: 1 Memory Usage: 17kB
  44. -> Seq Scan on actor (cost=0.00..4.00 rows=200 width=10) (actual time=0.027..0.143 rows=200 loops=1)
  45. Planning time: 1.495 ms
  46. Execution time: 15.426 ms
  47.  
  48. Nested Loop Left Join (cost=25.11..33.16 rows=1 width=51) (actual time=0.849..0.854 rows=1 loops=1)
  49. -> Index Scan using idx_title on film (cost=0.28..8.29 rows=1 width=19) (actual time=0.045..0.048 rows=1 loops=1)
  50. Index Cond: ((title)::text = 'ACADEMY DINOSAUR'::text)
  51. -> Aggregate (cost=24.84..24.85 rows=1 width=32) (actual time=0.797..0.797 rows=1 loops=1)
  52. -> Hash Join (cost=10.82..24.82 rows=5 width=6) (actual time=0.672..0.764 rows=10 loops=1)
  53. Hash Cond: (film_actor.actor_id = actor.actor_id)
  54. -> Bitmap Heap Scan on film_actor (cost=4.32..18.26 rows=5 width=2) (actual time=0.072..0.150 rows=10 loops=1)
  55. Recheck Cond: (film_id = film.film_id)
  56. Heap Blocks: exact=10
  57. -> Bitmap Index Scan on idx_fk_film_id (cost=0.00..4.32 rows=5 width=0) (actual time=0.041..0.041 rows=10 loops=1)
  58. Index Cond: (film_id = film.film_id)
  59. -> Hash (cost=4.00..4.00 rows=200 width=10) (actual time=0.561..0.561 rows=200 loops=1)
  60. Buckets: 1024 Batches: 1 Memory Usage: 17kB
  61. -> Seq Scan on actor (cost=0.00..4.00 rows=200 width=10) (actual time=0.039..0.275 rows=200 loops=1)
  62. Planning time: 1.722 ms
  63. Execution time: 1.087 ms
Add Comment
Please, Sign In to add comment