Postgres NOT IN performance

前端 未结 4 531
暗喜
暗喜 2020-12-28 22:09

Any ideas how to speed up this query?

Input

EXPLAIN SELECT entityid FROM entity e

LEFT JOIN level1entity l1 ON l1.level1id = e.level1_level1id
LEFT         


        
4条回答
  •  被撕碎了的回忆
    2020-12-28 22:26

    Since you are requiring level2entity record because of your where clause check for a specific userid "l2.userid = " You should make your "LEFT JOIN level2entity" into an "INNER JOIN level2entity"

    INNER JOIN level2entity l2 ON l2.level2id = l1.level2_level2id AND l2.userid = 'a987c246-65e5-48f6-9d2d-a7bcb6284c8f'
    

    This will, hopefully, filter down your entity's so your NOT IN will have less work to do.

提交回复
热议问题