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 '1994-12-01' and o_orderdate < cast(date '1994-12-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=2143356.21..2143356.26 rows=20 width=202) -> Sort (cost=2143356.21..2144833.69 rows=590992 width=202) Sort Key: (sum((lineitem.l_extendedprice * ('1'::numeric - lineitem.l_discount)))) DESC -> Finalize GroupAggregate (cost=2051699.97..2127630.13 rows=590992 width=202) Group Key: customer.c_custkey, nation.n_name -> Gather Merge (cost=2051699.97..2115317.79 rows=492494 width=202) Workers Planned: 2 -> Partial GroupAggregate (cost=2050699.94..2057471.73 rows=246247 width=202) Group Key: customer.c_custkey, nation.n_name -> Sort (cost=2050699.94..2051315.56 rows=246247 width=182) Sort Key: customer.c_custkey, nation.n_name -> Hash Join (cost=429795.54..2006763.33 rows=246247 width=182) Hash Cond: (customer.c_nationkey = nation.n_nationkey) -> Parallel Hash Join (cost=429793.97..2006005.79 rows=246247 width=160) Hash Cond: (orders.o_custkey = customer.c_custkey) -> Parallel Hash Join (cost=366436.02..1926166.44 rows=246247 width=16) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) -> Parallel Seq Scan on lineitem (cost=0.00..1468753.24 rows=6258734 width=20) Filter: (l_returnflag = 'R'::bpchar) -> Parallel Hash (cost=362157.46..362157.46 rows=246125 width=12) -> Parallel Seq Scan on orders (cost=0.00..362157.46 rows=246125 width=12) Filter: ((o_orderdate >= '1994-12-01'::date) AND (o_orderdate < '1995-03-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