我试图弄清楚查询 1 还是 2 是否更优化,并且似乎在我的 WHERE 子句中包含我的条件比在我的 JOIN 子句中更优化:
-- 1) "ups" inside where clause
explain analyze select * from item_events LEFT JOIN "carriers" ON "carriers"."item_event_id" = "item_events"."id" WHERE "carriers"."carrier_name" = 'ups' and "item_events"."property_id" = 895;
-- QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Gather (cost=1157.49..41948.17 rows=2721 width=381) (actual time=35.650..1832.871 rows=3933 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Nested Loop (cost=157.49..40676.07 rows=1134 width=381) (actual time=34.171..1824.416 rows=1311 loops=3)
-> Parallel Bitmap Heap Scan on item_events (cost=157.05..16828.84 rows=1969 width=286) (actual time=30.920..368.885 rows=1819 loops=3)
Recheck Cond: …
Run Code Online (Sandbox Code Playgroud) postgresql ×1