BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) from customer, orders, lineitem where o_orderkey in ( select l_orderkey from lineitem group by l_orderkey having sum(l_quantity) > 312 ) and c_custkey = o_custkey and o_orderkey = l_orderkey group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice order by o_totalprice desc, o_orderdate LIMIT 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=10332424.74..10332427.49 rows=100 width=39) (actual time=134632.737..134633.067 rows=100 loops=1) Buffers: shared hit=1336023 read=1088136 dirtied=1 written=15 -> GroupAggregate (cost=10332424.74..11158878.67 rows=30052870 width=39) (actual time=134632.733..134633.047 rows=100 loops=1) Buffers: shared hit=1336023 read=1088136 dirtied=1 written=15 -> Sort (cost=10332424.74..10407556.92 rows=30052870 width=39) (actual time=134632.713..134632.774 rows=701 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 85kB Buffers: shared hit=1336023 read=1088136 dirtied=1 written=15 -> Hash Join (cost=3057492.76..5777946.61 rows=30052870 width=39) (actual time=98316.626..134628.670 rows=777 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1336009 read=1088136 dirtied=1 written=15 -> Seq Scan on lineitem (cost=0.00..1668603.40 rows=60105740 width=8) (actual time=0.067..21850.570 rows=60045603 loops=1) Buffers: shared hit=582062 read=485484 -> Hash (cost=2963555.46..2963555.46 rows=7514984 width=39) (actual time=98154.464..98154.464 rows=111 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=753947 read=602652 dirtied=1 written=15 -> Hash Join (cost=2180607.30..2963555.46 rows=7514984 width=39) (actual time=87532.841..98149.581 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=753947 read=602652 dirtied=1 written=15 -> Hash Join (cost=2111579.30..2744227.78 rows=7514984 width=20) (actual time=85986.840..96587.596 rows=111 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=718762 read=602559 dirtied=1 written=15 -> Seq Scan on orders (cost=0.00..404074.68 rows=15029968 width=16) (actual time=0.018..5541.175 rows=15015000 loops=1) Buffers: shared hit=170671 read=83104 dirtied=1 written=8 -> Hash (cost=2060705.30..2060705.30 rows=4069920 width=4) (actual time=85845.947..85845.947 rows=111 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=548091 read=519455 written=7 -> HashAggregate (cost=1969132.10..2020006.10 rows=4069920 width=8) (actual time=76422.416..85845.002 rows=111 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 15014889 Buffers: shared hit=548091 read=519455 written=7 -> Seq Scan on lineitem (cost=0.00..1668603.40 rows=60105740 width=8) (actual time=0.030..22242.293 rows=60045603 loops=1) Buffers: shared hit=548091 read=519455 written=7 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1543.860..1543.860 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35185 read=93 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.025..828.900 rows=1500000 loops=1) Buffers: shared hit=35185 read=93 Total runtime: 134989.868 ms (39 rows) COMMIT; COMMIT