BEGIN; BEGIN EXPLAIN select s_name, count(*) as numwait from supplier, lineitem l1, orders, nation where s_suppkey = l1.l_suppkey and o_orderkey = l1.l_orderkey and o_orderstatus = 'F' and l1.l_receiptdate > l1.l_commitdate and exists ( select * from lineitem l2 where l2.l_orderkey = l1.l_orderkey and l2.l_suppkey <> l1.l_suppkey ) and not exists ( select * from lineitem l3 where l3.l_orderkey = l1.l_orderkey and l3.l_suppkey <> l1.l_suppkey and l3.l_receiptdate > l3.l_commitdate ) and s_nationkey = n_nationkey and n_name = 'CANADA' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=43053626.33..43053626.33 rows=1 width=26) -> Sort (cost=43053626.33..43053626.33 rows=1 width=26) Sort Key: (pg_catalog.count(*)) DESC, supplier.s_name -> HashAggregate (cost=43053626.31..43053626.32 rows=1 width=26) Group Key: supplier.s_name -> Remote Subquery Scan on all (datanode_1_1,datanode_2_1,datanode_3_1,datanode_4_1,datanode_5_1,datanode_6_1,datanode_7_1,datanode_8_1) (cost=26576308.43..43053626.30 rows=1 width=26) -> HashAggregate (cost=26576308.43..43053626.30 rows=1 width=26) Group Key: supplier.s_name -> Nested Loop Anti Join (cost=26576308.43..43053626.30 rows=1 width=26) -> Nested Loop (cost=26576308.31..43053611.33 rows=1 width=34) -> Hash Semi Join (cost=26576308.11..43053603.71 rows=1 width=38) Hash Cond: (l1.l_orderkey = l2.l_orderkey) Join Filter: (l2.l_suppkey <> l1.l_suppkey) -> Hash Join (cost=74379.63..14061767.90 rows=8000505 width=34) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) -> Bitmap Heap Scan on lineitem l1 (cost=50007.29..13207343.15 rows=200012629 width=8) Recheck Cond: (l_commitdate < l_receiptdate) -> Bitmap Index Scan on lineitem_l_orderkey_idx_part1 (cost=0.00..4.13 rows=200012629 width=0) -> Hash (cost=23872.35..23872.35 rows=40000 width=30) -> Nested Loop (cost=750.17..23872.35 rows=40000 width=30) -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) Filter: (n_name = 'CANADA'::bpchar) -> Bitmap Heap Scan on supplier (cost=750.17..23471.03 rows=40000 width=34) Recheck Cond: (s_nationkey = nation.n_nationkey) -> Bitmap Index Scan on supplier_s_nationkey_s_suppkey_idx (cost=0.00..740.17 rows=40000 width=0) Index Cond: (s_nationkey = nation.n_nationkey) -> Hash (cost=16657556.88..16657556.88 rows=600037888 width=8) -> Seq Scan on lineitem l2 (cost=0.00..16657556.88 rows=600037888 width=8) -> Index Scan using pk_orders on orders (cost=0.20..7.61 rows=1 width=4) Index Cond: (o_orderkey = l1.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) -> Index Scan using lineitem_l_orderkey_idx_part1 on lineitem l3 (cost=0.12..7.54 rows=2 width=8) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) (34 rows) COMMIT; COMMIT