小编Jel*_*rns的帖子

Why does this LEFT JOIN perform so much worse than LEFT JOIN LATERAL?

I have the following tables (taken from the Sakila database):

  • film: film_id is pkey
  • actor: actor_id is pkey
  • film_actor: film_id and actor_id are fkeys to film/actor

I am selecting a particular film. For this film, I also want all actors participating in that film. I have two queries for this: one with a LEFT JOIN and one with a LEFT JOIN LATERAL.

select film.film_id, film.title, a.actors
from   film
left join
  (         
       select     film_actor.film_id, array_agg(first_name) as actors
       from       actor
       inner …
Run Code Online (Sandbox Code Playgroud)

postgresql performance join execution-plan postgresql-10 postgresql-performance

14
推荐指数
1
解决办法
4050
查看次数