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 = 'VIETNAM' group by s_name order by numwait desc, s_name LIMIT 100; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=752504.36..752504.37 rows=1 width=34) -> Sort (cost=752504.36..752504.37 rows=1 width=34) Sort Key: (count(*)) DESC, supplier.s_name -> GroupAggregate (cost=752504.33..752504.35 rows=1 width=34) Group Key: supplier.s_name -> Sort (cost=752504.33..752504.34 rows=1 width=26) Sort Key: supplier.s_name -> Nested Loop (cost=4018.69..752504.32 rows=1 width=26) -> Nested Loop Semi Join (cost=4018.26..752496.98 rows=1 width=42) -> Gather (cost=4017.69..752489.96 rows=1 width=38) Workers Planned: 2 -> Nested Loop Anti Join (cost=3017.69..751489.86 rows=1 width=38) -> Parallel Hash Join (cost=3017.13..497888.44 rows=333246 width=38) Hash Cond: (l1.l_suppkey = supplier.s_suppkey) -> Parallel Index Only Scan using lineitem_l_orderkey_l_suppkey_idx on lineitem l1 (cost=0.56..461669.76 rows=8331145 width=12) -> Parallel Hash (cost=2987.15..2987.15 rows=2353 width=30) -> Hash Join (cost=1.32..2987.15 rows=2353 width=30) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) -> Parallel Seq Scan on supplier (cost=0.00..2805.24 rows=58824 width=34) -> Hash (cost=1.31..1.31 rows=1 width=4) -> Seq Scan on nation (cost=0.00..1.31 rows=1 width=4) Filter: (n_name = 'VIETNAM'::bpchar) -> Index Only Scan using lineitem_l_orderkey_l_suppkey_idx on lineitem l3 (cost=0.56..5.00 rows=49 width=12) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) -> Index Only Scan using lineitem_l_orderkey_l_suppkey_l_quantity_idx on lineitem l2 (cost=0.56..7.00 rows=148 width=12) Index Cond: (l_orderkey = l1.l_orderkey) Filter: (l_suppkey <> l1.l_suppkey) -> Index Scan using pk_orders on orders (cost=0.43..7.34 rows=1 width=8) Index Cond: (o_orderkey = l1.l_orderkey) Filter: (o_orderstatus = 'F'::bpchar) (31 rows) COMMIT; COMMIT