Postgres NOT IN performance
问题 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 JOIN level2entity l2 ON l2.level2id = l1.level2_level2id WHERE l2.userid = 'a987c246-65e5-48f6-9d2d-a7bcb6284c8f' AND (entityid NOT IN (1377776,1377792,1377793,1377794,1377795,1377796... 50000 ids) ) Output Nested Loop (cost=0.00..1452373.79 rows=3865 width=8) -> Nested Loop (cost=0.00..8.58 rows=1 width=8) Join Filter: (l1.level2_level2id = l2