BEGIN; BEGIN EXPLAIN select c_custkey, c_name, sum(l_extendedprice * (1 - l_discount)) as revenue, c_acctbal, n_name, c_address, c_phone, c_comment from customer, orders, lineitem, nation where c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate >= date '1993-06-01' and o_orderdate < cast(date '1993-06-01' + interval '3 month' as date) and l_returnflag = 'R' and c_nationkey = n_nationkey group by c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment order by revenue desc LIMIT 20; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=2137869.83..2137869.88 rows=20 width=202) -> Sort (cost=2137869.83..2139311.24 rows=576564 width=202) Sort Key: (sum((lineitem.l_extendedprice * ('1'::numeric - lineitem.l_discount)))) DESC -> Finalize GroupAggregate (cost=2048451.30..2122527.67 rows=576564 width=202) Group Key: customer.c_custkey, nation.n_name -> Gather Merge (cost=2048451.30..2110515.92 rows=480470 width=202) Workers Planned: 2 -> Partial GroupAggregate (cost=2047451.27..2054057.74 rows=240235 width=202) Group Key: customer.c_custkey, nation.n_name -> Sort (cost=2047451.27..2048051.86 rows=240235 width=182) Sort Key: customer.c_custkey, nation.n_name -> Hash Join (cost=429332.40..2004631.37 rows=240235 width=182) Hash Cond: (customer.c_nationkey = nation.n_nationkey) -> Parallel Hash Join (cost=429330.84..2003892.29 rows=240235 width=160) Hash Cond: (orders.o_custkey = customer.c_custkey) -> Parallel Hash Join (cost=365972.88..1924126.72 rows=240235 width=16) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) -> Parallel Seq Scan on lineitem (cost=0.00..1467295.96 rows=6252525 width=20) Filter: (l_returnflag = 'R'::bpchar) -> Parallel Hash (cost=361798.43..361798.43 rows=240116 width=12) -> Parallel Seq Scan on orders (cost=0.00..361798.43 rows=240116 width=12) Filter: ((o_orderdate >= '1993-06-01'::date) AND (o_orderdate < '1993-09-01'::date)) -> Parallel Hash (cost=42116.20..42116.20 rows=625020 width=148) -> Parallel Seq Scan on customer (cost=0.00..42116.20 rows=625020 width=148) -> Hash (cost=1.25..1.25 rows=25 width=30) -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (26 rows) COMMIT; COMMIT